Skip to content

Commit bafa348

Browse files
committed
[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. (cherry picked from commit 2f343fc)
1 parent 94447cf commit bafa348

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
@@ -32,6 +32,7 @@
3232
#include <bitset>
3333
#include <clocale>
3434
#include <csignal>
35+
#include <future>
3536
#include <string>
3637
#include <thread>
3738
#include <utility>
@@ -821,6 +822,18 @@ int main(int argc, char const *argv[]) {
821822
}
822823
}
823824

824-
SBDebugger::Terminate();
825+
// When terminating the debugger we have to wait on all the background tasks
826+
// to complete, which can take a while. Print a message when this takes longer
827+
// than 1 second.
828+
{
829+
std::future<void> future =
830+
std::async(std::launch::async, []() { SBDebugger::Terminate(); });
831+
832+
if (future.wait_for(std::chrono::seconds(1)) == std::future_status::timeout)
833+
fprintf(stderr, "Waiting for background tasks to complete...\n");
834+
835+
future.wait();
836+
}
837+
825838
return exit_code;
826839
}

0 commit comments

Comments
 (0)