Skip to content

Commit b178534

Browse files
authored
Merge pull request llvm#8471 from augusto2112/cp-d39266df97
[lldb] Detect when full DWARF debugging should be enabled
2 parents 3708688 + 95c779f commit b178534

File tree

7 files changed

+90
-51
lines changed

7 files changed

+90
-51
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class TargetProperties : public Properties {
184184

185185
bool GetSwiftEnableBareSlashRegex() const;
186186

187-
EnableSwiftCxxInterop GetEnableSwiftCxxInterop() const;
187+
AutoBool GetEnableSwiftCxxInterop() const;
188188

189-
bool GetSwiftEnableFullDwarfDebugging() const;
189+
AutoBool GetSwiftEnableFullDwarfDebugging() const;
190190

191191
bool GetSwiftAllowExplicitModules() const;
192192

lldb/include/lldb/lldb-private-enumerations.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ typedef enum SwiftModuleLoadingMode {
177177
} SwiftModuleLoadingMode;
178178

179179
// BEGIN SWIFT
180-
enum EnableSwiftCxxInterop {
181-
eAutoDetectSwiftCxxInterop,
182-
eEnableSwiftCxxInterop,
183-
eDisableSwiftCxxInterop
180+
enum class AutoBool {
181+
Auto,
182+
True,
183+
False
184184
};
185185
// END SWIFT
186186

lldb/source/Core/Module.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,16 +1168,16 @@ bool Module::IsSwiftCxxInteropEnabled() {
11681168
case eLazyBoolCalculate:
11691169
break;
11701170
}
1171-
EnableSwiftCxxInterop interop_enabled =
1171+
AutoBool interop_enabled =
11721172
Target::GetGlobalProperties().GetEnableSwiftCxxInterop();
11731173
switch (interop_enabled) {
1174-
case eEnableSwiftCxxInterop:
1174+
case AutoBool::True:
11751175
m_is_swift_cxx_interop_enabled = eLazyBoolYes;
11761176
break;
1177-
case eDisableSwiftCxxInterop:
1177+
case AutoBool::False:
11781178
m_is_swift_cxx_interop_enabled = eLazyBoolNo;
11791179
break;
1180-
case eAutoDetectSwiftCxxInterop: {
1180+
case AutoBool::Auto: {
11811181
// Look for the "-enable-experimental-cxx-interop" compile flag in the args
11821182
// of the compile units this module is composed of.
11831183
auto *sym_file = GetSymbolFile();

lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ struct DescriptorFinderForwarder : public swift::reflection::DescriptorFinder {
3232

3333
std::unique_ptr<swift::reflection::BuiltinTypeDescriptorBase>
3434
getBuiltinTypeDescriptor(const swift::reflection::TypeRef *TR) override {
35-
if (m_descriptor_finder)
35+
if (m_descriptor_finder && shouldConsultDescriptorFinder())
3636
return m_descriptor_finder->getBuiltinTypeDescriptor(TR);
3737
return nullptr;
3838
}
3939

4040
std::unique_ptr<swift::reflection::FieldDescriptorBase>
4141
getFieldDescriptor(const swift::reflection::TypeRef *TR) override {
42-
if (m_descriptor_finder)
42+
if (m_descriptor_finder && shouldConsultDescriptorFinder())
4343
return m_descriptor_finder->getFieldDescriptor(TR);
4444
return nullptr;
4545
}
4646

4747
std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
4848
getMultiPayloadEnumDescriptor(const swift::reflection::TypeRef *TR) override {
49-
if (m_descriptor_finder)
49+
if (m_descriptor_finder && shouldConsultDescriptorFinder())
5050
return m_descriptor_finder->getMultiPayloadEnumDescriptor(TR);
5151
return nullptr;
5252
}
@@ -57,8 +57,26 @@ struct DescriptorFinderForwarder : public swift::reflection::DescriptorFinder {
5757

5858
void ClearExternalDescriptorFinder() { m_descriptor_finder = nullptr; }
5959

60+
void SetImageAdded(bool image_added) {
61+
m_image_added |= image_added;
62+
}
63+
6064
private:
65+
bool shouldConsultDescriptorFinder() {
66+
switch (Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging()) {
67+
case lldb_private::AutoBool::True:
68+
return true;
69+
case lldb_private::AutoBool::False:
70+
return false;
71+
case lldb_private::AutoBool::Auto:
72+
// Full DWARF debugging is auto-enabled if there is no reflection metadata
73+
// to read from.
74+
return !m_image_added;
75+
}
76+
}
77+
6178
swift::reflection::DescriptorFinder *m_descriptor_finder = nullptr;
79+
bool m_image_added = false;
6280
};
6381

6482
/// An implementation of the generic ReflectionContextInterface that
@@ -82,21 +100,27 @@ class TargetReflectionContext : public ReflectionContextInterface {
82100
swift::ReflectionSectionKind)>
83101
find_section,
84102
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) override {
85-
return m_reflection_ctx.addImage(find_section, likely_module_names);
103+
auto id = m_reflection_ctx.addImage(find_section, likely_module_names);
104+
m_forwader.SetImageAdded(id.has_value());
105+
return id;
86106
}
87107

88108
std::optional<uint32_t>
89109
AddImage(swift::remote::RemoteAddress image_start,
90110
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) override {
91-
return m_reflection_ctx.addImage(image_start, likely_module_names);
111+
auto id = m_reflection_ctx.addImage(image_start, likely_module_names);
112+
m_forwader.SetImageAdded(id.has_value());
113+
return id;
92114
}
93115

94116
std::optional<uint32_t> ReadELF(
95117
swift::remote::RemoteAddress ImageStart,
96118
std::optional<llvm::sys::MemoryBlock> FileBuffer,
97119
llvm::SmallVector<llvm::StringRef, 1> likely_module_names = {}) override {
98-
return m_reflection_ctx.readELF(ImageStart, FileBuffer,
120+
auto id = m_reflection_ctx.readELF(ImageStart, FileBuffer,
99121
likely_module_names);
122+
m_forwader.SetImageAdded(id.has_value());
123+
return id;
100124
}
101125

102126
const swift::reflection::TypeRef *GetTypeRefOrNull(

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ class DWARFFieldDescriptorImpl : public swift::reflection::FieldDescriptorBase {
147147

148148
std::vector<std::unique_ptr<swift::reflection::FieldRecordBase>>
149149
getFieldRecords() override {
150-
if (!Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging())
151-
return {};
150+
assert(Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging() !=
151+
lldb_private::AutoBool::False &&
152+
"Full DWARF debugging for Swift is disabled!");
153+
152154
auto *dwarf =
153155
llvm::dyn_cast<SymbolFileDWARF>(m_type_system.GetSymbolFile());
154156
auto *dwarf_parser = m_type_system.GetDWARFParser();
@@ -303,8 +305,9 @@ class DWARFMultiPayloadEnumDescriptorImpl
303305
std::unique_ptr<swift::reflection::BuiltinTypeDescriptorBase>
304306
DWARFASTParserSwift::getBuiltinTypeDescriptor(
305307
const swift::reflection::TypeRef *TR) {
306-
if (!Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging())
307-
return nullptr;
308+
assert(Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging() !=
309+
lldb_private::AutoBool::False &&
310+
"Full DWARF debugging for Swift is disabled!");
308311

309312
auto pair = getTypeAndDie(m_swift_typesystem, TR);
310313
if (!pair)
@@ -344,8 +347,9 @@ DWARFASTParserSwift::getBuiltinTypeDescriptor(
344347
std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
345348
DWARFASTParserSwift::getMultiPayloadEnumDescriptor(
346349
const swift::reflection::TypeRef *TR) {
347-
if (!Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging())
348-
return nullptr;
350+
assert(Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging() !=
351+
lldb_private::AutoBool::False &&
352+
"Full DWARF debugging for Swift is disabled!");
349353

350354
auto pair = getTypeAndDie(m_swift_typesystem, TR);
351355
if (!pair)
@@ -449,8 +453,10 @@ NodePointer DWARFASTParserSwift::GetCanonicalDemangleTree(DWARFDIE &die) {
449453

450454
std::unique_ptr<swift::reflection::FieldDescriptorBase>
451455
DWARFASTParserSwift::getFieldDescriptor(const swift::reflection::TypeRef *TR) {
452-
if (!Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging())
453-
return nullptr;
456+
assert(Target::GetGlobalProperties().GetSwiftEnableFullDwarfDebugging() !=
457+
lldb_private::AutoBool::False &&
458+
"Full DWARF debugging for Swift is disabled!");
459+
454460

455461
auto pair = getTypeAndDie(m_swift_typesystem, TR);
456462
if (!pair)

lldb/source/Target/Target.cpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,15 +3101,15 @@ bool Target::IsSwiftCxxInteropEnabled() {
31013101
break;
31023102
}
31033103

3104-
EnableSwiftCxxInterop interop_enabled = GetEnableSwiftCxxInterop();
3104+
AutoBool interop_enabled = GetEnableSwiftCxxInterop();
31053105
switch (interop_enabled) {
3106-
case eEnableSwiftCxxInterop:
3106+
case AutoBool::True:
31073107
m_is_swift_cxx_interop_enabled = eLazyBoolYes;
31083108
break;
3109-
case eDisableSwiftCxxInterop:
3109+
case AutoBool::False:
31103110
m_is_swift_cxx_interop_enabled = eLazyBoolNo;
31113111
break;
3112-
case eAutoDetectSwiftCxxInterop: {
3112+
case AutoBool::Auto: {
31133113
if (GetImages().IsEmpty())
31143114
m_is_swift_cxx_interop_enabled = eLazyBoolNo;
31153115
else
@@ -4633,10 +4633,21 @@ static constexpr OptionEnumValueElement g_memory_module_load_level_values[] = {
46334633
};
46344634

46354635
static constexpr OptionEnumValueElement g_enable_swift_cxx_interop_values[] = {
4636-
{eAutoDetectSwiftCxxInterop, "auto",
4636+
{llvm::to_underlying(AutoBool::Auto), "auto",
46374637
"Automatically detect if C++ interop mode should be enabled."},
4638-
{eEnableSwiftCxxInterop, "true", "Enable C++ interop."},
4639-
{eDisableSwiftCxxInterop, "false", "Disable C++ interop."},
4638+
{llvm::to_underlying(AutoBool::True), "true", "Enable C++ interop."},
4639+
{llvm::to_underlying(AutoBool::False), "false", "Disable C++ interop."},
4640+
};
4641+
4642+
static constexpr OptionEnumValueElement g_enable_full_dwarf_debugging[] = {
4643+
{llvm::to_underlying(AutoBool::Auto), "auto",
4644+
"Automatically detect if full DWARF debugging should be enabled. Full "
4645+
"DWARF debugging is enabled if no reflection metadata is added to the "
4646+
"debugger."},
4647+
{llvm::to_underlying(AutoBool::True), "true",
4648+
"Enable full DWARF debugging."},
4649+
{llvm::to_underlying(AutoBool::False), "false",
4650+
"Disable full DWARF debugging."},
46404651
};
46414652

46424653
#define LLDB_PROPERTIES_target
@@ -4856,28 +4867,25 @@ bool TargetProperties::GetSwiftEnableBareSlashRegex() const {
48564867
return true;
48574868
}
48584869

4859-
EnableSwiftCxxInterop TargetProperties::GetEnableSwiftCxxInterop() const {
4870+
AutoBool TargetProperties::GetEnableSwiftCxxInterop() const {
48604871
const uint32_t idx = ePropertySwiftEnableCxxInterop;
48614872

4862-
EnableSwiftCxxInterop enable_interop =
4863-
(EnableSwiftCxxInterop)m_experimental_properties_up->GetValueProperties()
4864-
->GetPropertyAtIndexAs<EnableSwiftCxxInterop>(idx)
4865-
.value_or(static_cast<EnableSwiftCxxInterop>(
4873+
AutoBool enable_interop =
4874+
(AutoBool)m_experimental_properties_up->GetValueProperties()
4875+
->GetPropertyAtIndexAs<AutoBool>(idx)
4876+
.value_or(static_cast<AutoBool>(
48664877
g_target_properties[idx].default_uint_value));
48674878
return enable_interop;
48684879
}
48694880

4870-
bool TargetProperties::GetSwiftEnableFullDwarfDebugging() const {
4871-
const Property *exp_property =
4872-
m_collection_sp->GetPropertyAtIndex(ePropertyExperimental);
4873-
OptionValueProperties *exp_values =
4874-
exp_property->GetValue()->GetAsProperties();
4875-
if (exp_values)
4876-
return exp_values
4877-
->GetPropertyAtIndexAs<bool>(ePropertySwiftEnableFullDwarfDebugging)
4878-
.value_or(false);
4879-
4880-
return false;
4881+
AutoBool TargetProperties::GetSwiftEnableFullDwarfDebugging() const {
4882+
const uint32_t idx = ePropertySwiftEnableCxxInterop;
4883+
AutoBool enable_dwarf_debugging =
4884+
(AutoBool)m_experimental_properties_up->GetValueProperties()
4885+
->GetPropertyAtIndexAs<AutoBool>(idx)
4886+
.value_or(static_cast<AutoBool>(
4887+
g_target_properties[idx].default_uint_value));
4888+
return enable_dwarf_debugging;
48814889
}
48824890

48834891
bool TargetProperties::GetSwiftAllowExplicitModules() const {

lldb/source/Target/TargetProperties.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ let Definition = "target_experimental" in {
2020
DefaultFalse,
2121
Desc<"Passes the -enable-bare-slash-regex compiler flag to the swift compiler.">;
2222
def SwiftEnableCxxInterop: Property<"swift-enable-cxx-interop", "Enum">,
23-
DefaultEnumValue<"eAutoDetectSwiftCxxInterop">,
23+
DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">,
2424
EnumValues<"OptionEnumValues(g_enable_swift_cxx_interop_values)">,
2525
Desc<"Passes the -enable-cxx-interop flag to the swift compiler.">;
2626
def SwiftPluginServerForPath: Property<"swift-plugin-server-for-path",
2727
"Dictionary">,
2828
ElementType<"String">,
2929
Desc<"A dictionary of plugin paths as keys and swift-plugin-server binaries as values">;
30-
def SwiftEnableFullDwarfDebugging: Property<"swift-enable-full-dwarf-debugging", "Boolean">,
31-
DefaultFalse,
32-
Desc<"Read full debug information from DWARF for Swift debugging, whenever possible">;
30+
def SwiftEnableFullDwarfDebugging: Property<"swift-enable-full-dwarf-debugging", "Enum">,
31+
DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">,
32+
EnumValues<"OptionEnumValues(g_enable_full_dwarf_debugging)">,
33+
Desc<"Read full debug information from DWARF for Swift debugging. By default LLDB will use DWARF debug information if it cannot use reflection metadata.">;
3334
def SwiftAllowExplicitModules: Property<"swift-allow-explicit-modules", "Boolean">,
3435
DefaultTrue,
3536
Desc<"Allows explicit module flags to be passed through to ClangImporter.">;

0 commit comments

Comments
 (0)