Skip to content

Commit 2f343fc

Browse files
authored
[lldb] Print a message when background tasks take a while to complete (llvm#82799)
When terminating the debugger, we wait for all background tasks to complete. Given that there's no way to interrupt those treads, this can take a while. When that happens, the debugger appears to hang at exit. The above situation is unfortunately not uncommon when background downloading of dSYMs is enabled (`symbols.auto-download background`). Even when calling dsymForUUID with a reasonable timeout, it can take a while to complete. This patch improves the user experience by printing a message from the driver when it takes more than one (1) second to terminate the debugger.
1 parent 83ca78d commit 2f343fc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lldb/tools/driver/Driver.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <bitset>
3434
#include <clocale>
3535
#include <csignal>
36+
#include <future>
3637
#include <string>
3738
#include <thread>
3839
#include <utility>
@@ -801,6 +802,18 @@ int main(int argc, char const *argv[]) {
801802
}
802803
}
803804

804-
SBDebugger::Terminate();
805+
// When terminating the debugger we have to wait on all the background tasks
806+
// to complete, which can take a while. Print a message when this takes longer
807+
// than 1 second.
808+
{
809+
std::future<void> future =
810+
std::async(std::launch::async, []() { SBDebugger::Terminate(); });
811+
812+
if (future.wait_for(std::chrono::seconds(1)) == std::future_status::timeout)
813+
fprintf(stderr, "Waiting for background tasks to complete...\n");
814+
815+
future.wait();
816+
}
817+
805818
return exit_code;
806819
}

0 commit comments

Comments
 (0)