From d53d72e2841cd7e2c007751415679f9ff8a73062 Mon Sep 17 00:00:00 2001 From: brendandouglas Date: Fri, 8 Jun 2018 16:00:09 -0700 Subject: Skylark debugging protocol: include frames information in ThreadPausedEvents. This is almost always desirable -- if a thread is paused, the IDE expects to know the context. PiperOrigin-RevId: 199865078 --- .../build/lib/skylarkdebug/proto/skylark_debugging.proto | 5 +++++ .../build/lib/skylarkdebug/server/DebugEventHelper.java | 4 ++-- .../devtools/build/lib/skylarkdebug/server/ThreadHandler.java | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/google/devtools/build') diff --git a/src/main/java/com/google/devtools/build/lib/skylarkdebug/proto/skylark_debugging.proto b/src/main/java/com/google/devtools/build/lib/skylarkdebug/proto/skylark_debugging.proto index ed398e70fa..649f2936e2 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkdebug/proto/skylark_debugging.proto +++ b/src/main/java/com/google/devtools/build/lib/skylarkdebug/proto/skylark_debugging.proto @@ -184,6 +184,11 @@ message ThreadEndedEvent { message ThreadPausedEvent { // The thread that was paused. Thread thread = 1; + + // The list of stack frames for the paused thread. The first element in the + // list represents the topmost frame (that is, the current innermost + // function). + repeated Frame frame = 2; } // An event indicating that a thread has continued execution after being paused. diff --git a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebugEventHelper.java b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebugEventHelper.java index 0254484062..aa2279f97d 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebugEventHelper.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebugEventHelper.java @@ -130,9 +130,9 @@ final class DebugEventHelper { .build(); } - static DebugEvent threadPausedEvent(Thread thread) { + static DebugEvent threadPausedEvent(Thread thread, Collection frames) { return DebugEvent.newBuilder() - .setThreadPaused(ThreadPausedEvent.newBuilder().setThread(thread)) + .setThreadPaused(ThreadPausedEvent.newBuilder().setThread(thread).addAllFrame(frames)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/ThreadHandler.java b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/ThreadHandler.java index fd30c64e01..e1f74f9dd6 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/ThreadHandler.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/ThreadHandler.java @@ -225,6 +225,11 @@ final class ThreadHandler { } // no need to list frames within the synchronize block: threads can only be resumed in response // to a client request, and requests are handled serially + return listFrames(debuggable, pausedState); + } + + private static ImmutableList listFrames( + Debuggable debuggable, PausedThreadState pausedState) { return debuggable .listFrames(pausedState.location) .stream() @@ -265,6 +270,7 @@ final class ThreadHandler { SkylarkDebuggingProtos.Thread threadProto; PausedThreadState pausedState; + Debuggable debuggable; synchronized (threads) { ThreadState thread = threads.get(threadId); if (thread == null) { @@ -276,13 +282,15 @@ final class ThreadHandler { transport.postEvent(DebugEventHelper.threadStartedEvent(threadId, fallbackThreadName)); thread = doRegisterThread(threadId, fallbackThreadName, env); } + debuggable = thread.debuggable; pausedState = new PausedThreadState(location); thread.pausedState = pausedState; // get proto after setting the paused state, so that it's up to date threadProto = getThreadProto(thread); } - transport.postEvent(DebugEventHelper.threadPausedEvent(threadProto)); + transport.postEvent( + DebugEventHelper.threadPausedEvent(threadProto, listFrames(debuggable, pausedState))); pausedState.semaphore.acquireUninterruptibly(); transport.postEvent( DebugEventHelper.threadContinuedEvent( -- cgit v1.2.3