LLVM  9.0.0svn
DWARFDebugMacro.cpp
Go to the documentation of this file.
1 //===- DWARFDebugMacro.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 #include "llvm/Support/WithColor.h"
13 #include <cstdint>
14 
15 using namespace llvm;
16 using namespace dwarf;
17 
19  unsigned IndLevel = 0;
20  for (const Entry &E : Macros) {
21  // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
22  // this check handles the case of corrupted ".debug_macinfo" section.
23  if (IndLevel > 0)
24  IndLevel -= (E.Type == DW_MACINFO_end_file);
25  // Print indentation.
26  for (unsigned I = 0; I < IndLevel; I++)
27  OS << " ";
28  IndLevel += (E.Type == DW_MACINFO_start_file);
29 
31  switch (E.Type) {
32  default:
33  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
34  break;
35  case DW_MACINFO_define:
36  case DW_MACINFO_undef:
37  OS << " - lineno: " << E.Line;
38  OS << " macro: " << E.MacroStr;
39  break;
41  OS << " - lineno: " << E.Line;
42  OS << " filenum: " << E.File;
43  break;
45  break;
47  OS << " - constant: " << E.ExtConstant;
48  OS << " string: " << E.ExtStr;
49  break;
50  }
51  OS << "\n";
52  }
53 }
54 
56  uint32_t Offset = 0;
57  while (data.isValidOffset(Offset)) {
58  // A macro list entry consists of:
59  Entry E;
60  // 1. Macinfo type
61  E.Type = data.getULEB128(&Offset);
62 
63  if (E.Type == 0) {
64  // Reached end of ".debug_macinfo" section.
65  return;
66  }
67 
68  switch (E.Type) {
69  default:
70  // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
71  // Push the corrupted entry to the list and halt parsing.
72  E.Type = DW_MACINFO_invalid;
73  Macros.push_back(E);
74  return;
75  case DW_MACINFO_define:
76  case DW_MACINFO_undef:
77  // 2. Source line
78  E.Line = data.getULEB128(&Offset);
79  // 3. Macro string
80  E.MacroStr = data.getCStr(&Offset);
81  break;
83  // 2. Source line
84  E.Line = data.getULEB128(&Offset);
85  // 3. Source file id
86  E.File = data.getULEB128(&Offset);
87  break;
89  break;
91  // 2. Vendor extension constant
92  E.ExtConstant = data.getULEB128(&Offset);
93  // 3. Vendor extension string
94  E.ExtStr = data.getCStr(&Offset);
95  break;
96  }
97 
98  Macros.push_back(E);
99  }
100 }
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:23
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:37
raw_ostream & get()
Definition: WithColor.h:64
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:45
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:435