Coverage Report

Created: 2019-07-24 05:18

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