Skip to content

Commit 9f230a1

Browse files
committed
add swift-use-reflection-symbols experimental setting (default true)
1 parent 1060cf3 commit 9f230a1

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class TargetProperties : public Properties {
173173

174174
bool GetSwiftReadMetadataFromFileCache() const;
175175

176+
bool GetSwiftUseReflectionSymbols() const;
177+
176178
bool GetEnableAutoImportClangModules() const;
177179

178180
bool GetUseAllCompilerFlags() const;

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,28 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
127127
// by loading other parts of reflection metadata, but that work has a cost.
128128
// For lldb, that data loading can be a significant performance hit. Providing
129129
// a symbol greatly reduces memory read traffic to the process.
130-
Address addr;
130+
auto pointer = swift::remote::RemoteAbsolutePointer("", readValue);
131+
131132
auto &target = m_process.GetTarget();
132-
if (target.ResolveLoadAddress(address.getAddressData(), addr))
133-
if (addr.GetSection()->CanContainSwiftReflectionData())
134-
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
135-
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
136-
// MemoryReader requires this to be a Swift symbol. LLDB can also be
137-
// aware of local symbols, so avoid returning those.
138-
if (swift::Demangle::isSwiftSymbol(mangledName))
139-
return {mangledName, 0};
140-
}
133+
if (!target.GetSwiftUseReflectionSymbols())
134+
return pointer;
135+
136+
Address addr;
137+
if (!target.ResolveLoadAddress(address.getAddressData(), addr))
138+
return pointer;
139+
140+
if (!addr.GetSection()->CanContainSwiftReflectionData())
141+
return pointer;
142+
143+
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
144+
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
145+
// MemoryReader requires this to be a Swift symbol. LLDB can also be
146+
// aware of local symbols, so avoid returning those.
147+
if (swift::Demangle::isSwiftSymbol(mangledName))
148+
return {mangledName, 0};
149+
}
141150

142-
// Return the read value as is.
143-
return {"", (int64_t)readValue};
151+
return pointer;
144152
}
145153

146154
bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,

lldb/source/Target/Target.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,18 @@ bool TargetProperties::GetSwiftReadMetadataFromFileCache() const {
41684168
return true;
41694169
}
41704170

4171+
bool TargetProperties::GetSwiftUseReflectionSymbols() const {
4172+
const Property *exp_property = m_collection_sp->GetPropertyAtIndex(
4173+
nullptr, false, ePropertyExperimental);
4174+
OptionValueProperties *exp_values =
4175+
exp_property->GetValue()->GetAsProperties();
4176+
if (exp_values)
4177+
return exp_values->GetPropertyAtIndexAsBoolean(
4178+
nullptr, ePropertySwiftUseReflectionSymbols, true);
4179+
else
4180+
return true;
4181+
}
4182+
41714183
ArchSpec TargetProperties::GetDefaultArchitecture() const {
41724184
OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(
41734185
nullptr, ePropertyDefaultArch);

lldb/source/Target/TargetProperties.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ let Definition = "target_experimental" in {
1010
def SwiftReadMetadataFromFileCache: Property<"swift-read-metadata-from-file-cache", "Boolean">,
1111
DefaultTrue,
1212
Desc<"Read Swift reflection metadata from the file cache instead of the process when possible">;
13+
def SwiftUseReflectionSymbols : Property<"swift-use-reflection-symbols", "Boolean">,
14+
Global, DefaultTrue,
15+
Desc<"if true, optimize the loading of Swift reflection metadata by making use of available symbols.">;
1316
}
1417

1518
let Definition = "target" in {

0 commit comments

Comments
 (0)