14
14
#include < limits>
15
15
#include < optional>
16
16
17
- #include " llvm/Support/LEB128.h"
18
-
17
+ #include " LogChannelDWARF.h"
19
18
#include " lldb/Core/Module.h"
20
19
#include " lldb/Expression/DWARFExpression.h"
21
20
#include " lldb/Symbol/ObjectFile.h"
22
- #include " lldb/Utility/Stream.h"
23
- #include " lldb/Utility/StreamString.h"
21
+ #include " llvm/ADT/STLExtras.h"
22
+ #include " llvm/DebugInfo/DWARF/DWARFAddressRange.h"
23
+ #include " llvm/Support/Error.h"
24
+ #include " llvm/Support/FormatAdapters.h"
25
+ #include " llvm/Support/LEB128.h"
24
26
25
27
#include " DWARFCompileUnit.h"
26
28
#include " DWARFDebugAranges.h"
31
33
#include " SymbolFileDWARF.h"
32
34
#include " SymbolFileDWARFDwo.h"
33
35
34
- #include " llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
35
-
36
36
using namespace lldb_private ;
37
37
using namespace lldb_private ::dwarf;
38
38
using namespace lldb_private ::plugin::dwarf;
@@ -82,24 +82,11 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &data,
82
82
return true ;
83
83
}
84
84
85
- static DWARFRangeList GetRangesOrReportError (DWARFUnit &unit,
86
- const DWARFDebugInfoEntry &die,
87
- const DWARFFormValue &value) {
88
- llvm::Expected<DWARFRangeList> expected_ranges =
89
- (value.Form () == DW_FORM_rnglistx)
90
- ? unit.FindRnglistFromIndex (value.Unsigned ())
91
- : unit.FindRnglistFromOffset (value.Unsigned ());
92
- if (expected_ranges)
93
- return std::move (*expected_ranges);
94
-
95
- unit.GetSymbolFileDWARF ().GetObjectFile ()->GetModule ()->ReportError (
96
- " [{0:x16}]: DIE has DW_AT_ranges({1} {2:x16}) attribute, but "
97
- " range extraction failed ({3}), please file a bug "
98
- " and attach the file at the start of this error message" ,
99
- die.GetOffset (),
100
- llvm::dwarf::FormEncodingString (value.Form ()).str ().c_str (),
101
- value.Unsigned (), toString (expected_ranges.takeError ()).c_str ());
102
- return DWARFRangeList ();
85
+ static llvm::Expected<llvm::DWARFAddressRangesVector>
86
+ GetRanges (DWARFUnit &unit, const DWARFFormValue &value) {
87
+ return (value.Form () == DW_FORM_rnglistx)
88
+ ? unit.FindRnglistFromIndex (value.Unsigned ())
89
+ : unit.FindRnglistFromOffset (value.Unsigned ());
103
90
}
104
91
105
92
static void ExtractAttrAndFormValue (
@@ -117,7 +104,7 @@ static void ExtractAttrAndFormValue(
117
104
// DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges attributes.
118
105
bool DWARFDebugInfoEntry::GetDIENamesAndRanges (
119
106
DWARFUnit *cu, const char *&name, const char *&mangled,
120
- DWARFRangeList &ranges, std::optional<int > &decl_file,
107
+ llvm::DWARFAddressRangesVector &ranges, std::optional<int > &decl_file,
121
108
std::optional<int > &decl_line, std::optional<int > &decl_column,
122
109
std::optional<int > &call_file, std::optional<int > &call_line,
123
110
std::optional<int > &call_column, DWARFExpressionList *frame_base) const {
@@ -173,7 +160,17 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
173
160
break ;
174
161
175
162
case DW_AT_ranges:
176
- ranges = GetRangesOrReportError (*cu, *this , form_value);
163
+ if (llvm::Expected<llvm::DWARFAddressRangesVector> r =
164
+ GetRanges (*cu, form_value)) {
165
+ ranges = std::move (*r);
166
+ } else {
167
+ module->ReportError (
168
+ " [{0:x16}]: DIE has DW_AT_ranges({1} {2:x16}) attribute, but "
169
+ " range extraction failed ({3}), please file a bug "
170
+ " and attach the file at the start of this error message" ,
171
+ GetOffset (), llvm::dwarf::FormEncodingString (form_value.Form ()),
172
+ form_value.Unsigned (), fmt_consume (r.takeError ()));
173
+ }
177
174
break ;
178
175
179
176
case DW_AT_name:
@@ -259,22 +256,20 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
259
256
}
260
257
}
261
258
262
- if (ranges.IsEmpty ()) {
263
- if (lo_pc != LLDB_INVALID_ADDRESS) {
264
- if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
265
- ranges.Append (DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
266
- else
267
- ranges.Append (DWARFRangeList::Entry (lo_pc, 0 ));
268
- }
259
+ if (ranges.empty () && lo_pc != LLDB_INVALID_ADDRESS) {
260
+ lldb::addr_t range_hi_pc =
261
+ (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc) ? hi_pc : lo_pc;
262
+ ranges.emplace_back (lo_pc, range_hi_pc);
269
263
}
270
264
271
- if (set_frame_base_loclist_addr) {
272
- dw_addr_t lowest_range_pc = ranges.GetMinRangeBase (0 );
265
+ if (set_frame_base_loclist_addr && !ranges.empty ()) {
266
+ // TODO: Use the first range instead.
267
+ dw_addr_t lowest_range_pc = llvm::min_element (ranges)->LowPC ;
273
268
assert (lowest_range_pc >= cu->GetBaseAddress ());
274
269
frame_base->SetFuncFileAddress (lowest_range_pc);
275
270
}
276
271
277
- if (ranges.IsEmpty () || name == nullptr || mangled == nullptr ) {
272
+ if (ranges.empty () || name == nullptr || mangled == nullptr ) {
278
273
for (const DWARFDIE &die : dies) {
279
274
if (die) {
280
275
die.GetDIE ()->GetDIENamesAndRanges (die.GetCU (), name, mangled, ranges,
@@ -283,7 +278,7 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
283
278
}
284
279
}
285
280
}
286
- return !ranges.IsEmpty ();
281
+ return !ranges.empty ();
287
282
}
288
283
289
284
// Get all attribute values for a given DIE, including following any
@@ -499,24 +494,23 @@ bool DWARFDebugInfoEntry::GetAttributeAddressRange(
499
494
return false ;
500
495
}
501
496
502
- DWARFRangeList DWARFDebugInfoEntry::GetAttributeAddressRanges (
497
+ llvm::Expected<llvm::DWARFAddressRangesVector>
498
+ DWARFDebugInfoEntry::GetAttributeAddressRanges (
503
499
DWARFUnit *cu, bool check_hi_lo_pc, bool check_elaborating_dies) const {
504
500
505
501
DWARFFormValue form_value;
506
502
if (GetAttributeValue (cu, DW_AT_ranges, form_value))
507
- return GetRangesOrReportError (*cu, * this , form_value);
503
+ return GetRanges (*cu, form_value);
508
504
509
- DWARFRangeList ranges;
510
505
if (check_hi_lo_pc) {
511
506
dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
512
507
dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
513
508
if (GetAttributeAddressRange (cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS,
514
- check_elaborating_dies)) {
515
- if (lo_pc < hi_pc)
516
- ranges.Append (DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
517
- }
509
+ check_elaborating_dies) &&
510
+ lo_pc < hi_pc)
511
+ return llvm::DWARFAddressRangesVector{{lo_pc, hi_pc}};
518
512
}
519
- return ranges ;
513
+ return llvm::createStringError ( " DIE has no address range information " ) ;
520
514
}
521
515
522
516
// GetName
@@ -577,13 +571,15 @@ const char *DWARFDebugInfoEntry::GetPubname(const DWARFUnit *cu) const {
577
571
// / table instead of the compile unit offset.
578
572
void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable (
579
573
DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const {
574
+ Log *log = GetLog (DWARFLog::DebugInfo);
580
575
if (m_tag) {
581
576
if (m_tag == DW_TAG_subprogram) {
582
- DWARFRangeList ranges =
583
- GetAttributeAddressRanges (cu, /* check_hi_lo_pc=*/ true );
584
- for (const auto &r : ranges) {
585
- debug_aranges->AppendRange (GetOffset (), r.GetRangeBase (),
586
- r.GetRangeEnd ());
577
+ if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
578
+ GetAttributeAddressRanges (cu, /* check_hi_lo_pc=*/ true )) {
579
+ for (const auto &r : *ranges)
580
+ debug_aranges->AppendRange (GetOffset (), r.LowPC , r.HighPC );
581
+ } else {
582
+ LLDB_LOG_ERROR (log , ranges.takeError (), " DIE({1:x}): {0}" , GetOffset ());
587
583
}
588
584
}
589
585
0 commit comments