https://github.com/ashgti created https://github.com/llvm/llvm-project/pull/170792
The new support for automatically attaching to targets during a debug session is not guarded on how lldb-dap is running. If its running over stdio then this feature will not work. Instead, I added a message to the console and skip attempting to attach. >From efcdf2180b327486def24a17fcd37241c1ff1043 Mon Sep 17 00:00:00 2001 From: John Harrison <[email protected]> Date: Thu, 4 Dec 2025 17:48:45 -0800 Subject: [PATCH] [lldb-dap] Detect if we can automatically attach to targets. The new support for automatically attaching to targets during a debug session is not guarded on how lldb-dap is running. If its running over stdio then this feature will not work. Instead, I added a message to the console and skip attempting to attach. --- lldb/tools/lldb-dap/DAPSessionManager.h | 4 ++++ lldb/tools/lldb-dap/EventHelper.cpp | 7 +++++++ lldb/tools/lldb-dap/tool/lldb-dap.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/lldb/tools/lldb-dap/DAPSessionManager.h b/lldb/tools/lldb-dap/DAPSessionManager.h index ad76b081ad78b..193a1c7ebce5a 100644 --- a/lldb/tools/lldb-dap/DAPSessionManager.h +++ b/lldb/tools/lldb-dap/DAPSessionManager.h @@ -59,6 +59,9 @@ class DAPSessionManager { /// Get the singleton instance of the DAP session manager. static DAPSessionManager &GetInstance(); + void SetServerMode() { m_server_mode = true; } + bool GetServerMode() { return m_server_mode; } + /// Register a DAP session. void RegisterSession(lldb_private::MainLoop *loop, DAP *dap); @@ -103,6 +106,7 @@ class DAPSessionManager { DAPSessionManager(DAPSessionManager &&) = delete; DAPSessionManager &operator=(DAPSessionManager &&) = delete; + bool m_server_mode = false; bool m_client_failed = false; std::mutex m_sessions_mutex; std::condition_variable m_sessions_condition; diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index bdb6bb55fe168..526e406031b7a 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -449,6 +449,13 @@ void HandleTargetEvent(const lldb::SBEvent &event, Log *log) { } } } else if (event_mask & lldb::SBTarget::eBroadcastBitNewTargetCreated) { + if (!DAPSessionManager::GetInstance().GetServerMode()) { + dap->SendOutput(OutputType::Console, + "lldb-dap: Enable server mode for automatically " + "attaching to new debugger targets."); + return; + } + // For NewTargetCreated events, GetTargetFromEvent returns the parent // target, and GetCreatedTargetFromEvent returns the newly created target. lldb::SBTarget created_target = diff --git a/lldb/tools/lldb-dap/tool/lldb-dap.cpp b/lldb/tools/lldb-dap/tool/lldb-dap.cpp index 27516b2a25678..2499b4dd12e6b 100644 --- a/lldb/tools/lldb-dap/tool/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/tool/lldb-dap.cpp @@ -425,6 +425,8 @@ static llvm::Error serveConnection( return status.takeError(); } + DAPSessionManager::GetInstance().SetServerMode(); + std::string address = llvm::join(listener->GetListeningConnectionURI(), ", "); DAP_LOG(log, "started with connection listeners {0}", address); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
