Skip to content

Commit 207b685

Browse files
Merge pull request swiftlang#9788 from swiftlang/bugfix/lldb-objc-fixes-to-6.1
[lldb][cherry-pick] Various fixes to definition DIE parsing
2 parents dd0f3b2 + 94a3ee5 commit 207b685

24 files changed

+277
-188
lines changed

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
565565
while (!m_to_complete.empty()) {
566566
TypeToComplete to_complete = m_to_complete.back();
567567
m_to_complete.pop_back();
568-
CompleteRecordType(to_complete.die, to_complete.type.get(),
569-
to_complete.clang_type);
568+
CompleteRecordType(to_complete.die, to_complete.clang_type);
570569
}
571570
}
572571

@@ -1810,20 +1809,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
18101809
ConstString unique_typename(attrs.name);
18111810
Declaration unique_decl(attrs.decl);
18121811
uint64_t byte_size = attrs.byte_size.value_or(0);
1813-
if (attrs.byte_size && *attrs.byte_size == 0 && attrs.name &&
1814-
!die.HasChildren() && cu_language == eLanguageTypeObjC) {
1815-
// Work around an issue with clang at the moment where forward
1816-
// declarations for objective C classes are emitted as:
1817-
// DW_TAG_structure_type [2]
1818-
// DW_AT_name( "ForwardObjcClass" )
1819-
// DW_AT_byte_size( 0x00 )
1820-
// DW_AT_decl_file( "..." )
1821-
// DW_AT_decl_line( 1 )
1822-
//
1823-
// Note that there is no DW_AT_declaration and there are no children,
1824-
// and the byte size is zero.
1825-
attrs.is_forward_declaration = true;
1826-
}
18271812

18281813
if (attrs.name) {
18291814
GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
@@ -1873,8 +1858,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
18731858

18741859
if ((attrs.class_language == eLanguageTypeObjC ||
18751860
attrs.class_language == eLanguageTypeObjC_plus_plus) &&
1876-
!attrs.is_complete_objc_class &&
1877-
die.Supports_DW_AT_APPLE_objc_complete_type()) {
1861+
!attrs.is_complete_objc_class) {
18781862
// We have a valid eSymbolTypeObjCClass class symbol whose name
18791863
// matches the current objective C class that we are trying to find
18801864
// and this DIE isn't the complete definition (we checked
@@ -2241,7 +2225,6 @@ bool DWARFASTParserClang::ParseTemplateParameterInfos(
22412225
}
22422226

22432227
bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
2244-
lldb_private::Type *type,
22452228
CompilerType &clang_type) {
22462229
if (TypeSystemClang::UseRedeclCompletion())
22472230
if (!m_currently_parsed_record_dies.insert(die.GetDIE()).second)
@@ -2424,7 +2407,7 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die,
24242407
case DW_TAG_structure_type:
24252408
case DW_TAG_union_type:
24262409
case DW_TAG_class_type:
2427-
CompleteRecordType(die, type, clang_type);
2410+
CompleteRecordType(die, clang_type);
24282411
break;
24292412
case DW_TAG_enumeration_type:
24302413
CompleteEnumType(die, type, clang_type);
@@ -3909,8 +3892,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
39093892
static_cast<DWARFASTParserClang *>(
39103893
SymbolFileDWARF::GetDWARFParser(*dst_class_die.GetCU()));
39113894
auto link = [&](DWARFDIE src, DWARFDIE dst) {
3912-
SymbolFileDWARF::DIEToTypePtr &die_to_type =
3913-
dst_class_die.GetDWARF()->GetDIEToType();
3895+
auto &die_to_type = dst_class_die.GetDWARF()->GetDIEToType();
39143896
clang::DeclContext *dst_decl_ctx =
39153897
dst_dwarf_ast_parser->m_die_to_decl_ctx[dst.GetDIE()];
39163898
if (dst_decl_ctx)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
382382
const lldb_private::CompilerType &class_clang_type);
383383

384384
bool CompleteRecordType(const lldb_private::plugin::dwarf::DWARFDIE &die,
385-
lldb_private::Type *type,
386385
lldb_private::CompilerType &clang_type);
387386
bool CompleteEnumType(const lldb_private::plugin::dwarf::DWARFDIE &die,
388387
lldb_private::Type *type,

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ bool DWARFBaseDIE::HasChildren() const {
107107
return m_die && m_die->HasChildren();
108108
}
109109

110-
bool DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type() const {
111-
return IsValid() && GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu);
112-
}
113-
114110
DWARFAttributes DWARFBaseDIE::GetAttributes(Recurse recurse) const {
115111
if (IsValid())
116112
return m_die->GetAttributes(m_cu, recurse);

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,6 @@ bool DWARFUnit::LinkToSkeletonUnit(DWARFUnit &skeleton_unit) {
734734
return false; // Already linked to a different unit.
735735
}
736736

737-
bool DWARFUnit::Supports_DW_AT_APPLE_objc_complete_type() {
738-
return GetProducer() != eProducerLLVMGCC;
739-
}
740-
741-
bool DWARFUnit::DW_AT_decl_file_attributes_are_invalid() {
742-
// llvm-gcc makes completely invalid decl file attributes and won't ever be
743-
// fixed, so we need to know to ignore these.
744-
return GetProducer() == eProducerLLVMGCC;
745-
}
746-
747737
bool DWARFUnit::Supports_unnamed_objc_bitfields() {
748738
if (GetProducer() == eProducerClang)
749739
return GetProducerVersion() >= llvm::VersionTuple(425, 0, 13);
@@ -766,10 +756,6 @@ void DWARFUnit::ParseProducerInfo() {
766756
llvm::StringRef(R"(swiftlang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
767757
static const RegularExpression g_clang_version_regex(
768758
llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
769-
static const RegularExpression g_llvm_gcc_regex(
770-
llvm::StringRef(R"(4\.[012]\.[01] )"
771-
R"(\(Based on Apple Inc\. build [0-9]+\) )"
772-
R"(\(LLVM build [\.0-9]+\)$)"));
773759

774760
llvm::SmallVector<llvm::StringRef, 3> matches;
775761
if (g_swiftlang_version_regex.Execute(producer, &matches)) {
@@ -781,8 +767,6 @@ void DWARFUnit::ParseProducerInfo() {
781767
m_producer = eProducerClang;
782768
} else if (producer.contains("GNU")) {
783769
m_producer = eProducerGCC;
784-
} else if (g_llvm_gcc_regex.Execute(producer)) {
785-
m_producer = eProducerLLVMGCC;
786770
}
787771
}
788772

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ enum DWARFProducer {
3333
eProducerInvalid = 0,
3434
eProducerClang,
3535
eProducerGCC,
36-
eProducerLLVMGCC,
3736
eProducerSwift,
3837
eProducerOther
3938
};
@@ -172,10 +171,6 @@ class DWARFUnit : public UserID {
172171

173172
bool LinkToSkeletonUnit(DWARFUnit &skeleton_unit);
174173

175-
bool Supports_DW_AT_APPLE_objc_complete_type();
176-
177-
bool DW_AT_decl_file_attributes_are_invalid();
178-
179174
bool Supports_unnamed_objc_bitfields();
180175

181176
SymbolFileDWARF &GetSymbolFileDWARF() const { return m_dwarf; }

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
271271
// Report invalid
272272
continue;
273273
}
274-
DWARFUnit *cu = die.GetCU();
275-
if (!cu->Supports_DW_AT_APPLE_objc_complete_type()) {
276-
incomplete_types.push_back(die);
277-
continue;
278-
}
279274

280275
if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) {
281276
// If we find the complete version we're done.

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

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ SymbolFileDWARF::SymbolFileDWARF(ObjectFileSP objfile_sp,
472472
: SymbolFileCommon(std::move(objfile_sp)), m_debug_map_module_wp(),
473473
m_debug_map_symfile(nullptr),
474474
m_context(m_objfile_sp->GetModule()->GetSectionList(), dwo_section_list),
475-
m_fetched_external_modules(false),
476-
m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {}
475+
m_fetched_external_modules(false) {}
477476

478477
SymbolFileDWARF::~SymbolFileDWARF() = default;
479478

@@ -482,6 +481,13 @@ static ConstString GetDWARFMachOSegmentName() {
482481
return g_dwarf_section_name;
483482
}
484483

484+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &
485+
SymbolFileDWARF::GetDIEToType() {
486+
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
487+
return debug_map_symfile->GetDIEToType();
488+
return m_die_to_type;
489+
}
490+
485491
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
486492
SymbolFileDWARF::GetForwardDeclCompilerTypeToDIE() {
487493
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
@@ -1675,6 +1681,8 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
16751681
if (!dwarf_ast)
16761682
return false;
16771683
Type *type = GetDIEToType().lookup(decl_die.GetDIE());
1684+
assert(type);
1685+
16781686
if (decl_die != def_die) {
16791687
GetDIEToType()[def_die.GetDIE()] = type;
16801688
DWARFASTParserClang *ast_parser =
@@ -3072,37 +3080,6 @@ Symbol *SymbolFileDWARF::GetObjCClassSymbol(ConstString objc_class_name) {
30723080
return objc_class_symbol;
30733081
}
30743082

3075-
// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If
3076-
// they don't then we can end up looking through all class types for a complete
3077-
// type and never find the full definition. We need to know if this attribute
3078-
// is supported, so we determine this here and cache th result. We also need to
3079-
// worry about the debug map
3080-
// DWARF file
3081-
// if we are doing darwin DWARF in .o file debugging.
3082-
bool SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu) {
3083-
if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) {
3084-
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3085-
if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3086-
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3087-
else {
3088-
DWARFDebugInfo &debug_info = DebugInfo();
3089-
const uint32_t num_compile_units = GetNumCompileUnits();
3090-
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
3091-
DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx);
3092-
if (dwarf_cu != cu &&
3093-
dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) {
3094-
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3095-
break;
3096-
}
3097-
}
3098-
}
3099-
if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo &&
3100-
GetDebugMapSymfile())
3101-
return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type(this);
3102-
}
3103-
return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3104-
}
3105-
31063083
// This function can be used when a DIE is found that is a forward declaration
31073084
// DIE and we want to try and find a type that has the complete definition.
31083085
TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
@@ -3120,8 +3097,7 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
31203097
if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
31213098
return true;
31223099

3123-
if (must_be_implementation &&
3124-
type_die.Supports_DW_AT_APPLE_objc_complete_type()) {
3100+
if (must_be_implementation) {
31253101
const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
31263102
DW_AT_APPLE_objc_complete_type, 0);
31273103
if (!try_resolving_type)

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
246246
virtual void GetObjCMethods(ConstString class_name,
247247
llvm::function_ref<bool(DWARFDIE die)> callback);
248248

249-
bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
250-
251249
DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
252250

253251
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
@@ -358,9 +356,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
358356
m_file_index = file_index;
359357
}
360358

361-
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> DIEToTypePtr;
362-
363-
virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
359+
virtual llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType();
364360

365361
virtual llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
366362
GetForwardDeclCompilerTypeToDIE();
@@ -556,7 +552,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
556552
ExternalTypeModuleMap m_external_type_modules;
557553
std::unique_ptr<DWARFIndex> m_index;
558554
bool m_fetched_external_modules : 1;
559-
LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
560555

561556
typedef std::set<DIERef> DIERefSet;
562557
typedef llvm::StringMap<DIERefSet> NameToOffsetMap;
@@ -565,7 +560,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
565560
UniqueDWARFASTTypeMap m_unique_ast_type_map;
566561
// A map from DIE to lldb_private::Type. For record type, the key might be
567562
// either declaration DIE or definition DIE.
568-
DIEToTypePtr m_die_to_type;
563+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> m_die_to_type;
569564
DIEToVariableSP m_die_to_variable_sp;
570565
// A map from CompilerType to the struct/class/union/enum DIE (might be a
571566
// declaration or a definition) that is used to construct it.

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) {
249249
}
250250

251251
SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap(ObjectFileSP objfile_sp)
252-
: SymbolFileCommon(std::move(objfile_sp)), m_flags(), m_compile_unit_infos(),
253-
m_func_indexes(), m_glob_indexes(),
254-
m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {}
252+
: SymbolFileCommon(std::move(objfile_sp)), m_flags(),
253+
m_compile_unit_infos(), m_func_indexes(), m_glob_indexes() {}
255254

256255
SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap() = default;
257256

@@ -1178,22 +1177,6 @@ DWARFDIE SymbolFileDWARFDebugMap::FindDefinitionDIE(const DWARFDIE &die) {
11781177
return result;
11791178
}
11801179

1181-
bool SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type(
1182-
SymbolFileDWARF *skip_dwarf_oso) {
1183-
if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) {
1184-
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
1185-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1186-
if (skip_dwarf_oso != oso_dwarf &&
1187-
oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(nullptr)) {
1188-
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
1189-
return IterationAction::Stop;
1190-
}
1191-
return IterationAction::Continue;
1192-
});
1193-
}
1194-
return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
1195-
}
1196-
11971180
TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
11981181
const DWARFDIE &die, ConstString type_name,
11991182
bool must_be_implementation) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
293293

294294
DWARFDIE FindDefinitionDIE(const DWARFDIE &die);
295295

296-
bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
297-
298296
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
299297
const DWARFDIE &die, ConstString type_name, bool must_be_implementation);
300298

@@ -307,6 +305,10 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
307305
return m_unique_ast_type_map;
308306
}
309307

308+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType() {
309+
return m_die_to_type;
310+
}
311+
310312
// OSOEntry
311313
class OSOEntry {
312314
public:
@@ -345,7 +347,8 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
345347
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
346348
m_forward_decl_compiler_type_to_die;
347349
UniqueDWARFASTTypeMap m_unique_ast_type_map;
348-
LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
350+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> m_die_to_type;
351+
349352
DebugMap m_debug_map;
350353

351354
// When an object file from the debug map gets parsed in

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ bool SymbolFileDWARFDwo::ParseVendorDWARFOpcode(
102102
return GetBaseSymbolFile().ParseVendorDWARFOpcode(op, opcodes, offset, stack);
103103
}
104104

105-
SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() {
105+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &
106+
SymbolFileDWARFDwo::GetDIEToType() {
106107
return GetBaseSymbolFile().GetDIEToType();
107108
}
108109

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {
7070
SymbolFileDWARF *GetDIERefSymbolFile(const DIERef &die_ref) override;
7171

7272
protected:
73-
DIEToTypePtr &GetDIEToType() override;
73+
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType() override;
7474

7575
DIEToVariableSP &GetDIEToVariable() override;
7676

0 commit comments

Comments
 (0)