From d52eb3a6e9cd1daa208f1616d1fea3ca4eee70b0 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 8 Jan 2021 11:30:17 +0000 Subject: [PATCH] Fix thread state and PC for starting node app The problem is the sequence of events sent by the debug adapter. Vimspector requests threads: * When the initialisation exchange completes (requests all threads) * Whenever a thread event is received * whenever a stopped event is received. If any of those happens while any other request is in progress, we cache the request and handle it later. The latest request is processed when the response to the outstanding request is received. The problem is if the event is a stopped event, it is the handling of the threads request that actually sets the thread state internally to stopped. In a sequence where the first event is a stopped event, we end up discarding the stopped event. like: 1. Stopped event (thread 1 = stopped) (request threads) 2. Initialisation complete (cache request) 3. threads response received (discard response and process cached request) 4. response received (but forgotten about the stopped event). The solution is to always process the thread response, even if we send the cached request. To avoid flicker, we don't draw the screen, or expand any threads/stacks in the case where we're sending a cached request. --- python3/vimspector/stack_trace.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index df650b9..f38e4ba 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -188,11 +188,12 @@ class StackTraceView( object ): return def consume_threads( message ): + requesting = False if self._requesting_threads == StackTraceView.ThreadRequestState.PENDING: # We may have hit a thread event, so try again. self._requesting_threads = StackTraceView.ThreadRequestState.NO self.LoadThreads( *self._pending_thread_request ) - return + requesting = True self._requesting_threads = StackTraceView.ThreadRequestState.NO self._pending_thread_request = None @@ -211,8 +212,6 @@ class StackTraceView( object ): stoppedThreadId = stopEvent.get( 'threadId' ) allThreadsStopped = stopEvent.get( 'allThreadsStopped', False ) - requesting = False - # FIXME: This is horribly inefficient for t in message[ 'body' ][ 'threads' ]: thread = None @@ -240,7 +239,10 @@ class StackTraceView( object ): # If this is a stopped event, load the stack trace for the "current" # thread. Don't do this on other thrads requests because some servers # just break when that happens. - if infer_current_frame: + # + # Don't do this if we're also satisfying a cached request already (we'll + # do it then) + if infer_current_frame and not requesting: if thread.id == self._current_thread: if thread.CanExpand(): self._LoadStackTrace( thread, True, reason )