Skip to content

Improve error logging if SwiftASTContext cannot be constructed #5762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,26 +2446,31 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
if (auto *new_swift_scratch_ctx =
llvm::dyn_cast_or_null<TypeSystemSwiftTypeRefForExpressions>(
type_system_or_err->get())) {
auto report_error = [&](std::string message) {
m_cant_make_scratch_type_system[language] = true;
m_scratch_type_system_map.RemoveTypeSystemsForLanguage(language);
type_system_or_err = llvm::make_error<llvm::StringError>(
message, llvm::inconvertibleErrorCode());
};
auto *new_swift_ast_ctx =
new_swift_scratch_ctx->GetSwiftASTContext();
if (!new_swift_ast_ctx || new_swift_ast_ctx->HasFatalErrors()) {
if (!new_swift_ast_ctx)
report_error("Failed to construct SwiftASTContextForExpressions");
else if (new_swift_ast_ctx->HasFatalErrors()) {
DiagnosticManager diag_mgr;
new_swift_ast_ctx->PrintDiagnostics(diag_mgr);
std::string error_diagnostics = diag_mgr.GetString();
if (StreamSP error_stream_sp =
GetDebugger().GetAsyncErrorStream()) {
error_stream_sp->PutCString(
"Can't construct shared Swift state "
"for this process after repeated "
"attempts.\n");
error_stream_sp->PutCString("Giving up. Fatal errors:\n");
DiagnosticManager diag_mgr;
new_swift_ast_ctx->PrintDiagnostics(diag_mgr);
error_stream_sp->PutCString(diag_mgr.GetString().c_str());
error_stream_sp->PutCString(error_diagnostics.c_str());
error_stream_sp->Flush();
}

m_cant_make_scratch_type_system[language] = true;
m_scratch_type_system_map.RemoveTypeSystemsForLanguage(language);
type_system_or_err = llvm::make_error<llvm::StringError>(
"DIAF", llvm::inconvertibleErrorCode());
report_error(error_diagnostics);
}
}
}
Expand Down