Skip to content

Commit 4aed073

Browse files
committed
Move output of debugger warnings into SwiftASTContext.
The only noticeable side effect is that now each diagnostics printed separately.
1 parent 8250a14 commit 4aed073

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,6 @@ class Module : public std::enable_shared_from_this<Module>,
844844

845845
#ifdef LLDB_ENABLE_SWIFT
846846
void
847-
ReportWarningCantLoadSwiftModule(std::string details,
848-
llvm::Optional<lldb::user_id_t> debugger_id);
849-
void
850847
ReportWarningToolchainMismatch(CompileUnit &comp_unit,
851848
llvm::Optional<lldb::user_id_t> debugger_id);
852849

@@ -1110,7 +1107,6 @@ class Module : public std::enable_shared_from_this<Module>,
11101107
std::once_flag m_optimization_warning;
11111108
std::once_flag m_language_warning;
11121109
#ifdef LLDB_ENABLE_SWIFT
1113-
std::once_flag m_swift_import_warning;
11141110
std::once_flag m_toolchain_mismatch_warning;
11151111
#endif
11161112

lldb/include/lldb/Target/Process.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,6 @@ class Process : public std::enable_shared_from_this<Process>,
13501350
void PrintWarningOptimization(const SymbolContext &sc);
13511351

13521352
#ifdef LLDB_ENABLE_SWIFT
1353-
/// Prints a async warning message to the user one time per Process
1354-
/// for a Module whose Swift AST sections couldn't be loaded because
1355-
/// they aren't buildable on the current machine.
1356-
///
1357-
/// @param [in] module
1358-
/// The affected Module.
1359-
void PrintWarningCantLoadSwiftModule(Module &module, std::string details);
1360-
13611353
/// Print a user-visible warning about Swift CUs compiled with a
13621354
/// different Swift compiler than the one embedded in LLDB.
13631355
void PrintWarningToolchainMismatch(const SymbolContext &sc);

lldb/source/Core/Module.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,6 @@ void Module::ReportWarningUnsupportedLanguage(
11791179
}
11801180

11811181
#ifdef LLDB_ENABLE_SWIFT
1182-
void Module::ReportWarningCantLoadSwiftModule(
1183-
std::string details, llvm::Optional<lldb::user_id_t> debugger_id) {
1184-
StreamString ss;
1185-
ss << GetFileSpec() << ": "
1186-
<< "Cannot load Swift type information: " << details;
1187-
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
1188-
&m_swift_import_warning);
1189-
}
1190-
11911182
static llvm::VersionTuple GetAdjustedVersion(llvm::VersionTuple version) {
11921183
return version;
11931184
}

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,14 @@ static void printASTValidationError(
11181118
}
11191119

11201120
void SwiftASTContext::DiagnoseWarnings(Process &process, Module &module) const {
1121-
if (HasDiagnostics())
1122-
process.PrintWarningCantLoadSwiftModule(module,
1123-
GetAllDiagnostics().AsCString());
1121+
if (!HasDiagnostics())
1122+
return;
1123+
auto debugger_id = process.GetTarget().GetDebugger().GetID();
1124+
std::string msg;
1125+
llvm::raw_string_ostream(msg) << "Cannot load Swift type information for "
1126+
<< module.GetFileSpec().GetPath();
1127+
Debugger::ReportWarning(msg, debugger_id, &m_swift_import_warning);
1128+
StreamAllDiagnostics(debugger_id);
11241129
}
11251130

11261131
/// Locate the swift-plugin-server for a plugin library,
@@ -2483,6 +2488,35 @@ Status SwiftASTContext::GetAllDiagnostics() const {
24832488
return error;
24842489
}
24852490

2491+
void SwiftASTContext::StreamAllDiagnostics(
2492+
llvm::Optional<lldb::user_id_t> debugger_id) const {
2493+
Status error = m_fatal_errors;
2494+
if (!error.Success()) {
2495+
Debugger::ReportWarning(error.AsCString(), debugger_id,
2496+
&m_swift_diags_streamed);
2497+
return;
2498+
}
2499+
2500+
// Retrieve the error message from the DiagnosticConsumer.
2501+
DiagnosticManager diagnostic_manager;
2502+
PrintDiagnostics(diagnostic_manager);
2503+
for (auto &diag : diagnostic_manager.Diagnostics())
2504+
if (diag) {
2505+
std::string msg = diag->GetMessage().str();
2506+
switch (diag->GetSeverity()) {
2507+
case eDiagnosticSeverityError:
2508+
Debugger::ReportError(msg, debugger_id, &m_swift_diags_streamed);
2509+
break;
2510+
case eDiagnosticSeverityWarning:
2511+
case eDiagnosticSeverityRemark:
2512+
Debugger::ReportWarning(msg, debugger_id, &m_swift_warning_streamed);
2513+
break;
2514+
}
2515+
}
2516+
static_cast<StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get())
2517+
->Clear();
2518+
}
2519+
24862520
void SwiftASTContext::LogFatalErrors() const {
24872521
// Avoid spamming the health log with redundant copies of the fatal error.
24882522
if (m_logged_fatal_error) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ class SwiftASTContext : public TypeSystemSwift {
859859
/// Called by the VALID_OR_RETURN macro to log all errors.
860860
void LogFatalErrors() const;
861861
Status GetAllDiagnostics() const;
862+
/// Stream all diagnostics to the Debugger and clear them.
863+
void StreamAllDiagnostics(llvm::Optional<lldb::user_id_t> debugger_id) const;
862864

863865
llvm::TargetOptions *getTargetOptions();
864866

@@ -903,6 +905,9 @@ class SwiftASTContext : public TypeSystemSwift {
903905
std::unique_ptr<swift::irgen::IRGenerator> m_ir_generator_ap;
904906
std::unique_ptr<swift::irgen::IRGenModule> m_ir_gen_module_ap;
905907
llvm::once_flag m_ir_gen_module_once;
908+
mutable std::once_flag m_swift_import_warning;
909+
mutable std::once_flag m_swift_diags_streamed;
910+
mutable std::once_flag m_swift_warning_streamed;
906911
std::unique_ptr<swift::DiagnosticConsumer> m_diagnostic_consumer_ap;
907912
std::unique_ptr<swift::DependencyTracker> m_dependency_tracker;
908913
swift::ModuleDecl *m_scratch_module = nullptr;

lldb/source/Target/Process.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6010,12 +6010,6 @@ void Process::PrintWarningOptimization(const SymbolContext &sc) {
60106010
}
60116011

60126012
#ifdef LLDB_ENABLE_SWIFT
6013-
void Process::PrintWarningCantLoadSwiftModule(Module &module,
6014-
std::string details) {
6015-
module.ReportWarningCantLoadSwiftModule(std::move(details),
6016-
GetTarget().GetDebugger().GetID());
6017-
}
6018-
60196013
void Process::PrintWarningToolchainMismatch(const SymbolContext &sc) {
60206014
if (GetTarget().GetProcessLaunchInfo().IsScriptedProcess())
60216015
// It's very likely that the debugger used to launch the ScriptedProcess

lldb/test/Shell/Swift/DeserializationFailure.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ run
1818
expression 1
1919

2020
# The {{ }} avoids accidentally matching the input script!
21-
# CHECK: a.out:{{ }}{{.*}}The serialized module is corrupted.
21+
# CHECK: {{ }}a.out
22+
# CHECK: {{ }}The serialized module is corrupted.

0 commit comments

Comments
 (0)