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, maybe we have a line tables only
57  // situation. Check the line tables and build the arange table from this.
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 == nullptr) {
64  if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
65  LineTable::FileAddressRanges file_ranges;
66  const bool append = true;
67  const size_t num_ranges =
68  line_table->GetContiguousFileAddressRanges(file_ranges, append);
69  for (uint32_t idx = 0; idx < num_ranges; ++idx) {
71  file_ranges.GetEntryRef(idx);
72  debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
73  range.GetRangeEnd());
74  }
75  }
76  } else
77  debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
78  }
79  }
80 
81  if (debug_aranges->GetNumRanges() == num_debug_aranges) {
82  // We got nothing from the functions, maybe we have a line tables only
83  // situation. Check the line tables and build the arange table from this.
84  SymbolContext sc;
85  sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
86  if (sc.comp_unit) {
87  if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
88  LineTable::FileAddressRanges file_ranges;
89  const bool append = true;
90  const size_t num_ranges =
91  line_table->GetContiguousFileAddressRanges(file_ranges, append);
92  for (uint32_t idx = 0; idx < num_ranges; ++idx) {
94  file_ranges.GetEntryRef(idx);
95  debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
96  range.GetRangeEnd());
97  }
98  }
99  }
100  }
101 }
102 
104  return llvm::cast<DWARFCompileUnit>(DWARFUnit::GetNonSkeletonUnit());
105 }
106 
108  if (DIE()) {
109  const DWARFDebugAranges &func_aranges = GetFunctionAranges();
110 
111  // Re-check the aranges auto pointer contents in case it was created above
112  if (!func_aranges.IsEmpty())
113  return GetDIE(func_aranges.FindAddress(address));
114  }
115  return DWARFDIE();
116 }
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:260
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:1424
DWARFDIE
Definition: DWARFDIE.h:15
DWARFCompileUnit
Definition: DWARFCompileUnit.h:15
lldb_private::LineTable
Definition: LineTable.h:40
DWARFDebugAranges::IsEmpty
bool IsEmpty() const
Definition: DWARFDebugAranges.h:40
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:25
DWARFDebugAranges.h
lldb_private::Range
Definition: Process.h:60
lldb_private::CompileUnit::GetLineTable
LineTable * GetLineTable()
Get the line table for the compile unit.
Definition: CompileUnit.cpp:155
lldb_private::RangeVector
Definition: RangeMap.h:125
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:581
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:107
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:617
DWARFCompileUnit::GetNonSkeletonUnit
DWARFCompileUnit & GetNonSkeletonUnit()
Definition: DWARFCompileUnit.cpp:103
Stream.h
dw_addr_t
uint64_t dw_addr_t
Definition: dwarf.h:26
lldb
Definition: SBAddress.h:15
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:62