LLVM  6.0.0svn
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 
11 #include "SyntaxHighlighting.h"
14 #include <cstdint>
15 
16 using namespace llvm;
17 using namespace dwarf;
18 using namespace syntax;
19 
21  unsigned IndLevel = 0;
22  for (const Entry &E : Macros) {
23  // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
24  // this check handles the case of corrupted ".debug_macinfo" section.
25  if (IndLevel > 0)
26  IndLevel -= (E.Type == DW_MACINFO_end_file);
27  // Print indentation.
28  for (unsigned I = 0; I < IndLevel; I++)
29  OS << " ";
30  IndLevel += (E.Type == DW_MACINFO_start_file);
31 
32  WithColor(OS, syntax::Macro).get() << MacinfoString(E.Type);
33  switch (E.Type) {
34  default:
35  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
36  break;
37  case DW_MACINFO_define:
38  case DW_MACINFO_undef:
39  OS << " - lineno: " << E.Line;
40  OS << " macro: " << E.MacroStr;
41  break;
43  OS << " - lineno: " << E.Line;
44  OS << " filenum: " << E.File;
45  break;
47  break;
49  OS << " - constant: " << E.ExtConstant;
50  OS << " string: " << E.ExtStr;
51  break;
52  }
53  OS << "\n";
54  }
55 }
56 
58  uint32_t Offset = 0;
59  while (data.isValidOffset(Offset)) {
60  // A macro list entry consists of:
61  Entry E;
62  // 1. Macinfo type
63  E.Type = data.getULEB128(&Offset);
64 
65  if (E.Type == 0) {
66  // Reached end of ".debug_macinfo" section.
67  return;
68  }
69 
70  switch (E.Type) {
71  default:
72  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
73  // Push the corrupted entry to the list and halt parsing.
74  E.Type = DW_MACINFO_invalid;
75  Macros.push_back(E);
76  return;
77  case DW_MACINFO_define:
78  case DW_MACINFO_undef:
79  // 2. Source line
80  E.Line = data.getULEB128(&Offset);
81  // 3. Macro string
82  E.MacroStr = data.getCStr(&Offset);
83  break;
85  // 2. Source line
86  E.Line = data.getULEB128(&Offset);
87  // 3. Source file id
88  E.File = data.getULEB128(&Offset);
89  break;
91  break;
93  // 2. Vendor extension constant
94  E.ExtConstant = data.getULEB128(&Offset);
95  // 3. Vendor extension string
96  E.ExtStr = data.getCStr(&Offset);
97  break;
98  }
99 
100  Macros.push_back(E);
101  }
102 }
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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:44
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:428
An RAII object that temporarily switches an output stream to a specific color.