Skip to content

Commit bf30120

Browse files
committed
[lldb] Add a setting to allow Swift AST context instantiations
For testing purposes, it's useful to have a setting to disable the instantiation of SwiftASTContext, to ensure that TypeSystemSwiftTypeRef, which by default falls back to it on failure, is working independently. This setting might also be useful for end users, as when debugging a program that was built with a different compiler version versus what is embedded in LLDB instantiation of Swift AST contexts would be moot.
1 parent 4de562f commit bf30120

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ModuleListProperties : public Properties {
9595

9696
AutoBool GetSwiftEnableCxxInterop() const;
9797
AutoBool GetSwiftEnableFullDwarfDebugging() const;
98+
bool GetSwiftEnableASTContext() const;
9899
// END SWIFT
99100

100101
FileSpec GetClangModulesCachePath() const;

lldb/source/Core/CoreProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ let Definition = "modulelist" in {
6464
DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">,
6565
EnumValues<"OptionEnumValues(g_enable_full_dwarf_debugging)">,
6666
Desc<"Read full debug information from DWARF for Swift debugging. By default LLDB will use DWARF debug information if it cannot use reflection metadata.">;
67+
def SwiftEnableASTContext: Property<"swift-enable-ast-context", "Boolean">,
68+
Global,
69+
DefaultTrue,
70+
Desc<"Enable instantiating Swift AST contexts.">;
6771
// END SWIFT
6872
def SymLinkPaths: Property<"debug-info-symlink-paths", "FileSpecList">,
6973
Global,

lldb/source/Core/ModuleList.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ AutoBool ModuleListProperties::GetSwiftEnableFullDwarfDebugging() const {
274274
idx, static_cast<AutoBool>(
275275
g_modulelist_properties[idx].default_uint_value));
276276
}
277+
278+
bool ModuleListProperties::GetSwiftEnableASTContext() const {
279+
const uint32_t idx = ePropertySwiftEnableASTContext;
280+
return GetPropertyAtIndexAs<bool>(
281+
idx, g_modulelist_properties[idx].default_uint_value != 0);
282+
}
277283
// END SWIFT
278284

279285
FileSpec ModuleListProperties::GetLLDBIndexCachePath() const {

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,10 @@ SwiftASTContext::SwiftASTContext(std::string description,
976976
: TypeSystemSwift(), m_typeref_typesystem(&typeref_typesystem),
977977
m_compiler_invocation_ap(new swift::CompilerInvocation()),
978978
m_diagnostic_consumer_ap(new StoringDiagnosticConsumer(*this)) {
979+
assert(
980+
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableASTContext() &&
981+
"Swift AST context instantiation is disabled!");
982+
979983
m_description = description;
980984

981985
// Set the clang modules cache path.
@@ -1884,6 +1888,10 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
18841888
if (!SwiftASTContextSupportsLanguage(language))
18851889
return lldb::TypeSystemSP();
18861890

1891+
if (!ModuleList::GetGlobalModuleListProperties()
1892+
.GetSwiftEnableASTContext())
1893+
return lldb::TypeSystemSP();
1894+
18871895
std::string m_description;
18881896
{
18891897
llvm::raw_string_ostream ss(m_description);
@@ -2359,6 +2367,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23592367
if (!SwiftASTContextSupportsLanguage(language))
23602368
return lldb::TypeSystemSP();
23612369

2370+
if (!ModuleList::GetGlobalModuleListProperties()
2371+
.GetSwiftEnableASTContext())
2372+
return lldb::TypeSystemSP();
2373+
23622374
LLDB_SCOPED_TIMER();
23632375
std::string m_description = "SwiftASTContextForExpressions";
23642376
std::vector<swift::PluginSearchOption> plugin_search_options;
@@ -2650,6 +2662,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
26502662
TypeSystemSwiftTypeRefForExpressions &typeref_typesystem) {
26512663
LLDB_SCOPED_TIMER();
26522664

2665+
if (!ModuleList::GetGlobalModuleListProperties()
2666+
.GetSwiftEnableASTContext())
2667+
return lldb::TypeSystemSP();
2668+
26532669
CompileUnit *cu = sc.comp_unit;
26542670
StringRef swift_module_name = TypeSystemSwiftTypeRef::GetSwiftModuleFor(&sc);
26552671
std::string m_description;

0 commit comments

Comments
 (0)