Skip to content

Commit 31ce34b

Browse files
[lldb] Remove SymbolFileDWARF assumption in DWARFASTParserSwiftDescriptorFinder
A SymbolFile representing DWARF can be either a SymbolFileDWARF or a SymbolFileDWARFDebugMap. Prior to this commit DWARFASTParserSwiftDescriptorFinder assumed it would get a SymbolFileDWARF from the TypeSystem. By changing the query to obtain the SymbolFile from the `Type` itself (as opposed to `TypeSystem`), we can guarantee that the resulting SymbolFile will be a SymbolFileDWARF representing a specific object file. This was never discovered because our DWARF variants in embedded swift were still using dsyms.
1 parent 52bae8e commit 31ce34b

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

lldb/packages/Python/lldbsuite/test/make/Swift.rules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ SWIFTFLAGS ?= $(SWIFT_DEBUG_INFO_FLAG) -Onone -Xfrontend -serialize-debugging-op
4040
ifeq "$(MAKE_PDB)" "YES"
4141
SWIFT_LINK_FLAGS = $(SWIFTFLAGS) -Xlinker /debug
4242
else
43-
# On Darwin, `-g` automatically runs `dsymutil`. Removed so it can be enabled explicitly
44-
# as neeeded.
45-
SWIFT_LINK_FLAGS = $(patsubst -g,,$(SWIFTFLAGS))
43+
# On Darwin, debug-info flags (`-g`, `-gdwarf-types`) automatically run
44+
# `dsymutil` at link time. Removed so it can be enabled explicitly as needed.
45+
SWIFT_LINK_FLAGS = $(patsubst -gdwarf-types,,$(patsubst -g,,$(SWIFTFLAGS)))
4646
endif
4747

4848
SWIFTFLAGS += $(SWIFTFLAGS_EXTRAS)

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "DWARFASTParserSwift.h"
2020

2121
#include "DWARFDIE.h"
22+
#include "SymbolFileDWARFDebugMap.h"
2223

2324
#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
2425
#include "swift/Demangling/ManglingFlavor.h"
@@ -73,8 +74,11 @@ DWARFASTParserSwift::ResolveTypeAlias(lldb_private::CompilerType alias) {
7374
if (!ts_sp)
7475
return {};
7576
auto &ts = *ts_sp;
76-
auto *dwarf = llvm::dyn_cast_or_null<SymbolFileDWARF>(ts.GetSymbolFile());
77-
if (!dwarf)
77+
78+
// The Type system must have a SymbolFileDWARF backing it to answer the
79+
// queries below.
80+
if (!llvm::isa_and_nonnull<SymbolFileDWARF, SymbolFileDWARFDebugMap>(
81+
ts.GetSymbolFile()))
7882
return {};
7983

8084
// Type aliases are (for LLVM implementation reasons) using the
@@ -88,6 +92,8 @@ DWARFASTParserSwift::ResolveTypeAlias(lldb_private::CompilerType alias) {
8892
DWARFDIE parent_die;
8993
if (TypeSP parent_type =
9094
ts.FindTypeInModule(parent_ctx.GetOpaqueQualType())) {
95+
auto *dwarf =
96+
llvm::cast<SymbolFileDWARF>(parent_type->GetSymbolFile());
9197
parent_die = dwarf->GetDIE(parent_type->GetID());
9298
auto unsubstituted_pair =
9399
findUnsubstitutedGenericTypeAndDIE(ts, parent_die);
@@ -157,9 +163,6 @@ getTypeAndDie(TypeSystemSwiftTypeRef &ts,
157163
return {};
158164
}
159165

160-
auto *dwarf = llvm::cast_or_null<SymbolFileDWARF>(ts.GetSymbolFile());
161-
if (!dwarf)
162-
return {};
163166
TypeSP lldb_type = ts.FindTypeInModule(type.GetOpaqueQualType());
164167
if (!lldb_type) {
165168
if (ts.ContainsBoundGenericType(type.GetOpaqueQualType())) {
@@ -170,6 +173,8 @@ getTypeAndDie(TypeSystemSwiftTypeRef &ts,
170173
if (!lldb_type) {
171174
std::tie(lldb_type, type) = DWARFASTParserSwift::ResolveTypeAlias(type);
172175
if (lldb_type) {
176+
auto *dwarf =
177+
llvm::cast<SymbolFileDWARF>(lldb_type->GetSymbolFile());
173178
auto die = dwarf->GetDIE(lldb_type->GetID());
174179
return {{type, die}};
175180
}
@@ -181,6 +186,7 @@ getTypeAndDie(TypeSystemSwiftTypeRef &ts,
181186
type.GetMangledTypeName());
182187
return {};
183188
}
189+
auto *dwarf = llvm::cast<SymbolFileDWARF>(lldb_type->GetSymbolFile());
184190
auto die = dwarf->GetDIE(lldb_type->GetID());
185191

186192
if (auto unsubstituted_pair = findUnsubstitutedGenericTypeAndDIE(ts, die))
@@ -360,18 +366,18 @@ class DWARFFieldRecordImpl : public swift::reflection::FieldRecordBase {
360366
class DWARFFieldDescriptorImpl : public swift::reflection::FieldDescriptorBase {
361367
TypeSystemSwiftTypeRef &m_type_system;
362368
ConstString m_mangled_name;
363-
DIERef m_die_ref;
369+
DWARFDIE m_die;
364370
NodePointer m_superclass_node;
365371

366372
public:
367373
DWARFFieldDescriptorImpl(swift::reflection::FieldDescriptorKind kind,
368374
NodePointer superclass_node,
369375
TypeSystemSwiftTypeRef &type_system,
370-
ConstString mangled_name, DIERef die_ref)
376+
ConstString mangled_name, DWARFDIE die)
371377
: swift::reflection::FieldDescriptorBase(kind,
372378
superclass_node != nullptr),
373379
m_type_system(type_system), m_mangled_name(mangled_name),
374-
m_die_ref(die_ref), m_superclass_node(superclass_node) {}
380+
m_die(die), m_superclass_node(superclass_node) {}
375381

376382
~DWARFFieldDescriptorImpl() override = default;
377383

@@ -386,22 +392,16 @@ class DWARFFieldDescriptorImpl : public swift::reflection::FieldDescriptorBase {
386392
lldb_private::AutoBool::False &&
387393
"Full DWARF debugging for Swift is disabled!");
388394

389-
auto *dwarf =
390-
llvm::dyn_cast<SymbolFileDWARF>(m_type_system.GetSymbolFile());
391395
auto *dwarf_parser = m_type_system.GetDWARFParser();
392-
if (!dwarf || !dwarf_parser)
393-
return {};
394-
395-
auto die = dwarf->GetDIE(m_die_ref);
396-
if (!die)
396+
if (!m_die || !dwarf_parser)
397397
return {};
398398

399399
switch (Kind) {
400400
case swift::reflection::FieldDescriptorKind::Struct:
401401
case swift::reflection::FieldDescriptorKind::Class:
402-
return getFieldRecordsFromStructOrClass(die, dwarf_parser);
402+
return getFieldRecordsFromStructOrClass(m_die, dwarf_parser);
403403
case swift::reflection::FieldDescriptorKind::Enum:
404-
return getFieldRecordsFromEnum(die, dwarf_parser);
404+
return getFieldRecordsFromEnum(m_die, dwarf_parser);
405405
default:
406406
// TODO: handle more cases.
407407
LLDB_LOG(GetLog(LLDBLog::Types),
@@ -663,5 +663,5 @@ DWARFASTParserSwift::getFieldDescriptor(const swift::reflection::TypeRef *TR) {
663663

664664
return std::make_unique<DWARFFieldDescriptorImpl>(
665665
*kind, superclass_pointer, m_swift_typesystem, type.GetMangledTypeName(),
666-
*die.GetDIERef());
666+
die);
667667
}

0 commit comments

Comments
 (0)