Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- DWARFDebugAranges.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 "DWARFDebugAranges.h"
10
#include "DWARFDebugArangeSet.h"
11
#include "DWARFUnit.h"
12
#include "LogChannelDWARF.h"
13
#include "lldb/Utility/Log.h"
14
#include "lldb/Utility/Timer.h"
15
16
using namespace lldb;
17
using namespace lldb_private;
18
19
// Constructor
20
5.18k
DWARFDebugAranges::DWARFDebugAranges() : m_aranges() {}
21
22
// CountArangeDescriptors
23
class CountArangeDescriptors {
24
public:
25
0
  CountArangeDescriptors(uint32_t &count_ref) : count(count_ref) {
26
0
    //      printf("constructor CountArangeDescriptors()\n");
27
0
  }
28
0
  void operator()(const DWARFDebugArangeSet &set) {
29
0
    count += set.NumDescriptors();
30
0
  }
31
  uint32_t &count;
32
};
33
34
// Extract
35
2.62k
void DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) {
36
2.62k
  lldb::offset_t offset = 0;
37
38
2.62k
  DWARFDebugArangeSet set;
39
2.62k
  Range range;
40
3.83k
  while (debug_aranges_data.ValidOffset(offset)) {
41
1.21k
    const lldb::offset_t set_offset = offset;
42
1.21k
    if (llvm::Error error = set.extract(debug_aranges_data, &offset)) {
43
1
      Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
44
1
      LLDB_LOG_ERROR(log, std::move(error),
45
1
                     "DWARFDebugAranges::extract failed to extract "
46
1
                     ".debug_aranges set at offset %#" PRIx64,
47
1
                     set_offset);
48
1.21k
    } else {
49
1.21k
      const uint32_t num_descriptors = set.NumDescriptors();
50
1.21k
      if (num_descriptors > 0) {
51
1.21k
        const dw_offset_t cu_offset = set.GetHeader().cu_offset;
52
53
31.2k
        for (uint32_t i = 0; i < num_descriptors; 
++i30.0k
) {
54
30.0k
          const DWARFDebugArangeSet::Descriptor &descriptor =
55
30.0k
              set.GetDescriptorRef(i);
56
30.0k
          m_aranges.Append(RangeToDIE::Entry(descriptor.address,
57
30.0k
                                             descriptor.length, cu_offset));
58
30.0k
        }
59
1.21k
      }
60
1.21k
    }
61
    // Always use the previous DWARFDebugArangeSet's information to calculate
62
    // the offset of the next DWARFDebugArangeSet in case we entouncter an
63
    // error in the current DWARFDebugArangeSet and our offset position is
64
    // still in the middle of the data. If we do this, we can parse all valid
65
    // DWARFDebugArangeSet objects without returning invalid errors.
66
1.21k
    offset = set.GetNextOffset();
67
1.21k
    set.Clear();
68
1.21k
  }
69
2.62k
}
70
71
0
void DWARFDebugAranges::Dump(Log *log) const {
72
0
  if (log == nullptr)
73
0
    return;
74
75
0
  const size_t num_entries = m_aranges.GetSize();
76
0
  for (size_t i = 0; i < num_entries; ++i) {
77
0
    const RangeToDIE::Entry *entry = m_aranges.GetEntryAtIndex(i);
78
0
    if (entry)
79
0
      LLDB_LOGF(log, "0x%8.8x: [0x%" PRIx64 " - 0x%" PRIx64 ")", entry->data,
80
0
                entry->GetRangeBase(), entry->GetRangeEnd());
81
0
  }
82
0
}
83
84
void DWARFDebugAranges::AppendRange(dw_offset_t offset, dw_addr_t low_pc,
85
99.2k
                                    dw_addr_t high_pc) {
86
99.2k
  if (high_pc > low_pc)
87
99.2k
    m_aranges.Append(RangeToDIE::Entry(low_pc, high_pc - low_pc, offset));
88
99.2k
}
89
90
5.18k
void DWARFDebugAranges::Sort(bool minimize) {
91
5.18k
  LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
92
5.18k
                     static_cast<void *>(this));
93
94
5.18k
  m_aranges.Sort();
95
5.18k
  m_aranges.CombineConsecutiveEntriesWithEqualData();
96
5.18k
}
97
98
// FindAddress
99
130k
dw_offset_t DWARFDebugAranges::FindAddress(dw_addr_t address) const {
100
130k
  const RangeToDIE::Entry *entry = m_aranges.FindEntryThatContains(address);
101
130k
  if (entry)
102
128k
    return entry->data;
103
1.86k
  return DW_INVALID_OFFSET;
104
130k
}