/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
10 | | #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h" |
11 | | #include "SyntaxHighlighting.h" |
12 | | #include "llvm/BinaryFormat/Dwarf.h" |
13 | | #include "llvm/Support/raw_ostream.h" |
14 | | #include <cstdint> |
15 | | |
16 | | using namespace llvm; |
17 | | using namespace dwarf; |
18 | | using namespace syntax; |
19 | | |
20 | 2 | void DWARFDebugMacro::dump(raw_ostream &OS) const { |
21 | 2 | unsigned IndLevel = 0; |
22 | 162 | for (const Entry &E : Macros) { |
23 | 162 | // There should not be DW_MACINFO_end_file when IndLevel is Zero. However, |
24 | 162 | // this check handles the case of corrupted ".debug_macinfo" section. |
25 | 162 | if (IndLevel > 0) |
26 | 17 | IndLevel -= (E.Type == DW_MACINFO_end_file); |
27 | 162 | // Print indentation. |
28 | 181 | for (unsigned I = 0; I < IndLevel181 ; I++19 ) |
29 | 19 | OS << " "; |
30 | 162 | IndLevel += (E.Type == DW_MACINFO_start_file); |
31 | 162 | |
32 | 162 | WithColor(OS, syntax::Macro).get() << MacinfoString(E.Type); |
33 | 162 | switch (E.Type) { |
34 | 0 | default: |
35 | 0 | // Got a corrupted ".debug_macinfo" section (invalid macinfo type). |
36 | 0 | break; |
37 | 150 | case DW_MACINFO_define: |
38 | 150 | case DW_MACINFO_undef: |
39 | 150 | OS << " - lineno: " << E.Line; |
40 | 150 | OS << " macro: " << E.MacroStr; |
41 | 150 | break; |
42 | 6 | case DW_MACINFO_start_file: |
43 | 6 | OS << " - lineno: " << E.Line; |
44 | 6 | OS << " filenum: " << E.File; |
45 | 6 | break; |
46 | 6 | case DW_MACINFO_end_file: |
47 | 6 | break; |
48 | 0 | case DW_MACINFO_vendor_ext: |
49 | 0 | OS << " - constant: " << E.ExtConstant; |
50 | 0 | OS << " string: " << E.ExtStr; |
51 | 0 | break; |
52 | 162 | } |
53 | 162 | OS << "\n"; |
54 | 162 | } |
55 | 2 | } |
56 | | |
57 | 166 | void DWARFDebugMacro::parse(DataExtractor data) { |
58 | 166 | uint32_t Offset = 0; |
59 | 328 | while (data.isValidOffset(Offset)328 ) { |
60 | 265 | // A macro list entry consists of: |
61 | 265 | Entry E; |
62 | 265 | // 1. Macinfo type |
63 | 265 | E.Type = data.getULEB128(&Offset); |
64 | 265 | |
65 | 265 | if (E.Type == 0265 ) { |
66 | 103 | // Reached end of ".debug_macinfo" section. |
67 | 103 | return; |
68 | 103 | } |
69 | 162 | |
70 | 162 | switch (E.Type) { |
71 | 0 | default: |
72 | 0 | // Got a corrupted ".debug_macinfo" section (invalid macinfo type). |
73 | 0 | // Push the corrupted entry to the list and halt parsing. |
74 | 0 | E.Type = DW_MACINFO_invalid; |
75 | 0 | Macros.push_back(E); |
76 | 0 | return; |
77 | 150 | case DW_MACINFO_define: |
78 | 150 | case DW_MACINFO_undef: |
79 | 150 | // 2. Source line |
80 | 150 | E.Line = data.getULEB128(&Offset); |
81 | 150 | // 3. Macro string |
82 | 150 | E.MacroStr = data.getCStr(&Offset); |
83 | 150 | break; |
84 | 6 | case DW_MACINFO_start_file: |
85 | 6 | // 2. Source line |
86 | 6 | E.Line = data.getULEB128(&Offset); |
87 | 6 | // 3. Source file id |
88 | 6 | E.File = data.getULEB128(&Offset); |
89 | 6 | break; |
90 | 6 | case DW_MACINFO_end_file: |
91 | 6 | break; |
92 | 0 | case DW_MACINFO_vendor_ext: |
93 | 0 | // 2. Vendor extension constant |
94 | 0 | E.ExtConstant = data.getULEB128(&Offset); |
95 | 0 | // 3. Vendor extension string |
96 | 0 | E.ExtStr = data.getCStr(&Offset); |
97 | 0 | break; |
98 | 162 | } |
99 | 162 | |
100 | 162 | Macros.push_back(E); |
101 | 162 | } |
102 | 166 | } |