diff options
| author | Ebuka Ezike <yerimyah1@gmail.com> | 2025-10-20 21:54:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-20 21:54:13 +0100 |
| commit | cd67ca2f11f79d2ce08807682b571ca04dab0996 (patch) | |
| tree | 3a0771b2158e50bc0f327bcf571512afd37117ed /lldb/tools | |
| parent | 670fb3e7683c1fc83bcfff04bb15488617ff2a34 (diff) | |
| download | llvm-cd67ca2f11f79d2ce08807682b571ca04dab0996.tar.gz llvm-cd67ca2f11f79d2ce08807682b571ca04dab0996.tar.bz2 llvm-cd67ca2f11f79d2ce08807682b571ca04dab0996.zip | |
[lldb-dap] Send an Invalidated event on thread stack change. (#163976)
When the user send `thread return <expr>` command this changes the stack
length but the UI does not update.
Send stack invalidated event to the client to update the stack.
Diffstat (limited to 'lldb/tools')
| -rw-r--r-- | lldb/tools/lldb-dap/DAP.cpp | 19 | ||||
| -rw-r--r-- | lldb/tools/lldb-dap/DAP.h | 1 | ||||
| -rw-r--r-- | lldb/tools/lldb-dap/EventHelper.cpp | 7 | ||||
| -rw-r--r-- | lldb/tools/lldb-dap/EventHelper.h | 5 | ||||
| -rw-r--r-- | lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp | 2 |
5 files changed, 31 insertions, 3 deletions
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index f76656e98ca0..61226cceb6db 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -1368,6 +1368,12 @@ void DAP::EventThread() { broadcaster.AddListener(listener, eBroadcastBitStopEventThread); debugger.GetBroadcaster().AddListener( listener, lldb::eBroadcastBitError | lldb::eBroadcastBitWarning); + + // listen for thread events. + listener.StartListeningForEventClass( + debugger, lldb::SBThread::GetBroadcasterClassName(), + lldb::SBThread::eBroadcastBitStackChanged); + bool done = false; while (!done) { if (listener.WaitForEvent(1, event)) { @@ -1503,6 +1509,9 @@ void DAP::EventThread() { SendJSON(llvm::json::Value(std::move(bp_event))); } } + + } else if (lldb::SBThread::EventIsThreadEvent(event)) { + HandleThreadEvent(event); } else if (event_mask & lldb::eBroadcastBitError || event_mask & lldb::eBroadcastBitWarning) { lldb::SBStructuredData data = @@ -1522,6 +1531,16 @@ void DAP::EventThread() { } } +void DAP::HandleThreadEvent(const lldb::SBEvent &event) { + uint32_t event_type = event.GetType(); + + if (event_type & lldb::SBThread::eBroadcastBitStackChanged) { + const lldb::SBThread evt_thread = lldb::SBThread::GetThreadFromEvent(event); + SendInvalidatedEvent(*this, {InvalidatedEventBody::eAreaStacks}, + evt_thread.GetThreadID()); + } +} + std::vector<protocol::Breakpoint> DAP::SetSourceBreakpoints( const protocol::Source &source, const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints) { diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index a90ddf59671e..bf2c3f146a39 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -460,6 +460,7 @@ private: /// Event threads. /// @{ void EventThread(); + void HandleThreadEvent(const lldb::SBEvent &event); void ProgressEventThread(); std::thread event_thread; diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index 2b9ed229405a..3042d3293b48 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -276,11 +276,16 @@ void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process) { } void SendInvalidatedEvent( - DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas) { + DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas, + lldb::tid_t tid) { if (!dap.clientFeatures.contains(protocol::eClientFeatureInvalidatedEvent)) return; protocol::InvalidatedEventBody body; body.areas = areas; + + if (tid != LLDB_INVALID_THREAD_ID) + body.threadId = tid; + dap.Send(protocol::Event{"invalidated", std::move(body)}); } diff --git a/lldb/tools/lldb-dap/EventHelper.h b/lldb/tools/lldb-dap/EventHelper.h index 48eb5af6bd0b..be783d032a5a 100644 --- a/lldb/tools/lldb-dap/EventHelper.h +++ b/lldb/tools/lldb-dap/EventHelper.h @@ -11,6 +11,8 @@ #include "DAPForward.h" #include "Protocol/ProtocolEvents.h" +#include "lldb/lldb-defines.h" +#include "lldb/lldb-types.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Error.h" @@ -35,7 +37,8 @@ void SendContinuedEvent(DAP &dap); void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process); void SendInvalidatedEvent( - DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas); + DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas, + lldb::tid_t tid = LLDB_INVALID_THREAD_ID); void SendMemoryEvent(DAP &dap, lldb::SBValue variable); diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp b/lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp index b896eca817be..df6be06637a1 100644 --- a/lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp +++ b/lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp @@ -51,7 +51,7 @@ llvm::json::Value toJSON(const InvalidatedEventBody::Area &IEBA) { llvm::json::Value toJSON(const InvalidatedEventBody &IEB) { json::Object Result{{"areas", IEB.areas}}; if (IEB.threadId) - Result.insert({"threadID", IEB.threadId}); + Result.insert({"threadId", IEB.threadId}); if (IEB.stackFrameId) Result.insert({"stackFrameId", IEB.stackFrameId}); return Result; |
