LLVM  8.0.1
DWARFDebugMacro.cpp
Go to the documentation of this file.
1 //===- DWARFDebugMacro.cpp ------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 #include "llvm/Support/WithColor.h"
14 #include <cstdint>
15 
16 using namespace llvm;
17 using namespace dwarf;
18 
20  unsigned IndLevel = 0;
21  for (const Entry &E : Macros) {
22  // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
23  // this check handles the case of corrupted ".debug_macinfo" section.
24  if (IndLevel > 0)
25  IndLevel -= (E.Type == DW_MACINFO_end_file);
26  // Print indentation.
27  for (unsigned I = 0; I < IndLevel; I++)
28  OS << " ";
29  IndLevel += (E.Type == DW_MACINFO_start_file);
30 
32  switch (E.Type) {
33  default:
34  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
35  break;
36  case DW_MACINFO_define:
37  case DW_MACINFO_undef:
38  OS << " - lineno: " << E.Line;
39  OS << " macro: " << E.MacroStr;
40  break;
42  OS << " - lineno: " << E.Line;
43  OS << " filenum: " << E.File;
44  break;
46  break;
48  OS << " - constant: " << E.ExtConstant;
49  OS << " string: " << E.ExtStr;
50  break;
51  }
52  OS << "\n";
53  }
54 }
55 
57  uint32_t Offset = 0;
58  while (data.isValidOffset(Offset)) {
59  // A macro list entry consists of:
60  Entry E;
61  // 1. Macinfo type
62  E.Type = data.getULEB128(&Offset);
63 
64  if (E.Type == 0) {
65  // Reached end of ".debug_macinfo" section.
66  return;
67  }
68 
69  switch (E.Type) {
70  default:
71  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
72  // Push the corrupted entry to the list and halt parsing.
73  E.Type = DW_MACINFO_invalid;
74  Macros.push_back(E);
75  return;
76  case DW_MACINFO_define:
77  case DW_MACINFO_undef:
78  // 2. Source line
79  E.Line = data.getULEB128(&Offset);
80  // 3. Macro string
81  E.MacroStr = data.getCStr(&Offset);
82  break;
84  // 2. Source line
85  E.Line = data.getULEB128(&Offset);
86  // 3. Source file id
87  E.File = data.getULEB128(&Offset);
88  break;
90  break;
92  // 2. Vendor extension constant
93  E.ExtConstant = data.getULEB128(&Offset);
94  // 3. Vendor extension string
95  E.ExtStr = data.getCStr(&Offset);
96  break;
97  }
98 
99  Macros.push_back(E);
100  }
101 }
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:38
raw_ostream & get()
Definition: WithColor.h:65
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void parse(DataExtractor data)
Parse the debug_macinfo section accessible via the &#39;data&#39; parameter.
void dump(raw_ostream &OS) const
Print the macro list found within the debug_macinfo section.
This file contains constants used for implementing Dwarf debug support.
#define I(x, y, z)
Definition: MD5.cpp:58
const char * getCStr(uint32_t *offset_ptr) const
Extract a C string from *offset_ptr.
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:430