[Lldb-commits] [lldb] [lldb] Print a message when background tasks take a while to complete (PR #82799)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 28 20:02:26 PST 2024
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82799
>From 3db25301ed07ed0b44ff0f8cbe8d1657ba899036 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Wed, 28 Feb 2024 20:00:43 -0800
Subject: [PATCH] [lldb] Print a message when background tasks take a while to
complete
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.
---
lldb/tools/driver/Driver.cpp | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 9286abb27e1332..a821699c5e2ec2 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -33,6 +33,7 @@
#include <bitset>
#include <clocale>
#include <csignal>
+#include <future>
#include <string>
#include <thread>
#include <utility>
@@ -801,6 +802,18 @@ int main(int argc, char const *argv[]) {
}
}
- SBDebugger::Terminate();
+ // When terminating the debugger we have to wait on all the background tasks
+ // to complete, which can take a while. Print a message when this takes longer
+ // than 1 second.
+ {
+ std::future<void> future =
+ std::async(std::launch::async, []() { SBDebugger::Terminate(); });
+
+ if (future.wait_for(std::chrono::seconds(1)) == std::future_status::timeout)
+ fprintf(stderr, "Waiting for background tasks to complete...\n");
+
+ future.wait();
+ }
+
return exit_code;
}
More information about the lldb-commits
mailing list