Skip to content

Commit e8a039d

Browse files
committed
Permit cross-CU references
So far dw_offset_t was global for the whole SymbolFileDWARF but with .debug_types the same dw_offset_t may mean two different things depending on its section (=CU). So references now return whole new referenced DWARFDIE instead of just dw_offset_t. This means that some functions have to now handle 16 bytes instead of 8 bytes but I do not see that anywhere performance critical. Differential Revision: https://reviews.llvm.org/D61502 llvm-svn: 360795
1 parent 5e6ea24 commit e8a039d

File tree

13 files changed

+110
-131
lines changed

13 files changed

+110
-131
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
DIERef::DIERef(const DWARFFormValue &form_value)
1717
: cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) {
1818
if (form_value.IsValid()) {
19-
if (const DWARFUnit *unit = form_value.GetUnit()) {
20-
if (unit->GetBaseObjOffset() != DW_INVALID_OFFSET)
21-
cu_offset = unit->GetBaseObjOffset();
19+
DWARFDIE die = form_value.Reference();
20+
die_offset = die.GetOffset();
21+
if (die) {
22+
if (die.GetCU()->GetBaseObjOffset() != DW_INVALID_OFFSET)
23+
cu_offset = die.GetCU()->GetBaseObjOffset();
2224
else
23-
cu_offset = unit->GetOffset();
25+
cu_offset = die.GetCU()->GetOffset();
2426
}
25-
die_offset = form_value.Reference();
2627
}
2728
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
348348
// will have a hard time tracking down an unnammed structure type in
349349
// the module DWO file, so we make sure we don't get into this
350350
// situation by always resolving typedefs from the DWO file.
351-
const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid));
351+
const DWARFDIE encoding_die = encoding_uid.Reference();
352352

353353
// First make sure that the die that this is typedef'ed to _is_ just
354354
// a declaration (DW_AT_declaration == 1), not a full definition
@@ -499,7 +499,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
499499
// Clang sometimes erroneously emits id as objc_object*. In that
500500
// case we fix up the type to "id".
501501

502-
const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid));
502+
const DWARFDIE encoding_die = encoding_uid.Reference();
503503

504504
if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) {
505505
if (const char *struct_name = encoding_die.GetName()) {
@@ -1150,7 +1150,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
11501150
bool has_template_params = false;
11511151
DWARFFormValue specification_die_form;
11521152
DWARFFormValue abstract_origin_die_form;
1153-
dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
1153+
DWARFDIE object_pointer_die;
11541154

11551155
unsigned type_quals = 0;
11561156
clang::StorageClass storage =
@@ -1221,7 +1221,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
12211221
break;
12221222

12231223
case DW_AT_object_pointer:
1224-
object_pointer_die_offset = form_value.Reference();
1224+
object_pointer_die = form_value.Reference();
12251225
break;
12261226

12271227
case DW_AT_allocated:
@@ -1254,13 +1254,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
12541254
}
12551255

12561256
std::string object_pointer_name;
1257-
if (object_pointer_die_offset != DW_INVALID_OFFSET) {
1258-
DWARFDIE object_pointer_die = die.GetDIE(object_pointer_die_offset);
1259-
if (object_pointer_die) {
1260-
const char *object_pointer_name_cstr = object_pointer_die.GetName();
1261-
if (object_pointer_name_cstr)
1262-
object_pointer_name = object_pointer_name_cstr;
1263-
}
1257+
if (object_pointer_die) {
1258+
const char *object_pointer_name_cstr = object_pointer_die.GetName();
1259+
if (object_pointer_name_cstr)
1260+
object_pointer_name = object_pointer_name_cstr;
12641261
}
12651262

12661263
DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
@@ -1422,9 +1419,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
14221419
LinkDeclContextToDIE(spec_clang_decl_ctx, die);
14231420
} else {
14241421
dwarf->GetObjectFile()->GetModule()->ReportWarning(
1425-
"0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8" PRIx64
1422+
"0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x"
14261423
") has no decl\n",
1427-
die.GetID(), specification_die_form.Reference());
1424+
die.GetID(),
1425+
specification_die_form.Reference().GetOffset());
14281426
}
14291427
type_handled = true;
14301428
} else if (abstract_origin_die_form.IsValid()) {
@@ -1442,9 +1440,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
14421440
LinkDeclContextToDIE(abs_clang_decl_ctx, die);
14431441
} else {
14441442
dwarf->GetObjectFile()->GetModule()->ReportWarning(
1445-
"0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8" PRIx64
1443+
"0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x"
14461444
") has no decl\n",
1447-
die.GetID(), abstract_origin_die_form.Reference());
1445+
die.GetID(),
1446+
abstract_origin_die_form.Reference().GetOffset());
14481447
}
14491448
type_handled = true;
14501449
} else {
@@ -1587,8 +1586,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
15871586
clang::FunctionDecl *template_function_decl = nullptr;
15881587

15891588
if (abstract_origin_die_form.IsValid()) {
1590-
DWARFDIE abs_die =
1591-
dwarf->DebugInfo()->GetDIE(DIERef(abstract_origin_die_form));
1589+
DWARFDIE abs_die = abstract_origin_die_form.Reference();
15921590

15931591
SymbolContext sc;
15941592

@@ -3070,9 +3068,10 @@ bool DWARFASTParserClang::ParseChildMembers(
30703068
member_byte_offset > parent_byte_size)) {
30713069
module_sp->ReportError(
30723070
"0x%8.8" PRIx64
3073-
": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64
3071+
": DW_TAG_member '%s' refers to type 0x%8.8x"
30743072
" which extends beyond the bounds of 0x%8.8" PRIx64,
3075-
die.GetID(), name, encoding_form.Reference(),
3073+
die.GetID(), name,
3074+
encoding_form.Reference().GetOffset(),
30763075
parent_die.GetID());
30773076
}
30783077

@@ -3135,15 +3134,14 @@ bool DWARFASTParserClang::ParseChildMembers(
31353134
if (name)
31363135
module_sp->ReportError(
31373136
"0x%8.8" PRIx64
3138-
": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64
3137+
": DW_TAG_member '%s' refers to type 0x%8.8x"
31393138
" which was unable to be parsed",
3140-
die.GetID(), name, encoding_form.Reference());
3139+
die.GetID(), name, encoding_form.Reference().GetOffset());
31413140
else
31423141
module_sp->ReportError(
3143-
"0x%8.8" PRIx64
3144-
": DW_TAG_member refers to type 0x%8.8" PRIx64
3142+
"0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8x"
31453143
" which was unable to be parsed",
3146-
die.GetID(), encoding_form.Reference());
3144+
die.GetID(), encoding_form.Reference().GetOffset());
31473145
}
31483146
}
31493147

@@ -3253,11 +3251,12 @@ bool DWARFASTParserClang::ParseChildMembers(
32533251
Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form));
32543252
if (base_class_type == NULL) {
32553253
module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to "
3256-
"resolve the base class at 0x%8.8" PRIx64
3254+
"resolve the base class at 0x%8.8x"
32573255
" from enclosing type 0x%8.8x. \nPlease file "
32583256
"a bug and attach the file at the start of "
32593257
"this error message",
3260-
die.GetOffset(), encoding_form.Reference(),
3258+
die.GetOffset(),
3259+
encoding_form.Reference().GetOffset(),
32613260
parent_die.GetOffset());
32623261
break;
32633262
}
@@ -3550,7 +3549,7 @@ Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) {
35503549

35513550
if (attr == DW_AT_type &&
35523551
attributes.ExtractFormValueAtIndex(i, form_value))
3553-
return dwarf->ResolveTypeUID(dwarf->GetDIE(DIERef(form_value)), true);
3552+
return dwarf->ResolveTypeUID(form_value.Reference(), true);
35543553
}
35553554
}
35563555
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,18 @@ bool DWARFAttributes::ExtractFormValueAtIndex(
4141
return form_value.ExtractValue(cu->GetData(), &offset);
4242
}
4343

44-
uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr,
45-
uint64_t fail_value) const {
44+
DWARFDIE
45+
DWARFAttributes::FormValueAsReference(dw_attr_t attr) const {
4646
const uint32_t attr_idx = FindAttributeIndex(attr);
4747
if (attr_idx != UINT32_MAX)
48-
return FormValueAsUnsignedAtIndex(attr_idx, fail_value);
49-
return fail_value;
48+
return FormValueAsReferenceAtIndex(attr_idx);
49+
return {};
5050
}
5151

52-
uint64_t
53-
DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i,
54-
uint64_t fail_value) const {
52+
DWARFDIE
53+
DWARFAttributes::FormValueAsReferenceAtIndex(uint32_t i) const {
5554
DWARFFormValue form_value;
5655
if (ExtractFormValueAtIndex(i, form_value))
5756
return form_value.Reference();
58-
return fail_value;
57+
return {};
5958
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class DWARFAttributes {
6565
}
6666
dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); }
6767
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const;
68-
uint64_t FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const;
69-
uint64_t FormValueAsUnsigned(dw_attr_t attr, uint64_t fail_value) const;
68+
DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const;
69+
DWARFDIE FormValueAsReference(dw_attr_t attr) const;
7070
uint32_t FindAttributeIndex(dw_attr_t attr) const;
7171
void Clear() { m_infos.clear(); }
7272
size_t Size() const { return m_infos.size(); }

lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ uint64_t DWARFBaseDIE::GetAttributeValueAsUnsigned(const dw_attr_t attr,
5656
return fail_value;
5757
}
5858

59-
uint64_t DWARFBaseDIE::GetAttributeValueAsReference(const dw_attr_t attr,
60-
uint64_t fail_value) const {
61-
if (IsValid())
62-
return m_die->GetAttributeValueAsReference(GetDWARF(), GetCU(), attr,
63-
fail_value);
64-
else
65-
return fail_value;
66-
}
67-
6859
uint64_t DWARFBaseDIE::GetAttributeValueAsAddress(const dw_attr_t attr,
6960
uint64_t fail_value) const {
7061
if (IsValid())

lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DWARFUnit;
1919
class DWARFDebugInfoEntry;
2020
class DWARFDeclContext;
2121
class SymbolFileDWARF;
22+
class DWARFDIE;
2223

2324
class DWARFBaseDIE {
2425
public:
@@ -113,9 +114,6 @@ class DWARFBaseDIE {
113114
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr,
114115
uint64_t fail_value) const;
115116

116-
uint64_t GetAttributeValueAsReference(const dw_attr_t attr,
117-
uint64_t fail_value) const;
118-
119117
uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
120118
uint64_t fail_value) const;
121119

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ DWARFDIE::GetSibling() const {
112112

113113
DWARFDIE
114114
DWARFDIE::GetReferencedDIE(const dw_attr_t attr) const {
115-
const dw_offset_t die_offset =
116-
GetAttributeValueAsReference(attr, DW_INVALID_OFFSET);
117-
if (die_offset != DW_INVALID_OFFSET)
118-
return GetDIE(die_offset);
115+
if (IsValid())
116+
return m_die->GetAttributeValueAsReference(GetDWARF(), GetCU(), attr);
119117
else
120-
return DWARFDIE();
118+
return {};
121119
}
122120

123121
DWARFDIE
@@ -137,7 +135,7 @@ DWARFDIE::GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const {
137135
DWARFFormValue form_value;
138136
if (m_die->GetAttributeValue(dwarf, cu, attr, form_value, nullptr,
139137
check_specification_or_abstract_origin))
140-
return dwarf->GetDIE(DIERef(form_value));
138+
return form_value.Reference();
141139
}
142140
return DWARFDIE();
143141
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -693,16 +693,16 @@ void DWARFDebugInfoEntry::DumpAttribute(
693693

694694
case DW_AT_abstract_origin:
695695
case DW_AT_specification: {
696-
uint64_t abstract_die_offset = form_value.Reference();
696+
DWARFDIE abstract_die = form_value.Reference();
697697
form_value.Dump(s);
698-
// *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
699-
GetName(dwarf2Data, cu, abstract_die_offset, s);
698+
// *ostrm_ptr << HEX32 << abstract_die.GetOffset() << " ( ";
699+
GetName(dwarf2Data, abstract_die.GetCU(), abstract_die.GetOffset(), s);
700700
} break;
701701

702702
case DW_AT_type: {
703-
uint64_t type_die_offset = form_value.Reference();
703+
DWARFDIE type_die = form_value.Reference();
704704
s.PutCString(" ( ");
705-
AppendTypeName(dwarf2Data, cu, type_die_offset, s);
705+
AppendTypeName(dwarf2Data, type_die.GetCU(), type_die.GetOffset(), s);
706706
s.PutCString(" )");
707707
} break;
708708

@@ -734,13 +734,6 @@ size_t DWARFDebugInfoEntry::GetAttributes(
734734
const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
735735
lldb::offset_t offset = 0;
736736
if (cu) {
737-
if (m_tag != DW_TAG_compile_unit && m_tag != DW_TAG_partial_unit) {
738-
SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
739-
if (dwo_symbol_file)
740-
return GetAttributes(dwo_symbol_file->GetCompileUnit(),
741-
fixed_form_sizes, attributes, curr_depth);
742-
}
743-
744737
dwarf2Data = cu->GetSymbolFileDWARF();
745738
abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
746739
}
@@ -779,9 +772,7 @@ size_t DWARFDebugInfoEntry::GetAttributes(
779772

780773
if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
781774
if (form_value.ExtractValue(debug_info_data, &offset)) {
782-
dw_offset_t die_offset = form_value.Reference();
783-
DWARFDIE spec_die =
784-
const_cast<DWARFUnit *>(cu)->GetDIE(die_offset);
775+
DWARFDIE spec_die = form_value.Reference();
785776
if (spec_die)
786777
spec_die.GetAttributes(attributes, curr_depth + 1);
787778
}
@@ -845,8 +836,7 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
845836

846837
if (check_specification_or_abstract_origin) {
847838
if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) {
848-
DWARFDIE die =
849-
const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
839+
DWARFDIE die = form_value.Reference();
850840
if (die) {
851841
dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
852842
die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
@@ -857,8 +847,7 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
857847
}
858848

859849
if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) {
860-
DWARFDIE die =
861-
const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
850+
DWARFDIE die = form_value.Reference();
862851
if (die) {
863852
dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
864853
die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
@@ -920,15 +909,14 @@ uint64_t DWARFDebugInfoEntry::GetAttributeValueAsUnsigned(
920909
//
921910
// Get the value of an attribute as reference and fix up and compile unit
922911
// relative offsets as needed.
923-
uint64_t DWARFDebugInfoEntry::GetAttributeValueAsReference(
924-
SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
925-
const dw_attr_t attr, uint64_t fail_value,
912+
DWARFDIE DWARFDebugInfoEntry::GetAttributeValueAsReference(
913+
SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr,
926914
bool check_specification_or_abstract_origin) const {
927915
DWARFFormValue form_value;
928916
if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
929917
check_specification_or_abstract_origin))
930918
return form_value.Reference();
931-
return fail_value;
919+
return {};
932920
}
933921

934922
uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress(
@@ -1207,8 +1195,9 @@ bool DWARFDebugInfoEntry::AppendTypeName(SymbolFileDWARF *dwarf2Data,
12071195
// Follow the DW_AT_type if possible
12081196
DWARFFormValue form_value;
12091197
if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value)) {
1210-
uint64_t next_die_offset = form_value.Reference();
1211-
result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1198+
DWARFDIE next_die = form_value.Reference();
1199+
result = AppendTypeName(dwarf2Data, next_die.GetCU(),
1200+
next_die.GetOffset(), s);
12121201
}
12131202

12141203
switch (abbrevDecl->Tag()) {
@@ -1353,28 +1342,18 @@ DWARFDebugInfoEntry::GetParentDeclContextDIE(
13531342
}
13541343
}
13551344

1356-
dw_offset_t die_offset;
1357-
1358-
die_offset =
1359-
attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1360-
if (die_offset != DW_INVALID_OFFSET) {
1361-
DWARFDIE spec_die = cu->GetDIE(die_offset);
1362-
if (spec_die) {
1363-
DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1364-
if (decl_ctx_die)
1365-
return decl_ctx_die;
1366-
}
1345+
DWARFDIE spec_die = attributes.FormValueAsReference(DW_AT_specification);
1346+
if (spec_die) {
1347+
DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1348+
if (decl_ctx_die)
1349+
return decl_ctx_die;
13671350
}
13681351

1369-
die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin,
1370-
DW_INVALID_OFFSET);
1371-
if (die_offset != DW_INVALID_OFFSET) {
1372-
DWARFDIE abs_die = cu->GetDIE(die_offset);
1373-
if (abs_die) {
1374-
DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1375-
if (decl_ctx_die)
1376-
return decl_ctx_die;
1377-
}
1352+
DWARFDIE abs_die = attributes.FormValueAsReference(DW_AT_abstract_origin);
1353+
if (abs_die) {
1354+
DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1355+
if (decl_ctx_die)
1356+
return decl_ctx_die;
13781357
}
13791358

13801359
die = die.GetParent();

0 commit comments

Comments
 (0)