Skip to content

Commit 7fdbc30

Browse files
committed
Revert "[lldb][DebugNames] Only skip processing of DW_AT_declarations for class/union types"
and two follow-up commits. The reason is the crash we've discovered when processing -gsimple-template-names binaries. I'm committing a minimal reproducer as a separate patch. This reverts the following commits: - 51dd4ea (#92328) - 3d9d485 (#93839) - afe6ab7 (#94400)
1 parent 67aaa9f commit 7fdbc30

12 files changed

+393
-481
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class DWARFASTParser {
6060

6161
virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
6262

63-
virtual lldb_private::Type *FindDefinitionTypeForDIE(const DWARFDIE &die) = 0;
64-
6563
static std::optional<SymbolFile::ArrayInfo>
6664
ParseChildArrayInfo(const DWARFDIE &parent_die,
6765
const ExecutionContext *exe_ctx = nullptr);

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

Lines changed: 179 additions & 222 deletions
Large diffs are not rendered by default.

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

Lines changed: 109 additions & 88 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ bool DebugNamesDWARFIndex::ProcessEntry(
8585
DWARFDIE die = GetDIE(entry);
8686
if (!die)
8787
return true;
88-
// Clang erroneously emits index entries for declaration DIEs in case when the
89-
// definition is in a type unit (llvm.org/pr77696). Weed those out.
90-
if (die.IsStructUnionOrClass() &&
91-
die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
92-
return true;
9388
return callback(die);
9489
}
9590

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

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,6 @@ static ConstString GetDWARFMachOSegmentName() {
481481
return g_dwarf_section_name;
482482
}
483483

484-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
485-
SymbolFileDWARF::GetForwardDeclCompilerTypeToDIE() {
486-
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
487-
return debug_map_symfile->GetForwardDeclCompilerTypeToDIE();
488-
return m_forward_decl_compiler_type_to_die;
489-
}
490-
491484
UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() {
492485
SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
493486
if (debug_map_symfile)
@@ -1639,33 +1632,27 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
16391632
return true;
16401633
}
16411634

1642-
// Once we start resolving this type, remove it from the forward
1643-
// declaration map in case anyone's child members or other types require this
1644-
// type to get resolved.
1645-
DWARFDIE dwarf_die = GetDIE(die_it->second);
1646-
GetForwardDeclCompilerTypeToDIE().erase(die_it);
1647-
Type *type = nullptr;
1648-
if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
1649-
type = dwarf_ast->FindDefinitionTypeForDIE(dwarf_die);
1650-
if (!type)
1651-
return false;
1652-
1653-
die_it = GetForwardDeclCompilerTypeToDIE().find(
1654-
compiler_type_no_qualifiers.GetOpaqueQualType());
1655-
if (die_it != GetForwardDeclCompilerTypeToDIE().end()) {
1656-
dwarf_die = GetDIE(die_it->getSecond());
1635+
DWARFDIE dwarf_die = GetDIE(die_it->getSecond());
1636+
if (dwarf_die) {
1637+
// Once we start resolving this type, remove it from the forward
1638+
// declaration map in case anyone child members or other types require this
1639+
// type to get resolved. The type will get resolved when all of the calls
1640+
// to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done.
16571641
GetForwardDeclCompilerTypeToDIE().erase(die_it);
1658-
}
16591642

1660-
if (Log *log = GetLog(DWARFLog::DebugInfo | DWARFLog::TypeCompletion))
1661-
GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1662-
log, "{0:x8}: {1} ({2}) '{3}' resolving forward declaration...",
1663-
dwarf_die.GetID(), DW_TAG_value_to_name(dwarf_die.Tag()),
1664-
dwarf_die.Tag(), type->GetName().AsCString());
1665-
assert(compiler_type);
1666-
if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
1667-
return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
1668-
return true;
1643+
Type *type = GetDIEToType().lookup(dwarf_die.GetDIE());
1644+
1645+
Log *log = GetLog(DWARFLog::DebugInfo | DWARFLog::TypeCompletion);
1646+
if (log)
1647+
GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1648+
log, "{0:x8}: {1} ({2}) '{3}' resolving forward declaration...",
1649+
dwarf_die.GetID(), DW_TAG_value_to_name(dwarf_die.Tag()),
1650+
dwarf_die.Tag(), type->GetName().AsCString());
1651+
assert(compiler_type);
1652+
if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
1653+
return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
1654+
}
1655+
return false;
16691656
}
16701657

16711658
Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die,

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,12 @@ class SymbolFileDWARF : public SymbolFileCommon {
335335

336336
virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
337337

338-
virtual llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
339-
GetForwardDeclCompilerTypeToDIE();
338+
typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
339+
CompilerTypeToDIE;
340+
341+
virtual CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() {
342+
return m_forward_decl_compiler_type_to_die;
343+
}
340344

341345
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
342346
DIEToVariableSP;
@@ -529,14 +533,9 @@ class SymbolFileDWARF : public SymbolFileCommon {
529533
NameToOffsetMap m_function_scope_qualified_name_map;
530534
std::unique_ptr<DWARFDebugRanges> m_ranges;
531535
UniqueDWARFASTTypeMap m_unique_ast_type_map;
532-
// A map from DIE to lldb_private::Type. For record type, the key might be
533-
// either declaration DIE or definition DIE.
534536
DIEToTypePtr m_die_to_type;
535537
DIEToVariableSP m_die_to_variable_sp;
536-
// A map from CompilerType to the struct/class/union/enum DIE (might be a
537-
// declaration or a definition) that is used to construct it.
538-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
539-
m_forward_decl_compiler_type_to_die;
538+
CompilerTypeToDIE m_forward_decl_compiler_type_to_die;
540539
llvm::DenseMap<dw_offset_t, std::unique_ptr<SupportFileList>>
541540
m_type_unit_support_files;
542541
std::vector<uint32_t> m_lldb_cu_to_dwarf_unit;

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,6 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
284284
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
285285
const DWARFDIE &die, ConstString type_name, bool must_be_implementation);
286286

287-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
288-
GetForwardDeclCompilerTypeToDIE() {
289-
return m_forward_decl_compiler_type_to_die;
290-
}
291-
292287
UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
293288
return m_unique_ast_type_map;
294289
}
@@ -326,10 +321,6 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
326321
std::vector<uint32_t> m_func_indexes; // Sorted by address
327322
std::vector<uint32_t> m_glob_indexes;
328323
std::map<std::pair<ConstString, llvm::sys::TimePoint<>>, OSOInfoSP> m_oso_map;
329-
// A map from CompilerType to the struct/class/union/enum DIE (might be a
330-
// declaration or a definition) that is used to construct it.
331-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
332-
m_forward_decl_compiler_type_to_die;
333324
UniqueDWARFASTTypeMap m_unique_ast_type_map;
334325
LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
335326
DebugMap m_debug_map;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() {
110110
return GetBaseSymbolFile().GetDIEToVariable();
111111
}
112112

113-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
113+
SymbolFileDWARF::CompilerTypeToDIE &
114114
SymbolFileDWARFDwo::GetForwardDeclCompilerTypeToDIE() {
115115
return GetBaseSymbolFile().GetForwardDeclCompilerTypeToDIE();
116116
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {
7272

7373
DIEToVariableSP &GetDIEToVariable() override;
7474

75-
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
76-
GetForwardDeclCompilerTypeToDIE() override;
75+
CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() override;
7776

7877
UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() override;
7978

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

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,66 @@
1313
using namespace lldb_private::dwarf;
1414
using namespace lldb_private::plugin::dwarf;
1515

16-
static bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
17-
return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
18-
Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
19-
}
20-
21-
UniqueDWARFASTType *UniqueDWARFASTTypeList::Find(
22-
const DWARFDIE &die, const lldb_private::Declaration &decl,
23-
const int32_t byte_size, bool is_forward_declaration) {
24-
for (UniqueDWARFASTType &udt : m_collection) {
16+
bool UniqueDWARFASTTypeList::Find(const DWARFDIE &die,
17+
const lldb_private::Declaration &decl,
18+
const int32_t byte_size,
19+
UniqueDWARFASTType &entry) const {
20+
for (const UniqueDWARFASTType &udt : m_collection) {
2521
// Make sure the tags match
26-
if (udt.m_die.Tag() == die.Tag() || (IsStructOrClassTag(udt.m_die.Tag()) &&
27-
IsStructOrClassTag(die.Tag()))) {
28-
// If they are not both definition DIEs or both declaration DIEs, then
29-
// don't check for byte size and declaration location, because declaration
30-
// DIEs usually don't have those info.
31-
bool matching_size_declaration =
32-
udt.m_is_forward_declaration != is_forward_declaration
33-
? true
34-
: (udt.m_byte_size < 0 || byte_size < 0 ||
35-
udt.m_byte_size == byte_size) &&
36-
udt.m_declaration == decl;
37-
if (!matching_size_declaration)
38-
continue;
39-
// The type has the same name, and was defined on the same file and
40-
// line. Now verify all of the parent DIEs match.
41-
DWARFDIE parent_arg_die = die.GetParent();
42-
DWARFDIE parent_pos_die = udt.m_die.GetParent();
43-
bool match = true;
44-
bool done = false;
45-
while (!done && match && parent_arg_die && parent_pos_die) {
46-
const dw_tag_t parent_arg_tag = parent_arg_die.Tag();
47-
const dw_tag_t parent_pos_tag = parent_pos_die.Tag();
48-
if (parent_arg_tag == parent_pos_tag ||
49-
(IsStructOrClassTag(parent_arg_tag) &&
50-
IsStructOrClassTag(parent_pos_tag))) {
51-
switch (parent_arg_tag) {
52-
case DW_TAG_class_type:
53-
case DW_TAG_structure_type:
54-
case DW_TAG_union_type:
55-
case DW_TAG_namespace: {
56-
const char *parent_arg_die_name = parent_arg_die.GetName();
57-
if (parent_arg_die_name == nullptr) {
58-
// Anonymous (i.e. no-name) struct
59-
match = false;
60-
} else {
61-
const char *parent_pos_die_name = parent_pos_die.GetName();
62-
if (parent_pos_die_name == nullptr ||
63-
((parent_arg_die_name != parent_pos_die_name) &&
64-
strcmp(parent_arg_die_name, parent_pos_die_name)))
65-
match = false;
22+
if (udt.m_die.Tag() == die.Tag()) {
23+
// Validate byte sizes of both types only if both are valid.
24+
if (udt.m_byte_size < 0 || byte_size < 0 ||
25+
udt.m_byte_size == byte_size) {
26+
// Make sure the file and line match
27+
if (udt.m_declaration == decl) {
28+
// The type has the same name, and was defined on the same file and
29+
// line. Now verify all of the parent DIEs match.
30+
DWARFDIE parent_arg_die = die.GetParent();
31+
DWARFDIE parent_pos_die = udt.m_die.GetParent();
32+
bool match = true;
33+
bool done = false;
34+
while (!done && match && parent_arg_die && parent_pos_die) {
35+
const dw_tag_t parent_arg_tag = parent_arg_die.Tag();
36+
const dw_tag_t parent_pos_tag = parent_pos_die.Tag();
37+
if (parent_arg_tag == parent_pos_tag) {
38+
switch (parent_arg_tag) {
39+
case DW_TAG_class_type:
40+
case DW_TAG_structure_type:
41+
case DW_TAG_union_type:
42+
case DW_TAG_namespace: {
43+
const char *parent_arg_die_name = parent_arg_die.GetName();
44+
if (parent_arg_die_name ==
45+
nullptr) // Anonymous (i.e. no-name) struct
46+
{
47+
match = false;
48+
} else {
49+
const char *parent_pos_die_name = parent_pos_die.GetName();
50+
if (parent_pos_die_name == nullptr ||
51+
((parent_arg_die_name != parent_pos_die_name) &&
52+
strcmp(parent_arg_die_name, parent_pos_die_name)))
53+
match = false;
54+
}
55+
} break;
56+
57+
case DW_TAG_compile_unit:
58+
case DW_TAG_partial_unit:
59+
done = true;
60+
break;
61+
default:
62+
break;
63+
}
6664
}
67-
} break;
65+
parent_arg_die = parent_arg_die.GetParent();
66+
parent_pos_die = parent_pos_die.GetParent();
67+
}
6868

69-
case DW_TAG_compile_unit:
70-
case DW_TAG_partial_unit:
71-
done = true;
72-
break;
73-
default:
74-
break;
69+
if (match) {
70+
entry = udt;
71+
return true;
7572
}
7673
}
77-
parent_arg_die = parent_arg_die.GetParent();
78-
parent_pos_die = parent_pos_die.GetParent();
79-
}
80-
81-
if (match) {
82-
return &udt;
8374
}
8475
}
8576
}
86-
return nullptr;
77+
return false;
8778
}

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,31 @@ class UniqueDWARFASTType {
2323
// Constructors and Destructors
2424
UniqueDWARFASTType() : m_type_sp(), m_die(), m_declaration() {}
2525

26+
UniqueDWARFASTType(lldb::TypeSP &type_sp, const DWARFDIE &die,
27+
const Declaration &decl, int32_t byte_size)
28+
: m_type_sp(type_sp), m_die(die), m_declaration(decl),
29+
m_byte_size(byte_size) {}
30+
2631
UniqueDWARFASTType(const UniqueDWARFASTType &rhs)
2732
: m_type_sp(rhs.m_type_sp), m_die(rhs.m_die),
28-
m_declaration(rhs.m_declaration), m_byte_size(rhs.m_byte_size),
29-
m_is_forward_declaration(rhs.m_is_forward_declaration) {}
33+
m_declaration(rhs.m_declaration), m_byte_size(rhs.m_byte_size) {}
3034

3135
~UniqueDWARFASTType() = default;
3236

37+
UniqueDWARFASTType &operator=(const UniqueDWARFASTType &rhs) {
38+
if (this != &rhs) {
39+
m_type_sp = rhs.m_type_sp;
40+
m_die = rhs.m_die;
41+
m_declaration = rhs.m_declaration;
42+
m_byte_size = rhs.m_byte_size;
43+
}
44+
return *this;
45+
}
46+
3347
lldb::TypeSP m_type_sp;
3448
DWARFDIE m_die;
3549
Declaration m_declaration;
3650
int32_t m_byte_size = -1;
37-
// True if the m_die is a forward declaration DIE.
38-
bool m_is_forward_declaration = true;
3951
};
4052

4153
class UniqueDWARFASTTypeList {
@@ -50,9 +62,8 @@ class UniqueDWARFASTTypeList {
5062
m_collection.push_back(entry);
5163
}
5264

53-
UniqueDWARFASTType *Find(const DWARFDIE &die, const Declaration &decl,
54-
const int32_t byte_size,
55-
bool is_forward_declaration);
65+
bool Find(const DWARFDIE &die, const Declaration &decl,
66+
const int32_t byte_size, UniqueDWARFASTType &entry) const;
5667

5768
protected:
5869
typedef std::vector<UniqueDWARFASTType> collection;
@@ -69,15 +80,14 @@ class UniqueDWARFASTTypeMap {
6980
m_collection[name.GetCString()].Append(entry);
7081
}
7182

72-
UniqueDWARFASTType *Find(ConstString name, const DWARFDIE &die,
73-
const Declaration &decl, const int32_t byte_size,
74-
bool is_forward_declaration) {
83+
bool Find(ConstString name, const DWARFDIE &die, const Declaration &decl,
84+
const int32_t byte_size, UniqueDWARFASTType &entry) const {
7585
const char *unique_name_cstr = name.GetCString();
76-
collection::iterator pos = m_collection.find(unique_name_cstr);
86+
collection::const_iterator pos = m_collection.find(unique_name_cstr);
7787
if (pos != m_collection.end()) {
78-
return pos->second.Find(die, decl, byte_size, is_forward_declaration);
88+
return pos->second.Find(die, decl, byte_size, entry);
7989
}
80-
return nullptr;
90+
return false;
8191
}
8292

8393
protected:

lldb/test/Shell/SymbolFile/DWARF/delayed-definition-die-searching.test

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)