[lldb] [llvm] [lldb-dap] Add multi-session support with shared debugger instances (PR #163653)

John Harrison via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 10:47:04 PDT 2025


================
@@ -1289,13 +1293,92 @@ protocol::Capabilities DAP::GetCustomCapabilities() {
 }
 
 void DAP::StartEventThread() {
-  event_thread = std::thread(&DAP::EventThread, this);
+  // Get event thread for this debugger (creates it if it doesn't exist).
+  event_thread_sp = DAPSessionManager::GetInstance().GetEventThreadForDebugger(
+      debugger, this);
 }
 
 void DAP::StartProgressEventThread() {
   progress_event_thread = std::thread(&DAP::ProgressEventThread, this);
 }
 
+void DAP::StartEventThreads() {
+  if (clientFeatures.contains(eClientFeatureProgressReporting))
+    StartProgressEventThread();
+
+  StartEventThread();
+}
+
+llvm::Error DAP::InitializeDebugger(std::optional<uint32_t> target_id) {
+  // Initialize debugger instance (shared or individual).
+  if (target_id) {
+    std::optional<lldb::SBTarget> shared_target =
+        DAPSessionManager::GetInstance().TakeTargetById(*target_id);
+    // If the target ID is not valid, then we won't find a target.
+    if (!shared_target) {
+      return llvm::createStringError(
+          "Unable to find existing target for target ID");
+    }
+    // Get the debugger from the target and set it up.
+    debugger = shared_target->GetDebugger();
+    StartEventThreads();
----------------
ashgti wrote:

Should we have a hook for running any commands when the debugger is reused? Reusing the debugger would any state would be persisted between DAP sessions and having a hook to perform any updates would be helpful, I think.

https://github.com/llvm/llvm-project/pull/163653


More information about the llvm-commits mailing list