LLDB  mainline
DWARFDebugAranges.cpp
Go to the documentation of this file.
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 "lldb/Utility/Log.h"
13 #include "lldb/Utility/Timer.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 // Constructor
20 
21 // CountArangeDescriptors
23 public:
24  CountArangeDescriptors(uint32_t &count_ref) : count(count_ref) {
25  // printf("constructor CountArangeDescriptors()\n");
26  }
27  void operator()(const DWARFDebugArangeSet &set) {
28  count += set.NumDescriptors();
29  }
31 };
32 
33 // Extract
35 DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) {
36  lldb::offset_t offset = 0;
37 
39  Range range;
40  while (debug_aranges_data.ValidOffset(offset)) {
41  llvm::Error error = set.extract(debug_aranges_data, &offset);
42  if (!error)
43  return error;
44 
45  const uint32_t num_descriptors = set.NumDescriptors();
46  if (num_descriptors > 0) {
47  const dw_offset_t cu_offset = set.GetHeader().cu_offset;
48 
49  for (uint32_t i = 0; i < num_descriptors; ++i) {
50  const DWARFDebugArangeSet::Descriptor &descriptor =
51  set.GetDescriptorRef(i);
53  descriptor.length, cu_offset));
54  }
55  }
56  set.Clear();
57  }
58  return llvm::ErrorSuccess();
59 }
60 
61 void DWARFDebugAranges::Dump(Log *log) const {
62  if (log == nullptr)
63  return;
64 
65  const size_t num_entries = m_aranges.GetSize();
66  for (size_t i = 0; i < num_entries; ++i) {
68  if (entry)
69  LLDB_LOGF(log, "0x%8.8x: [0x%" PRIx64 " - 0x%" PRIx64 ")", entry->data,
70  entry->GetRangeBase(), entry->GetRangeEnd());
71  }
72 }
73 
75  dw_addr_t high_pc) {
76  if (high_pc > low_pc)
77  m_aranges.Append(RangeToDIE::Entry(low_pc, high_pc - low_pc, offset));
78 }
79 
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));
84 
85  m_aranges.Sort();
87 }
88 
89 // FindAddress
91  const RangeToDIE::Entry *entry = m_aranges.FindEntryThatContains(address);
92  if (entry)
93  return entry->data;
94  return DW_INVALID_OFFSET;
95 }
A class that represents a running process on the host machine.
dw_offset_t FindAddress(dw_addr_t address) const
CountArangeDescriptors(uint32_t &count_ref)
void CombineConsecutiveEntriesWithEqualData()
Definition: RangeMap.h:449
llvm::Error Error
A timer class that simplifies common timing metrics.
Definition: Timer.h:23
uint64_t dw_addr_t
Definition: dwarf.h:26
void Sort(bool minimize)
uint64_t offset_t
Definition: lldb-types.h:87
const Entry * GetEntryAtIndex(size_t i) const
Definition: RangeMap.h:491
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
void Dump(lldb_private::Log *log) const
void Append(const Entry &entry)
Definition: RangeMap.h:421
llvm::Error extract(const lldb_private::DWARFDataExtractor &debug_aranges_data)
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
#define LLDB_LOGF(log,...)
Definition: Log.h:249
Definition: SBAddress.h:15
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:526
#define DW_INVALID_OFFSET
Definition: dwarf.h:34
BaseType GetRangeEnd() const
Definition: RangeMap.h:62
void operator()(const DWARFDebugArangeSet &set)
BaseType GetRangeBase() const
Definition: RangeMap.h:46