1 //===-- DWARFDebugMacro.cpp -----------------------------------------------===//
\r
3 // The LLVM Compiler Infrastructure
\r
5 // This file is distributed under the University of Illinois Open Source
\r
6 // License. See LICENSE.TXT for details.
\r
8 //===----------------------------------------------------------------------===//
\r
10 #include "SyntaxHighlighting.h"
\r
11 #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
\r
12 #include "llvm/Support/Compiler.h"
\r
13 #include "llvm/Support/Dwarf.h"
\r
14 #include "llvm/Support/Format.h"
\r
15 #include "llvm/Support/raw_ostream.h"
\r
17 using namespace llvm;
\r
18 using namespace dwarf;
\r
19 using namespace syntax;
\r
21 void DWARFDebugMacro::dump(raw_ostream &OS) const {
\r
22 unsigned IndLevel = 0;
\r
23 for (const Entry &E : Macros) {
\r
24 // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
\r
25 // this check handles the case of corrupted ".debug_macinfo" section.
\r
27 IndLevel -= (E.Type == DW_MACINFO_end_file);
\r
28 // Print indentation.
\r
29 for (unsigned I = 0; I < IndLevel; I++)
\r
31 IndLevel += (E.Type == DW_MACINFO_start_file);
\r
33 WithColor(OS, syntax::Macro).get() << MacinfoString(E.Type);
\r
36 // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
\r
38 case DW_MACINFO_define:
\r
39 case DW_MACINFO_undef:
\r
40 OS << " - lineno: " << E.Line;
\r
41 OS << " macro: " << E.MacroStr;
\r
43 case DW_MACINFO_start_file:
\r
44 OS << " - lineno: " << E.Line;
\r
45 OS << " filenum: " << E.File;
\r
47 case DW_MACINFO_end_file:
\r
49 case DW_MACINFO_vendor_ext:
\r
50 OS << " - constant: " << E.ExtConstant;
\r
51 OS << " string: " << E.ExtStr;
\r
58 void DWARFDebugMacro::parse(DataExtractor data) {
\r
59 uint32_t Offset = 0;
\r
60 while (data.isValidOffset(Offset)) {
\r
61 // A macro list entry consists of:
\r
64 E.Type = data.getULEB128(&Offset);
\r
67 // Reached end of ".debug_macinfo" section.
\r
73 // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
\r
74 // Push the corrupted entry to the list and halt parsing.
\r
75 E.Type = DW_MACINFO_invalid;
\r
76 Macros.push_back(E);
\r
78 case DW_MACINFO_define:
\r
79 case DW_MACINFO_undef:
\r
81 E.Line = data.getULEB128(&Offset);
\r
83 E.MacroStr = data.getCStr(&Offset);
\r
85 case DW_MACINFO_start_file:
\r
87 E.Line = data.getULEB128(&Offset);
\r
88 // 3. Source file id
\r
89 E.File = data.getULEB128(&Offset);
\r
91 case DW_MACINFO_end_file:
\r
93 case DW_MACINFO_vendor_ext:
\r
94 // 2. Vendor extension constant
\r
95 E.ExtConstant = data.getULEB128(&Offset);
\r
96 // 3. Vendor extension string
\r
97 E.ExtStr = data.getCStr(&Offset);
\r
101 Macros.push_back(E);
\r