Skip to content

Commit c20a058

Browse files
committed
[lldb-dap] Send an Invalidated event on thread stack change.
When the user send `thread return <expr>` command this changes the stack length. but the UI does not update. Send stack invalidated event to update the stack
1 parent 8e054f8 commit c20a058

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,12 @@ void DAP::EventThread() {
13681368
broadcaster.AddListener(listener, eBroadcastBitStopEventThread);
13691369
debugger.GetBroadcaster().AddListener(
13701370
listener, lldb::eBroadcastBitError | lldb::eBroadcastBitWarning);
1371+
1372+
// listen for thread events.
1373+
listener.StartListeningForEventClass(
1374+
debugger, lldb::SBThread::GetBroadcasterClassName(),
1375+
lldb::SBThread::eBroadcastBitStackChanged);
1376+
13711377
bool done = false;
13721378
while (!done) {
13731379
if (listener.WaitForEvent(1, event)) {
@@ -1503,6 +1509,9 @@ void DAP::EventThread() {
15031509
SendJSON(llvm::json::Value(std::move(bp_event)));
15041510
}
15051511
}
1512+
1513+
} else if (lldb::SBThread::EventIsThreadEvent(event)) {
1514+
HandleThreadEvent(event);
15061515
} else if (event_mask & lldb::eBroadcastBitError ||
15071516
event_mask & lldb::eBroadcastBitWarning) {
15081517
lldb::SBStructuredData data =
@@ -1522,6 +1531,16 @@ void DAP::EventThread() {
15221531
}
15231532
}
15241533

1534+
void DAP::HandleThreadEvent(const lldb::SBEvent &event) {
1535+
uint32_t event_type = event.GetType();
1536+
1537+
if (event_type & lldb::SBThread::eBroadcastBitStackChanged) {
1538+
const lldb::SBThread evt_thread = lldb::SBThread::GetThreadFromEvent(event);
1539+
SendInvalidatedEvent(*this, {InvalidatedEventBody::eAreaStacks},
1540+
evt_thread.GetThreadID());
1541+
}
1542+
}
1543+
15251544
std::vector<protocol::Breakpoint> DAP::SetSourceBreakpoints(
15261545
const protocol::Source &source,
15271546
const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints) {

lldb/tools/lldb-dap/DAP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ struct DAP final : public DAPTransport::MessageHandler {
460460
/// Event threads.
461461
/// @{
462462
void EventThread();
463+
void HandleThreadEvent(const lldb::SBEvent &event);
463464
void ProgressEventThread();
464465

465466
std::thread event_thread;

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Protocol/ProtocolRequests.h"
1616
#include "Protocol/ProtocolTypes.h"
1717
#include "lldb/API/SBFileSpec.h"
18+
#include "lldb/lldb-defines.h"
1819
#include "llvm/Support/Error.h"
1920
#include <utility>
2021

@@ -276,11 +277,16 @@ void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process) {
276277
}
277278

278279
void SendInvalidatedEvent(
279-
DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas) {
280+
DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas,
281+
lldb::tid_t tid) {
280282
if (!dap.clientFeatures.contains(protocol::eClientFeatureInvalidatedEvent))
281283
return;
282284
protocol::InvalidatedEventBody body;
283285
body.areas = areas;
286+
287+
if (tid != LLDB_INVALID_THREAD_ID)
288+
body.threadId = tid;
289+
284290
dap.Send(protocol::Event{"invalidated", std::move(body)});
285291
}
286292

lldb/tools/lldb-dap/EventHelper.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "DAPForward.h"
1313
#include "Protocol/ProtocolEvents.h"
14+
#include "lldb/lldb-defines.h"
15+
#include "lldb/lldb-types.h"
1416
#include "llvm/ADT/ArrayRef.h"
1517
#include "llvm/Support/Error.h"
1618

@@ -35,7 +37,8 @@ void SendContinuedEvent(DAP &dap);
3537
void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process);
3638

3739
void SendInvalidatedEvent(
38-
DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas);
40+
DAP &dap, llvm::ArrayRef<protocol::InvalidatedEventBody::Area> areas,
41+
lldb::tid_t tid = LLDB_INVALID_THREAD_ID);
3942

4043
void SendMemoryEvent(DAP &dap, lldb::SBValue variable);
4144

lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ llvm::json::Value toJSON(const InvalidatedEventBody::Area &IEBA) {
5151
llvm::json::Value toJSON(const InvalidatedEventBody &IEB) {
5252
json::Object Result{{"areas", IEB.areas}};
5353
if (IEB.threadId)
54-
Result.insert({"threadID", IEB.threadId});
54+
Result.insert({"threadId", IEB.threadId});
5555
if (IEB.stackFrameId)
5656
Result.insert({"stackFrameId", IEB.stackFrameId});
5757
return Result;

0 commit comments

Comments
 (0)