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 "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
21 
22 // CountArangeDescriptors
24 public:
25  CountArangeDescriptors(uint32_t &count_ref) : count(count_ref) {
26  // printf("constructor CountArangeDescriptors()\n");
27  }
29  count += set.NumDescriptors();
30  }
32 };
33 
34 // Extract
35 void 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  const lldb::offset_t set_offset = offset;
42  if (llvm::Error error = set.extract(debug_aranges_data, &offset)) {
43  Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
44  LLDB_LOG_ERROR(log, std::move(error),
45  "DWARFDebugAranges::extract failed to extract "
46  ".debug_aranges set at offset %#" PRIx64,
47  set_offset);
48  } else {
49  const uint32_t num_descriptors = set.NumDescriptors();
50  if (num_descriptors > 0) {
51  const dw_offset_t cu_offset = set.GetHeader().cu_offset;
52 
53  for (uint32_t i = 0; i < num_descriptors; ++i) {
54  const DWARFDebugArangeSet::Descriptor &descriptor =
55  set.GetDescriptorRef(i);
57  descriptor.length, cu_offset));
58  }
59  }
60  }
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  offset = set.GetNextOffset();
67  set.Clear();
68  }
69 }
70 
71 void DWARFDebugAranges::Dump(Log *log) const {
72  if (log == nullptr)
73  return;
74 
75  const size_t num_entries = m_aranges.GetSize();
76  for (size_t i = 0; i < num_entries; ++i) {
78  if (entry)
79  LLDB_LOGF(log, "0x%8.8x: [0x%" PRIx64 " - 0x%" PRIx64 ")", entry->data,
80  entry->GetRangeBase(), entry->GetRangeEnd());
81  }
82 }
83 
85  dw_addr_t high_pc) {
86  if (high_pc > low_pc)
87  m_aranges.Append(RangeToDIE::Entry(low_pc, high_pc - low_pc, offset));
88 }
89 
90 void DWARFDebugAranges::Sort(bool minimize) {
91  LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
92  static_cast<void *>(this));
93 
94  m_aranges.Sort();
96 }
97 
98 // FindAddress
100  const RangeToDIE::Entry *entry = m_aranges.FindEntryThatContains(address);
101  if (entry)
102  return entry->data;
103  return DW_INVALID_OFFSET;
104 }
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
LLDB_SCOPED_TIMERF
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:82
CountArangeDescriptors::count
uint32_t & count
Definition: DWARFDebugAranges.cpp:31
lldb_private::DataExtractor::ValidOffset
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:945
CountArangeDescriptors
Definition: DWARFDebugAranges.cpp:23
DWARFDebugAranges::Sort
void Sort(bool minimize)
Definition: DWARFDebugAranges.cpp:90
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::RangeDataVector::Sort
void Sort()
Definition: RangeMap.h:411
DWARFDebugArangeSet::Descriptor::length
dw_addr_t length
Definition: DWARFDebugArangeSet.h:38
DWARFDebugArangeSet.h
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::RangeDataVector::GetEntryAtIndex
const Entry * GetEntryAtIndex(size_t i) const
Definition: RangeMap.h:479
DWARFDebugAranges::FindAddress
dw_offset_t FindAddress(dw_addr_t address) const
Definition: DWARFDebugAranges.cpp:99
lldb_private::RangeData
Definition: RangeMap.h:373
lldb_private::DWARFDataExtractor
Definition: DWARFDataExtractor.h:18
DW_INVALID_OFFSET
#define DW_INVALID_OFFSET
Definition: dwarf.h:34
DWARFDebugArangeSet
Definition: DWARFDebugArangeSet.h:16
lldb_private::RangeDataVector::FindEntryThatContains
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:514
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::RangeDataVector::Append
void Append(const Entry &entry)
Definition: RangeMap.h:409
Log.h
DWARF_LOG_DEBUG_INFO
#define DWARF_LOG_DEBUG_INFO
Definition: LogChannelDWARF.h:14
DWARFDebugAranges::AppendRange
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
Definition: DWARFDebugAranges.cpp:84
Timer.h
DWARFDebugAranges::Dump
void Dump(lldb_private::Log *log) const
Definition: DWARFDebugAranges.cpp:71
DWARFDebugAranges.h
LogChannelDWARF.h
set
set(option_framework FRAMEWORK) endif() if(LLDB_ENABLE_PYTHON) get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR) set(lldb_python_wrapper $
Definition: API/CMakeLists.txt:9
DWARFUnit.h
CountArangeDescriptors::CountArangeDescriptors
CountArangeDescriptors(uint32_t &count_ref)
Definition: DWARFDebugAranges.cpp:25
DWARFDebugAranges::m_aranges
RangeToDIE m_aranges
Definition: DWARFDebugAranges.h:51
uint32_t
lldb_private::RangeDataVector::GetSize
size_t GetSize() const
Definition: RangeMap.h:477
CountArangeDescriptors::operator()
void operator()(const DWARFDebugArangeSet &set)
Definition: DWARFDebugAranges.cpp:28
DWARFDebugAranges::DWARFDebugAranges
DWARFDebugAranges()
Definition: DWARFDebugAranges.cpp:20
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
DWARFDebugArangeSet::Descriptor::address
dw_addr_t address
Definition: DWARFDebugArangeSet.h:37
DWARFDebugAranges::extract
void extract(const lldb_private::DWARFDataExtractor &debug_aranges_data)
Definition: DWARFDebugAranges.cpp:35
DWARFDebugArangeSet::Descriptor
Definition: DWARFDebugArangeSet.h:36
lldb_private::Log
Definition: Log.h:49
lldb_private::RangeData::data
DataType data
Definition: RangeMap.h:376
dw_addr_t
uint64_t dw_addr_t
Definition: dwarf.h:26
lldb_private::RangeDataVector::CombineConsecutiveEntriesWithEqualData
void CombineConsecutiveEntriesWithEqualData()
Definition: RangeMap.h:437
lldb
Definition: SBAddress.h:15
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:265
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:62