Skip to content

[lldb/Swift] Add progress report callback when loading a module #4773

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
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,8 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
m_ast_context_ap.reset(swift::ASTContext::get(
GetLanguageOptions(), GetTypeCheckerOptions(), GetSILOptions(),
GetSearchPathOptions(), GetClangImporterOptions(),
GetSymbolGraphOptions(), GetSourceManager(), GetDiagnosticEngine()));
GetSymbolGraphOptions(), GetSourceManager(), GetDiagnosticEngine(),
ReportModuleLoadingProgress));
m_diagnostic_consumer_ap.reset(new StoringDiagnosticConsumer(*this));

if (getenv("LLDB_SWIFT_DUMP_DIAGS")) {
Expand Down Expand Up @@ -3407,6 +3408,15 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
m_swift_module_cache.insert({ID, module});
}

bool SwiftASTContext::ReportModuleLoadingProgress(llvm::StringRef module_name,
bool is_overlay) {
Progress progress(llvm::formatv(is_overlay ? "Importing overlay module {0}"
: "Importing module {0}",
module_name.data())
.str());
return true;
}

swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
Status &error, bool *cached) {
if (cached)
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ class SwiftASTContext : public TypeSystemSwift {
swift::ModuleDecl *CreateModule(const SourceModule &module, Status &error,
swift::ImplicitImportInfo importInfo);

static bool ReportModuleLoadingProgress(llvm::StringRef module_name,
bool is_overlay);

// This function should only be called when all search paths
// for all items in a swift::ASTContext have been setup to
// allow for imports to happen correctly. Use with caution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def setUp(self):
self.broadcaster = self.dbg.GetBroadcaster()
self.listener = lldbutil.start_listening_from(self.broadcaster,
lldb.SBDebugger.eBroadcastBitProgress)

# Don't run ClangImporter tests if Clangimporter is disabled.
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
@skipUnlessDarwin
@swiftTest
@skipIf(oslist=no_match(["macosx"]))
def test_swift_progress_report(self):
"""Test that we are able to fetch swift type-system progress events"""
self.build()
Expand All @@ -32,11 +35,13 @@ def test_swift_progress_report(self):

# Resolve variable to exercise the type-system
self.runCmd("expr boo")
self.runCmd("v s")

beacons = [ "Loading Swift module",
"Caching Swift user imports from",
"Setting up Swift reflection for",
"Getting Swift compile unit imports for"]
"Getting Swift compile unit imports for",
"Importing module", "Importing overlay module"]

while len(beacons):
event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Invisible
import Foundation

func main() {
let boo = Invisible.👻()
let s = NSAttributedString(string: "Hello")
print("break here")
}

Expand Down