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 
14 #include "lldb/Symbol/LineTable.h"
15 #include "lldb/Utility/Stream.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
21  s->Printf("0x%8.8x: Compile Unit: length = 0x%8.8x, version = 0x%4.4x, "
22  "abbr_offset = 0x%8.8x, addr_size = 0x%2.2x (next CU at "
23  "{0x%8.8x})\n",
24  GetOffset(), GetLength(), GetVersion(), GetAbbrevOffset(),
25  GetAddressByteSize(), GetNextUnitOffset());
26 }
27 
29  DWARFDebugAranges *debug_aranges) {
30  // This function is usually called if there in no .debug_aranges section in
31  // order to produce a compile unit level set of address ranges that is
32  // accurate.
33 
34  size_t num_debug_aranges = debug_aranges->GetNumRanges();
35 
36  // First get the compile unit DIE only and check contains ranges information.
37  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
38 
39  const dw_offset_t cu_offset = GetOffset();
40  if (die) {
41  DWARFRangeList ranges;
42  const size_t num_ranges =
43  die->GetAttributeAddressRanges(this, ranges, /*check_hi_lo_pc=*/true);
44  if (num_ranges > 0) {
45  for (size_t i = 0; i < num_ranges; ++i) {
46  const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
47  debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
48  range.GetRangeEnd());
49  }
50 
51  return;
52  }
53  }
54 
55  if (debug_aranges->GetNumRanges() == num_debug_aranges) {
56  // We got nothing from the debug info, try to build the arange table from
57  // the debug map OSO aranges.
58  SymbolContext sc;
59  sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
60  if (sc.comp_unit) {
61  SymbolFileDWARFDebugMap *debug_map_sym_file =
62  m_dwarf.GetDebugMapSymfile();
63  if (debug_map_sym_file) {
64  auto *cu_info =
65  debug_map_sym_file->GetCompileUnitInfo(&GetSymbolFileDWARF());
66  // If there are extra compile units the OSO entries aren't a reliable
67  // source of information.
68  if (cu_info->compile_units_sps.empty())
69  debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
70  }
71  }
72  }
73 
74  if (debug_aranges->GetNumRanges() == num_debug_aranges) {
75  // We got nothing from the functions, maybe we have a line tables only
76  // situation. Check the line tables and build the arange table from this.
77  SymbolContext sc;
78  sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
79  if (sc.comp_unit) {
80  if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
81  LineTable::FileAddressRanges file_ranges;
82  const bool append = true;
83  const size_t num_ranges =
84  line_table->GetContiguousFileAddressRanges(file_ranges, append);
85  for (uint32_t idx = 0; idx < num_ranges; ++idx) {
87  file_ranges.GetEntryRef(idx);
88  debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
89  range.GetRangeEnd());
90  }
91  }
92  }
93  }
94 }
95 
97  return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());
98 }
99 
101  if (DIE()) {
102  const DWARFDebugAranges &func_aranges = GetFunctionAranges();
103 
104  // Re-check the aranges auto pointer contents in case it was created above
105  if (!func_aranges.IsEmpty())
106  return GetDIE(func_aranges.FindAddress(address));
107  }
108  return DWARFDIE();
109 }
SymbolFileDWARFDebugMap.h
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
DWARFCompileUnit.h
CompileUnit.h
DWARFDebugAranges
Definition: DWARFDebugAranges.h:16
DWARFCompileUnit::BuildAddressRangeTable
void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) override
Definition: DWARFCompileUnit.cpp:28
lldb_private::RangeVector::GetEntryRef
Entry & GetEntryRef(size_t i)
Definition: RangeMap.h:303
lldb_private::GetVersion
const char * GetVersion()
Retrieves a string representing the complete LLDB version, which includes the lldb version number,...
Definition: Version.cpp:38
DWARFDebugAranges::FindAddress
dw_offset_t FindAddress(dw_addr_t address) const
Definition: DWARFDebugAranges.cpp:99
lldb_private::Stream
Definition: Stream.h:28
DWARFDebugInfoEntry
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
Definition: DWARFDebugInfoEntry.h:31
lldb_private::SymbolContext
Definition: SymbolContext.h:33
SymbolFileDWARFDebugMap::AddOSOARanges
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
Definition: SymbolFileDWARFDebugMap.cpp:1455
DWARFDIE
Definition: DWARFDIE.h:16
DWARFCompileUnit
Definition: DWARFCompileUnit.h:15
lldb_private::LineTable
Definition: LineTable.h:40
DWARFDebugAranges::IsEmpty
bool IsEmpty() const
Definition: DWARFDebugAranges.h:40
SymbolFileDWARFDebugMap::GetCompileUnitInfo
CompileUnitInfo * GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf)
Definition: SymbolFileDWARFDebugMap.cpp:1289
DWARFDebugAranges::GetNumRanges
size_t GetNumRanges() const
Definition: DWARFDebugAranges.h:41
DWARFDebugAranges::AppendRange
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
Definition: DWARFDebugAranges.cpp:84
SymbolFileDWARFDebugMap
Definition: SymbolFileDWARFDebugMap.h:26
DWARFDebugAranges.h
lldb_private::Range
Definition: Process.h:61
lldb_private::CompileUnit::GetLineTable
LineTable * GetLineTable()
Get the line table for the compile unit.
Definition: CompileUnit.cpp:161
lldb_private::RangeVector
Definition: RangeMap.h:136
DWARFCompileUnit::Dump
void Dump(lldb_private::Stream *s) const override
Definition: DWARFCompileUnit.cpp:20
uint32_t
LineTable.h
DWARFUnit::GetNonSkeletonUnit
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:654
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
DWARFCompileUnit::LookupAddress
DWARFDIE LookupAddress(const dw_addr_t address)
Definition: DWARFCompileUnit.cpp:100
DWARFDebugInfoEntry::GetAttributeAddressRanges
size_t GetAttributeAddressRanges(DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:630
DWARFCompileUnit::GetNonSkeletonUnit
DWARFCompileUnit & GetNonSkeletonUnit()
Definition: DWARFCompileUnit.cpp:96
Stream.h
dw_addr_t
uint64_t dw_addr_t
Definition: dwarf.h:29
lldb
Definition: SBAddress.h:15
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:78