1 //===-- DWARFDebugAranges.cpp -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "DWARFDebugAranges.h"
10 #include "DWARFDebugArangeSet.h"
11 #include "DWARFUnit.h"
12 #include "lldb/Utility/Log.h"
13 #include "lldb/Utility/Timer.h"
16 using namespace lldb_private;
19 DWARFDebugAranges::DWARFDebugAranges() : m_aranges() {}
21 // CountArangeDescriptors
22 class CountArangeDescriptors {
24 CountArangeDescriptors(uint32_t &count_ref) : count(count_ref) {
25 // printf("constructor CountArangeDescriptors()\n");
27 void operator()(const DWARFDebugArangeSet &set) {
28 count += set.NumDescriptors();
35 DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) {
36 lldb::offset_t offset = 0;
38 DWARFDebugArangeSet set;
40 while (debug_aranges_data.ValidOffset(offset)) {
41 llvm::Error error = set.extract(debug_aranges_data, &offset);
45 const uint32_t num_descriptors = set.NumDescriptors();
46 if (num_descriptors > 0) {
47 const dw_offset_t cu_offset = set.GetHeader().cu_offset;
49 for (uint32_t i = 0; i < num_descriptors; ++i) {
50 const DWARFDebugArangeSet::Descriptor &descriptor =
51 set.GetDescriptorRef(i);
52 m_aranges.Append(RangeToDIE::Entry(descriptor.address,
53 descriptor.length, cu_offset));
58 return llvm::ErrorSuccess();
61 void DWARFDebugAranges::Dump(Log *log) const {
65 const size_t num_entries = m_aranges.GetSize();
66 for (size_t i = 0; i < num_entries; ++i) {
67 const RangeToDIE::Entry *entry = m_aranges.GetEntryAtIndex(i);
69 log->Printf("0x%8.8x: [0x%" PRIx64 " - 0x%" PRIx64 ")", entry->data,
70 entry->GetRangeBase(), entry->GetRangeEnd());
74 void DWARFDebugAranges::AppendRange(dw_offset_t offset, dw_addr_t low_pc,
77 m_aranges.Append(RangeToDIE::Entry(low_pc, high_pc - low_pc, offset));
80 void DWARFDebugAranges::Sort(bool minimize) {
81 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
82 Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
83 static_cast<void *>(this));
86 m_aranges.CombineConsecutiveEntriesWithEqualData();
90 dw_offset_t DWARFDebugAranges::FindAddress(dw_addr_t address) const {
91 const RangeToDIE::Entry *entry = m_aranges.FindEntryThatContains(address);
94 return DW_INVALID_OFFSET;