Skip to content

Commit 25d5589

Browse files
committed
Revert PeekDIEName related patch
Summary: Revert "[lldb][DWARFUnit] Implement PeekDIEName query (llvm#78486)" This reverts commit 4684507. Revert "[lldb][DWARFIndex] Use IDX_parent to implement GetFullyQualifiedType query (llvm#79932)" This reverts commit 91f4a84. Note(toyang): added back the DWARFDeclContext arrayref constructor
1 parent 5bcf07e commit 25d5589

File tree

10 files changed

+10
-425
lines changed

10 files changed

+10
-425
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "DWARFFormValue.h"
1919
#include "DWARFUnit.h"
2020

21+
class DWARFUnit;
22+
2123
using namespace lldb_private;
2224
using namespace lldb_private::dwarf;
2325
using namespace lldb_private::plugin::dwarf;
@@ -500,8 +502,7 @@ dw_addr_t DWARFFormValue::Address() const {
500502
&offset, index_size);
501503
}
502504

503-
std::pair<DWARFUnit *, uint64_t>
504-
DWARFFormValue::ReferencedUnitAndOffset() const {
505+
DWARFDIE DWARFFormValue::Reference() const {
505506
uint64_t value = m_value.value.uval;
506507
switch (m_form) {
507508
case DW_FORM_ref1:
@@ -515,9 +516,9 @@ DWARFFormValue::ReferencedUnitAndOffset() const {
515516
if (!m_unit->ContainsDIEOffset(value)) {
516517
m_unit->GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
517518
"DW_FORM_ref* DIE reference {0:x16} is outside of its CU", value);
518-
return {nullptr, 0};
519+
return {};
519520
}
520-
return {const_cast<DWARFUnit *>(m_unit), value};
521+
return const_cast<DWARFUnit *>(m_unit)->GetDIE(value);
521522

522523
case DW_FORM_ref_addr: {
523524
DWARFUnit *ref_cu =
@@ -526,29 +527,24 @@ DWARFFormValue::ReferencedUnitAndOffset() const {
526527
if (!ref_cu) {
527528
m_unit->GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
528529
"DW_FORM_ref_addr DIE reference {0:x16} has no matching CU", value);
529-
return {nullptr, 0};
530+
return {};
530531
}
531-
return {ref_cu, value};
532+
return ref_cu->GetDIE(value);
532533
}
533534

534535
case DW_FORM_ref_sig8: {
535536
DWARFTypeUnit *tu =
536537
m_unit->GetSymbolFileDWARF().DebugInfo().GetTypeUnitForHash(value);
537538
if (!tu)
538-
return {nullptr, 0};
539-
return {tu, tu->GetTypeOffset()};
539+
return {};
540+
return tu->GetDIE(tu->GetTypeOffset());
540541
}
541542

542543
default:
543-
return {nullptr, 0};
544+
return {};
544545
}
545546
}
546547

547-
DWARFDIE DWARFFormValue::Reference() const {
548-
auto [unit, offset] = ReferencedUnitAndOffset();
549-
return unit ? unit->GetDIE(offset) : DWARFDIE();
550-
}
551-
552548
uint64_t DWARFFormValue::Reference(dw_offset_t base_offset) const {
553549
uint64_t value = m_value.value.uval;
554550
switch (m_form) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ class DWARFFormValue {
6060
const DWARFUnit *u);
6161
std::optional<uint8_t> GetFixedSize() const;
6262
DWARFDIE Reference() const;
63-
64-
/// If this is a reference to another DIE, return the corresponding DWARFUnit
65-
/// and DIE offset such that Unit->GetDIE(offset) produces the desired DIE.
66-
/// Otherwise, a nullptr and unspecified offset are returned.
67-
std::pair<DWARFUnit *, uint64_t> ReferencedUnitAndOffset() const;
68-
6963
uint64_t Reference(dw_offset_t offset) const;
7064
bool Boolean() const { return m_value.value.uval != 0; }
7165
uint64_t Unsigned() const { return m_value.value.uval; }

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -670,30 +670,6 @@ DWARFUnit::GetDIE(dw_offset_t die_offset) {
670670
return DWARFDIE(); // Not found
671671
}
672672

673-
llvm::StringRef DWARFUnit::PeekDIEName(dw_offset_t die_offset) {
674-
DWARFDebugInfoEntry die;
675-
if (!die.Extract(GetData(), *this, &die_offset))
676-
return llvm::StringRef();
677-
678-
// Does die contain a DW_AT_Name?
679-
if (const char *name =
680-
die.GetAttributeValueAsString(this, DW_AT_name, nullptr))
681-
return name;
682-
683-
// Does its DW_AT_specification or DW_AT_abstract_origin contain an AT_Name?
684-
for (auto attr : {DW_AT_specification, DW_AT_abstract_origin}) {
685-
DWARFFormValue form_value;
686-
if (!die.GetAttributeValue(this, attr, form_value))
687-
continue;
688-
auto [unit, offset] = form_value.ReferencedUnitAndOffset();
689-
if (unit)
690-
if (auto name = unit->PeekDIEName(offset); !name.empty())
691-
return name;
692-
}
693-
694-
return llvm::StringRef();
695-
}
696-
697673
DWARFUnit &DWARFUnit::GetNonSkeletonUnit() {
698674
ExtractUnitDIEIfNeeded();
699675
if (m_dwo)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ class DWARFUnit : public UserID {
145145

146146
DWARFDIE GetDIE(dw_offset_t die_offset);
147147

148-
/// Returns the AT_Name of the DIE at `die_offset`, if it exists, without
149-
/// parsing the entire compile unit. An empty is string is returned upon
150-
/// error or if the attribute is not present.
151-
llvm::StringRef PeekDIEName(dw_offset_t die_offset);
152-
153148
DWARFUnit &GetNonSkeletonUnit();
154149

155150
static uint8_t GetAddressByteSize(const DWARFUnit *cu);

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

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "lldb/Core/Module.h"
1515
#include "lldb/Utility/RegularExpression.h"
1616
#include "lldb/Utility/Stream.h"
17-
#include "llvm/ADT/Sequence.h"
1817
#include <optional>
1918

2019
using namespace lldb_private;
@@ -329,79 +328,6 @@ getParentChain(Entry entry, uint32_t max_parents) {
329328
}
330329
} // namespace
331330

332-
void DebugNamesDWARFIndex::GetFullyQualifiedType(
333-
const DWARFDeclContext &context,
334-
llvm::function_ref<bool(DWARFDIE die)> callback) {
335-
if (context.GetSize() == 0)
336-
return;
337-
338-
llvm::StringRef leaf_name = context[0].name;
339-
llvm::SmallVector<llvm::StringRef> parent_names;
340-
for (auto idx : llvm::seq<int>(1, context.GetSize()))
341-
parent_names.emplace_back(context[idx].name);
342-
343-
// For each entry, grab its parent chain and check if we have a match.
344-
for (const DebugNames::Entry &entry :
345-
m_debug_names_up->equal_range(leaf_name)) {
346-
if (!isType(entry.tag()))
347-
continue;
348-
349-
// If we get a NULL foreign_tu back, the entry doesn't match the type unit
350-
// in the .dwp file, or we were not able to load the .dwo file or the DWO ID
351-
// didn't match.
352-
std::optional<DWARFTypeUnit *> foreign_tu = GetForeignTypeUnit(entry);
353-
if (foreign_tu && foreign_tu.value() == nullptr)
354-
continue;
355-
356-
// Grab at most one extra parent, subsequent parents are not necessary to
357-
// test equality.
358-
std::optional<llvm::SmallVector<Entry, 4>> parent_chain =
359-
getParentChain(entry, parent_names.size() + 1);
360-
361-
if (!parent_chain) {
362-
// Fallback: use the base class implementation.
363-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
364-
return GetFullyQualifiedTypeImpl(context, die, callback);
365-
}))
366-
return;
367-
continue;
368-
}
369-
370-
if (SameParentChain(parent_names, *parent_chain) &&
371-
!ProcessEntry(entry, callback))
372-
return;
373-
}
374-
m_fallback.GetFullyQualifiedType(context, callback);
375-
}
376-
377-
bool DebugNamesDWARFIndex::SameParentChain(
378-
llvm::ArrayRef<llvm::StringRef> parent_names,
379-
llvm::ArrayRef<DebugNames::Entry> parent_entries) const {
380-
381-
if (parent_entries.size() != parent_names.size())
382-
return false;
383-
384-
auto SameAsEntryATName = [this](llvm::StringRef name,
385-
const DebugNames::Entry &entry) {
386-
// Peek at the AT_name of `entry` and test equality to `name`.
387-
auto maybe_dieoffset = entry.getDIEUnitOffset();
388-
if (!maybe_dieoffset)
389-
return false;
390-
DWARFUnit *unit = GetNonSkeletonUnit(entry);
391-
if (!unit)
392-
return false;
393-
return name == unit->PeekDIEName(unit->GetOffset() + *maybe_dieoffset);
394-
};
395-
396-
// If the AT_name of any parent fails to match the expected name, we don't
397-
// have a match.
398-
for (auto [parent_name, parent_entry] :
399-
llvm::zip_equal(parent_names, parent_entries))
400-
if (!SameAsEntryATName(parent_name, parent_entry))
401-
return false;
402-
return true;
403-
}
404-
405331
void DebugNamesDWARFIndex::GetTypes(
406332
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
407333
for (const DebugNames::Entry &entry :

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ class DebugNamesDWARFIndex : public DWARFIndex {
4141
void GetCompleteObjCClass(
4242
ConstString class_name, bool must_be_implementation,
4343
llvm::function_ref<bool(DWARFDIE die)> callback) override;
44-
45-
/// Uses DWARF5's IDX_parent fields, when available, to speed up this query.
46-
void GetFullyQualifiedType(
47-
const DWARFDeclContext &context,
48-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
4944
void GetTypes(ConstString name,
5045
llvm::function_ref<bool(DWARFDIE die)> callback) override;
5146
void GetTypes(const DWARFDeclContext &context,
@@ -114,10 +109,6 @@ class DebugNamesDWARFIndex : public DWARFIndex {
114109
bool ProcessEntry(const DebugNames::Entry &entry,
115110
llvm::function_ref<bool(DWARFDIE die)> callback);
116111

117-
/// Returns true if `parent_entries` have identical names to `parent_names`.
118-
bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,
119-
llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
120-
121112
static void MaybeLogLookupError(llvm::Error error,
122113
const DebugNames::NameIndex &ni,
123114
llvm::StringRef name);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
367367

368368
Type *ResolveTypeUID(const DIERef &die_ref);
369369

370-
/// Returns the DWARFIndex for this symbol, if it exists.
371-
DWARFIndex *getIndex() { return m_index.get(); }
372-
373370
protected:
374371
SymbolFileDWARF(const SymbolFileDWARF &) = delete;
375372
const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete;

lldb/unittests/SymbolFile/DWARF/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_lldb_unittest(SymbolFileDWARFTests
22
DWARFASTParserClangTests.cpp
3-
DWARFDebugNamesIndexTest.cpp
43
DWARFDIETest.cpp
54
DWARFIndexCachingTest.cpp
65
DWARFUnitTest.cpp

lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -111,87 +111,6 @@ TEST(DWARFDIETest, ChildIteration) {
111111
EXPECT_TRUE(no_children_die.children().empty());
112112
}
113113

114-
TEST(DWARFDIETest, PeekName) {
115-
const char *yamldata = R"(
116-
--- !ELF
117-
FileHeader:
118-
Class: ELFCLASS64
119-
Data: ELFDATA2LSB
120-
Type: ET_EXEC
121-
Machine: EM_386
122-
DWARF:
123-
debug_str:
124-
- 'NameType1'
125-
- 'NameType2'
126-
debug_abbrev:
127-
- Table:
128-
- Code: 0x00000001
129-
Tag: DW_TAG_compile_unit
130-
Children: DW_CHILDREN_yes
131-
Attributes:
132-
- Attribute: DW_AT_language
133-
Form: DW_FORM_data2
134-
- Code: 0x00000002
135-
Tag: DW_TAG_base_type
136-
Children: DW_CHILDREN_no
137-
Attributes:
138-
- Attribute: DW_AT_name
139-
Form: DW_FORM_strp
140-
- Code: 0x00000003
141-
Tag: DW_TAG_base_type
142-
Children: DW_CHILDREN_no
143-
Attributes:
144-
- Attribute: DW_AT_abstract_origin
145-
Form: DW_FORM_ref1
146-
- Code: 0x00000004
147-
Tag: DW_TAG_base_type
148-
Children: DW_CHILDREN_no
149-
Attributes:
150-
- Attribute: DW_AT_specification
151-
Form: DW_FORM_ref1
152-
debug_info:
153-
- Version: 4
154-
AddrSize: 8
155-
Entries:
156-
- AbbrCode: 0x00000001
157-
Values:
158-
- Value: 0x000000000000000C
159-
- AbbrCode: 0x00000002
160-
Values:
161-
- Value: 0x0000000000000000 # Name = NameType1
162-
- AbbrCode: 0x00000002
163-
Values:
164-
- Value: 0x000000000000000a # Name = NameType2
165-
- AbbrCode: 0x00000003
166-
Values:
167-
- Value: 0x000000000000000e # Ref abstract origin to NameType1 DIE.
168-
- AbbrCode: 0x00000004
169-
Values:
170-
- Value: 0x0000000000000013 # Ref specification to NameType2 DIE.
171-
- AbbrCode: 0x00000000
172-
)";
173-
174-
YAMLModuleTester t(yamldata);
175-
auto *symbol_file =
176-
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());
177-
DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0);
178-
179-
dw_offset_t first_die_offset = 11;
180-
EXPECT_EQ(unit->PeekDIEName(first_die_offset), "");
181-
182-
dw_offset_t second_die_offset = 14;
183-
EXPECT_EQ(unit->PeekDIEName(second_die_offset), "NameType1");
184-
185-
dw_offset_t third_die_offset = 19;
186-
EXPECT_EQ(unit->PeekDIEName(third_die_offset), "NameType2");
187-
188-
dw_offset_t fourth_die_offset = 24;
189-
EXPECT_EQ(unit->PeekDIEName(fourth_die_offset), "NameType1");
190-
191-
dw_offset_t fifth_die_offset = 26;
192-
EXPECT_EQ(unit->PeekDIEName(fifth_die_offset), "NameType2");
193-
}
194-
195114
TEST(DWARFDIETest, GetContext) {
196115
const char *yamldata = R"(
197116
--- !ELF

0 commit comments

Comments
 (0)