Skip to content

Commit 84304ad

Browse files
Merge pull request llvm#2413 from adrian-prantl/70008042-5.4
Invoke SwiftASTContext::LogConfiguration() on all error paths (NFC outside of types log)
2 parents 7c164fa + dec585e commit 84304ad

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lldb/scripts/check-ast-context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ def look_for_METHOD(c):
421421
'GetFatalErrors',
422422
'PrintDiagnostics',
423423
'GetASTContext',
424-
'SetTriple'
424+
'SetTriple',
425+
'LogConfiguration'
425426
]
426427

427428
for method in methods:

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,14 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
16941694
m_description,
16951695
target ? target->GetArchitecture().GetTriple() : triple,
16961696
target)));
1697+
bool suppress_config_log = false;
1698+
auto defer_log = llvm::make_scope_exit([swift_ast_sp, &suppress_config_log] {
1699+
// To avoid spamming the log with useless info, we don't log the
1700+
// configuration if everything went fine and the current module
1701+
// doesn't have any Swift contents (i.e., the shared cache dylibs).
1702+
if (!suppress_config_log)
1703+
swift_ast_sp->LogConfiguration();
1704+
});
16971705

16981706
// This is a module AST context, mark it as such.
16991707
swift_ast_sp->m_is_scratch_context = false;
@@ -1706,9 +1714,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
17061714

17071715
bool set_triple = false;
17081716
bool found_swift_modules = false;
1709-
17101717
SymbolFile *sym_file = module.GetSymbolFile();
1711-
17121718
std::string target_triple;
17131719

17141720
if (sym_file) {
@@ -1831,15 +1837,17 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
18311837

18321838
std::vector<std::string> module_names;
18331839
swift_ast_sp->RegisterSectionModules(module, module_names);
1834-
if (module_names.size()) {
1840+
if (!module_names.size()) {
1841+
// This dylib has no Swift contents; logging the configuration is pointless.
1842+
suppress_config_log = true;
1843+
} else {
18351844
swift_ast_sp->ValidateSectionModules(module, module_names);
18361845
if (lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES)) {
18371846
std::lock_guard<std::recursive_mutex> locker(g_log_mutex);
18381847
LOG_PRINTF(LIBLLDB_LOG_TYPES, "((Module*)%p, \"%s\") = %p",
18391848
static_cast<void *>(&module),
18401849
module.GetFileSpec().GetFilename().AsCString("<anonymous>"),
18411850
static_cast<void *>(swift_ast_sp.get()));
1842-
swift_ast_sp->LogConfiguration();
18431851
}
18441852
}
18451853

@@ -1926,6 +1934,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
19261934
// detect if we have a iOS simulator.
19271935
std::shared_ptr<SwiftASTContextForExpressions> swift_ast_sp(
19281936
new SwiftASTContextForExpressions(m_description, target));
1937+
auto defer_log = llvm::make_scope_exit(
1938+
[swift_ast_sp] { swift_ast_sp->LogConfiguration(); });
19291939

19301940
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Target)");
19311941

@@ -2280,7 +2290,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22802290
LOG_PRINTF(LIBLLDB_LOG_TYPES, "((Target*)%p) = %p",
22812291
static_cast<void *>(&target),
22822292
static_cast<void *>(swift_ast_sp.get()));
2283-
swift_ast_sp->LogConfiguration();
22842293

22852294
if (swift_ast_sp->HasFatalErrors()) {
22862295
logError(swift_ast_sp->GetFatalErrors().AsCString());
@@ -4929,8 +4938,8 @@ void SwiftASTContext::ClearModuleDependentCaches() {
49294938
}
49304939

49314940
void SwiftASTContext::LogConfiguration() {
4932-
VALID_OR_RETURN_VOID();
4933-
4941+
// It makes no sense to call VALID_OR_RETURN here. We specifically
4942+
// want the logs in the error case!
49344943
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES));
49354944
if (!log)
49364945
return;

0 commit comments

Comments
 (0)