LLDB mainline
DWARFCompileUnit.cpp
Go to the documentation of this file.
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"
12
15#include "lldb/Utility/Stream.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
21 s->Format(
22
23 "{0:x16}: Compile Unit: length = {1:x8}, version = {2:x}, "
24 "abbr_offset = {3:x8}, addr_size = {4:x2} (next CU at "
25 "[{5:x16}])\n",
28}
29
31 DWARFDebugAranges *debug_aranges) {
32 // This function is usually called if there in no .debug_aranges section in
33 // order to produce a compile unit level set of address ranges that is
34 // accurate.
35
36 size_t num_debug_aranges = debug_aranges->GetNumRanges();
37
38 // First get the compile unit DIE only and check contains ranges information.
40
41 const dw_offset_t cu_offset = GetOffset();
42 if (die) {
43 DWARFRangeList ranges =
44 die->GetAttributeAddressRanges(this, /*check_hi_lo_pc=*/true);
45 for (const DWARFRangeList::Entry &range : ranges)
46 debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
47 range.GetRangeEnd());
48
49 if (!ranges.IsEmpty())
50 return;
51 }
52
53 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
54 // We got nothing from the debug info, try to build the arange table from
55 // the debug map OSO aranges.
58 if (sc.comp_unit) {
59 SymbolFileDWARFDebugMap *debug_map_sym_file =
61 if (debug_map_sym_file) {
62 auto *cu_info =
63 debug_map_sym_file->GetCompileUnitInfo(&GetSymbolFileDWARF());
64 // If there are extra compile units the OSO entries aren't a reliable
65 // source of information.
66 if (cu_info->compile_units_sps.empty())
67 debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
68 }
69 }
70 }
71
72 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
73 // We got nothing from the functions, maybe we have a line tables only
74 // situation. Check the line tables and build the arange table from this.
77 if (sc.comp_unit) {
78 if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
80 const bool append = true;
81 const size_t num_ranges =
82 line_table->GetContiguousFileAddressRanges(file_ranges, append);
83 for (uint32_t idx = 0; idx < num_ranges; ++idx) {
85 file_ranges.GetEntryRef(idx);
86 debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
87 range.GetRangeEnd());
88 }
89 }
90 }
91 }
92}
93
95 return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());
96}
97
99 if (DIE()) {
100 const DWARFDebugAranges &func_aranges = GetFunctionAranges();
101
102 // Re-check the aranges auto pointer contents in case it was created above
103 if (!func_aranges.IsEmpty())
104 return GetDIE(func_aranges.FindAddress(address));
105 }
106 return DWARFDIE();
107}
DWARFDIE LookupAddress(const dw_addr_t address)
void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) override
DWARFCompileUnit & GetNonSkeletonUnit()
void Dump(lldb_private::Stream *s) const override
dw_offset_t FindAddress(dw_addr_t address) const
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
bool IsEmpty() const
size_t GetNumRanges() const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DWARFRangeList GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:200
dw_offset_t GetAbbrevOffset() const
Definition: DWARFUnit.cpp:442
const DWARFDebugInfoEntry * GetUnitDIEPtrOnly()
Definition: DWARFUnit.h:303
const DWARFDebugAranges & GetFunctionAranges()
Definition: DWARFUnit.cpp:858
uint16_t GetVersion() const
Definition: DWARFUnit.h:155
uint8_t GetAddressByteSize() const
Definition: DWARFUnit.h:158
dw_offset_t GetNextUnitOffset() const
Definition: DWARFUnit.h:150
SymbolFileDWARF & m_dwarf
Definition: DWARFUnit.h:323
DWARFDIE DIE()
Definition: DWARFUnit.h:180
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:663
DWARFDIE GetDIE(dw_offset_t die_offset)
Definition: DWARFUnit.cpp:642
uint32_t GetLength() const
Definition: DWARFUnit.h:154
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:134
CompileUnitInfo * GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf)
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
lldb_private::CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu)
SymbolFileDWARFDebugMap * GetDebugMapSymfile()
LineTable * GetLineTable()
Get the line table for the compile unit.
A line table class.
Definition: LineTable.h:40
Entry & GetEntryRef(size_t i)
Definition: RangeMap.h:303
bool IsEmpty() const
Definition: RangeMap.h:293
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
CompileUnit * comp_unit
The CompileUnit for a given query.
uint64_t dw_offset_t
Definition: dwarf.h:31
uint64_t dw_addr_t
Definition: dwarf.h:27
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
BaseType GetRangeBase() const
Definition: RangeMap.h:45
BaseType GetRangeEnd() const
Definition: RangeMap.h:78