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.
This commit is contained in:
Ben Jackson 2021-01-08 11:30:17 +00:00
commit d52eb3a6e9

View file

@ -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 )