Skip to content

Commit 97740ea

Browse files
committed
[lldb] Log SwiftASTContext configuration to Swift health
1 parent f6faf0c commit 97740ea

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

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

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ std::recursive_mutex g_log_mutex;
185185
} \
186186
} while (0)
187187

188+
#define SWIFT_LOG_PRINTF(FMT, ...) \
189+
LOG_PRINTF_IMPL(LIBLLDB_LOG_TYPES, false, FMT, ##__VA_ARGS__); \
190+
SWIFT_LOG_PRINTF_IMPL(FMT, ##__VA_ARGS__)
191+
#define SWIFT_LOG_PRINTF_IMPL(FMT, ...) \
192+
do { \
193+
if (Log *log = lldb_private::GetSwiftHealthLog()) { \
194+
std::lock_guard<std::recursive_mutex> locker(g_log_mutex); \
195+
/* The format string is optimized for code size, not speed. */ \
196+
log->Printf("%s::%s%s" FMT, m_description.c_str(), \
197+
IsLambda(__FUNCTION__) ? "" : __FUNCTION__, \
198+
(FMT && FMT[0] == '(') ? "" : "() -- ", ##__VA_ARGS__); \
199+
} \
200+
} while (0)
201+
188202
using namespace lldb;
189203
using namespace lldb_private;
190204

@@ -5078,65 +5092,61 @@ void SwiftASTContext::ClearModuleDependentCaches() {
50785092
void SwiftASTContext::LogConfiguration() {
50795093
// It makes no sense to call VALID_OR_RETURN here. We specifically
50805094
// want the logs in the error case!
5081-
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES));
5082-
if (!log)
5083-
return;
5084-
5085-
LOG_PRINTF(LIBLLDB_LOG_TYPES,
5086-
"(SwiftASTContext*)%p:", static_cast<void *>(this));
5095+
SWIFT_LOG_PRINTF("(SwiftASTContext*)%p:", static_cast<void *>(this));
50875096

50885097
if (!m_ast_context_ap) {
5089-
log->Printf(" (no AST context)");
5098+
SWIFT_LOG_PRINTF(" (no AST context)");
50905099
return;
50915100
}
50925101

5093-
log->Printf(" Architecture : %s",
5094-
m_ast_context_ap->LangOpts.Target.getTriple().c_str());
5095-
log->Printf(" SDK path : %s",
5096-
m_ast_context_ap->SearchPathOpts.SDKPath.c_str());
5097-
log->Printf(" Runtime resource path : %s",
5098-
m_ast_context_ap->SearchPathOpts.RuntimeResourcePath.c_str());
5099-
log->Printf(" Runtime library paths : (%llu items)",
5100-
(unsigned long long)
5101-
m_ast_context_ap->SearchPathOpts.RuntimeLibraryPaths.size());
5102+
SWIFT_LOG_PRINTF(" Architecture : %s",
5103+
m_ast_context_ap->LangOpts.Target.getTriple().c_str());
5104+
SWIFT_LOG_PRINTF(" SDK path : %s",
5105+
m_ast_context_ap->SearchPathOpts.SDKPath.c_str());
5106+
SWIFT_LOG_PRINTF(
5107+
" Runtime resource path : %s",
5108+
m_ast_context_ap->SearchPathOpts.RuntimeResourcePath.c_str());
5109+
SWIFT_LOG_PRINTF(" Runtime library paths : (%llu items)",
5110+
(unsigned long long)m_ast_context_ap->SearchPathOpts
5111+
.RuntimeLibraryPaths.size());
51025112

51035113
for (const auto &runtime_library_path :
51045114
m_ast_context_ap->SearchPathOpts.RuntimeLibraryPaths) {
5105-
log->Printf(" %s", runtime_library_path.c_str());
5115+
SWIFT_LOG_PRINTF(" %s", runtime_library_path.c_str());
51065116
}
51075117

5108-
log->Printf(" Runtime library import paths : (%llu items)",
5109-
(unsigned long long)m_ast_context_ap->SearchPathOpts
5110-
.RuntimeLibraryImportPaths.size());
5118+
SWIFT_LOG_PRINTF(" Runtime library import paths : (%llu items)",
5119+
(unsigned long long)m_ast_context_ap->SearchPathOpts
5120+
.RuntimeLibraryImportPaths.size());
51115121

51125122
for (const auto &runtime_import_path :
51135123
m_ast_context_ap->SearchPathOpts.RuntimeLibraryImportPaths) {
5114-
log->Printf(" %s", runtime_import_path.c_str());
5124+
SWIFT_LOG_PRINTF(" %s", runtime_import_path.c_str());
51155125
}
51165126

5117-
log->Printf(" Framework search paths : (%llu items)",
5118-
(unsigned long long)
5119-
m_ast_context_ap->SearchPathOpts.FrameworkSearchPaths.size());
5127+
SWIFT_LOG_PRINTF(" Framework search paths : (%llu items)",
5128+
(unsigned long long)m_ast_context_ap->SearchPathOpts
5129+
.FrameworkSearchPaths.size());
51205130
for (const auto &framework_search_path :
51215131
m_ast_context_ap->SearchPathOpts.FrameworkSearchPaths) {
5122-
log->Printf(" %s", framework_search_path.Path.c_str());
5132+
SWIFT_LOG_PRINTF(" %s", framework_search_path.Path.c_str());
51235133
}
51245134

5125-
log->Printf(" Import search paths : (%llu items)",
5126-
(unsigned long long)
5127-
m_ast_context_ap->SearchPathOpts.ImportSearchPaths.size());
5135+
SWIFT_LOG_PRINTF(" Import search paths : (%llu items)",
5136+
(unsigned long long)m_ast_context_ap->SearchPathOpts
5137+
.ImportSearchPaths.size());
51285138
for (std::string &import_search_path :
51295139
m_ast_context_ap->SearchPathOpts.ImportSearchPaths) {
5130-
log->Printf(" %s", import_search_path.c_str());
5140+
SWIFT_LOG_PRINTF(" %s", import_search_path.c_str());
51315141
}
51325142

51335143
swift::ClangImporterOptions &clang_importer_options =
51345144
GetClangImporterOptions();
51355145

5136-
log->Printf(" Extra clang arguments : (%llu items)",
5137-
(unsigned long long)clang_importer_options.ExtraArgs.size());
5146+
SWIFT_LOG_PRINTF(" Extra clang arguments : (%llu items)",
5147+
(unsigned long long)clang_importer_options.ExtraArgs.size());
51385148
for (std::string &extra_arg : clang_importer_options.ExtraArgs) {
5139-
log->Printf(" %s", extra_arg.c_str());
5149+
SWIFT_LOG_PRINTF(" %s", extra_arg.c_str());
51405150
}
51415151
}
51425152

0 commit comments

Comments
 (0)