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;
19using namespace lldb_private::plugin::dwarf;
20
22 s->Format(
23
24 "{0:x16}: Compile Unit: length = {1:x8}, version = {2:x}, "
25 "abbr_offset = {3:x8}, addr_size = {4:x2} (next CU at "
26 "[{5:x16}])\n",
27 GetOffset(), GetLength(), GetVersion(), (uint32_t)GetAbbrevOffset(),
29}
30
32 DWARFDebugAranges *debug_aranges) {
33 // This function is usually called if there in no .debug_aranges section in
34 // order to produce a compile unit level set of address ranges that is
35 // accurate.
36
37 size_t num_debug_aranges = debug_aranges->GetNumRanges();
38
39 // First get the compile unit DIE only and check contains ranges information.
41
42 const dw_offset_t cu_offset = GetOffset();
43 if (die) {
44 DWARFRangeList ranges =
45 die->GetAttributeAddressRanges(this, /*check_hi_lo_pc=*/true);
46 for (const DWARFRangeList::Entry &range : ranges)
47 debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
48 range.GetRangeEnd());
49
50 if (!ranges.IsEmpty())
51 return;
52 }
53
54 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
55 // We got nothing from the debug info, try to build the arange table from
56 // the debug map OSO aranges.
59 if (sc.comp_unit) {
60 SymbolFileDWARFDebugMap *debug_map_sym_file =
62 if (debug_map_sym_file) {
63 auto *cu_info =
64 debug_map_sym_file->GetCompileUnitInfo(&GetSymbolFileDWARF());
65 // If there are extra compile units the OSO entries aren't a reliable
66 // source of information.
67 if (cu_info->compile_units_sps.empty())
68 debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
69 }
70 }
71 }
72
73 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
74 // We got nothing from the functions, maybe we have a line tables only
75 // situation. Check the line tables and build the arange table from this.
78 if (sc.comp_unit) {
79 if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
81 const bool append = true;
82 const size_t num_ranges =
83 line_table->GetContiguousFileAddressRanges(file_ranges, append);
84 for (uint32_t idx = 0; idx < num_ranges; ++idx) {
86 file_ranges.GetEntryRef(idx);
87 debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
88 range.GetRangeEnd());
89 }
90 }
91 }
92 }
93}
94
96 return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());
97}
98
100 if (DIE()) {
101 const DWARFDebugAranges &func_aranges = GetFunctionAranges();
102
103 // Re-check the aranges auto pointer contents in case it was created above
104 if (!func_aranges.IsEmpty())
105 return GetDIE(func_aranges.FindAddress(address));
106 }
107 return DWARFDIE();
108}
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:353
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
CompileUnit * comp_unit
The CompileUnit for a given query.
DWARFDIE LookupAddress(const dw_addr_t address)
void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) 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)
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
const DWARFDebugInfoEntry * GetUnitDIEPtrOnly()
Definition: DWARFUnit.h:285
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:181
const DWARFDebugAranges & GetFunctionAranges()
Definition: DWARFUnit.cpp:914
dw_offset_t GetNextUnitOffset() const
Definition: DWARFUnit.h:114
DWARFDIE GetDIE(dw_offset_t die_offset)
Definition: DWARFUnit.cpp:652
CompileUnitInfo * GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf)
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu)
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: SBAddress.h:15
BaseType GetRangeBase() const
Definition: RangeMap.h:45
BaseType GetRangeEnd() const
Definition: RangeMap.h:78