Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- DWARFCompileUnit.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 "DWARFCompileUnit.h"
10
#include "DWARFDebugAranges.h"
11
#include "SymbolFileDWARFDebugMap.h"
12
13
#include "lldb/Symbol/CompileUnit.h"
14
#include "lldb/Symbol/LineTable.h"
15
#include "lldb/Utility/Stream.h"
16
17
using namespace lldb;
18
using namespace lldb_private;
19
20
0
void DWARFCompileUnit::Dump(Stream *s) const {
21
0
  s->Printf("0x%8.8x: Compile Unit: length = 0x%8.8x, version = 0x%4.4x, "
22
0
            "abbr_offset = 0x%8.8x, addr_size = 0x%2.2x (next CU at "
23
0
            "{0x%8.8x})\n",
24
0
            GetOffset(), GetLength(), GetVersion(), GetAbbrevOffset(),
25
0
            GetAddressByteSize(), GetNextUnitOffset());
26
0
}
27
28
void DWARFCompileUnit::BuildAddressRangeTable(
29
2.47k
    DWARFDebugAranges *debug_aranges) {
30
  // This function is usually called if there in no .debug_aranges section in
31
  // order to produce a compile unit level set of address ranges that is
32
  // accurate.
33
34
2.47k
  size_t num_debug_aranges = debug_aranges->GetNumRanges();
35
36
  // First get the compile unit DIE only and check contains ranges information.
37
2.47k
  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
38
39
2.47k
  const dw_offset_t cu_offset = GetOffset();
40
2.47k
  if (die) {
41
2.47k
    DWARFRangeList ranges;
42
2.47k
    const size_t num_ranges =
43
2.47k
        die->GetAttributeAddressRanges(this, ranges, /*check_hi_lo_pc=*/true);
44
2.47k
    if (num_ranges > 0) {
45
3.33k
      for (size_t i = 0; i < num_ranges; 
++i1.79k
) {
46
1.79k
        const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
47
1.79k
        debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
48
1.79k
                                   range.GetRangeEnd());
49
1.79k
      }
50
51
1.53k
      return;
52
1.53k
    }
53
2.47k
  }
54
55
939
  if (debug_aranges->GetNumRanges() == num_debug_aranges) {
56
    // We got nothing from the debug info, maybe we have a line tables only
57
    // situation. Check the line tables and build the arange table from this.
58
939
    SymbolContext sc;
59
939
    sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
60
939
    if (sc.comp_unit) {
61
939
      SymbolFileDWARFDebugMap *debug_map_sym_file =
62
939
          m_dwarf.GetDebugMapSymfile();
63
939
      if (debug_map_sym_file == nullptr) {
64
25
        if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
65
25
          LineTable::FileAddressRanges file_ranges;
66
25
          const bool append = true;
67
25
          const size_t num_ranges =
68
25
              line_table->GetContiguousFileAddressRanges(file_ranges, append);
69
25
          for (uint32_t idx = 0; idx < num_ranges; 
++idx0
) {
70
0
            const LineTable::FileAddressRanges::Entry &range =
71
0
                file_ranges.GetEntryRef(idx);
72
0
            debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
73
0
                                       range.GetRangeEnd());
74
0
          }
75
25
        }
76
25
      } else
77
914
        debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
78
939
    }
79
939
  }
80
81
939
  if (debug_aranges->GetNumRanges() == num_debug_aranges) {
82
    // We got nothing from the functions, maybe we have a line tables only
83
    // situation. Check the line tables and build the arange table from this.
84
25
    SymbolContext sc;
85
25
    sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
86
25
    if (sc.comp_unit) {
87
25
      if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
88
25
        LineTable::FileAddressRanges file_ranges;
89
25
        const bool append = true;
90
25
        const size_t num_ranges =
91
25
            line_table->GetContiguousFileAddressRanges(file_ranges, append);
92
25
        for (uint32_t idx = 0; idx < num_ranges; 
++idx0
) {
93
0
          const LineTable::FileAddressRanges::Entry &range =
94
0
              file_ranges.GetEntryRef(idx);
95
0
          debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
96
0
                                     range.GetRangeEnd());
97
0
        }
98
25
      }
99
25
    }
100
25
  }
101
939
}
102
103
67.5k
DWARFCompileUnit &DWARFCompileUnit::GetNonSkeletonUnit() {
104
67.5k
  return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());
105
67.5k
}
106
107
58.5k
DWARFDIE DWARFCompileUnit::LookupAddress(const dw_addr_t address) {
108
58.5k
  if (DIE()) {
109
58.5k
    const DWARFDebugAranges &func_aranges = GetFunctionAranges();
110
111
    // Re-check the aranges auto pointer contents in case it was created above
112
58.5k
    if (!func_aranges.IsEmpty())
113
58.5k
      return GetDIE(func_aranges.FindAddress(address));
114
58.5k
  }
115
10
  return DWARFDIE();
116
58.5k
}