From 8801c2dac4b97a2b5100d4d222a095b4c64b3daf Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 21 Nov 2020 17:41:20 +0000 Subject: [PATCH] Fix pause/continue of individual threads work around buggy java server sending invalid threads response. java server supports this separate threads running/paused as a test case. --- python3/vimspector/debug_session.py | 40 ++++++++++++++++++----------- python3/vimspector/stack_trace.py | 19 ++++++++------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 67ec6a1..c6a1f72 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -434,49 +434,59 @@ class DebugSession( object ): @IfConnected() def StepInto( self ): - if self._stackTraceView.GetCurrentThreadId() is None: + threadId = self._stackTraceView.GetCurrentThreadId() + if threadId is None: return - self._connection.DoRequest( None, { + def handler( *_ ): + self._stackTraceView.OnContinued( { 'threadId': threadId } ) + self._codeView.SetCurrentFrame( None ) + + self._connection.DoRequest( handler, { 'command': 'stepIn', 'arguments': { - 'threadId': self._stackTraceView.GetCurrentThreadId() + 'threadId': threadId }, } ) - self._stackTraceView.OnContinued() - self._codeView.SetCurrentFrame( None ) @IfConnected() def StepOut( self ): - if self._stackTraceView.GetCurrentThreadId() is None: + threadId = self._stackTraceView.GetCurrentThreadId() + if threadId is None: return - self._connection.DoRequest( None, { + def handler( *_ ): + self._stackTraceView.OnContinued( { 'threadId': threadId } ) + self._codeView.SetCurrentFrame( None ) + + self._connection.DoRequest( handler, { 'command': 'stepOut', 'arguments': { - 'threadId': self._stackTraceView.GetCurrentThreadId() + 'threadId': threadId }, } ) - self._stackTraceView.OnContinued() - self._codeView.SetCurrentFrame( None ) + def Continue( self ): if not self._connection: self.Start() return - if self._stackTraceView.GetCurrentThreadId() is None: + threadId = self._stackTraceView.GetCurrentThreadId() + if threadId is None: utils.UserMessage( 'No current thread', persist = True ) return - self._connection.DoRequest( None, { + def handler( *_ ): + self._stackTraceView.OnContinued( { 'threadId': threadId } ) + self._codeView.SetCurrentFrame( None ) + + self._connection.DoRequest( handler, { 'command': 'continue', 'arguments': { - 'threadId': self._stackTraceView.GetCurrentThreadId(), + 'threadId': threadId, }, } ) - self._stackTraceView.OnContinued() - self._codeView.SetCurrentFrame( None ) @IfConnected() def Pause( self ): diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index dd2662c..a0b4734 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -49,6 +49,7 @@ class Thread: def Continued( self ): self.state = Thread.RUNNING self.stopped_event = None + self.Collapse() def Exited( self ): self.state = Thread.TERMINATED @@ -56,7 +57,7 @@ class Thread: def State( self ): if self.state == Thread.PAUSED: - return self.stopped_event.get( 'description', 'paused' ) + return self.stopped_event.get( 'description' ) or 'paused' elif self.state == Thread.RUNNING: return 'running' return 'terminated' @@ -191,7 +192,7 @@ class StackTraceView( object ): self.LoadThreads( *self._pending_thread_request ) return - if not message[ 'body' ][ 'threads' ]: + if not ( message.get( 'body' ) or {} ).get( 'threads' ): # This is a protocol error. It is required to return at least one! utils.UserMessage( 'Protocol error: Server returned no threads', persist = False, @@ -372,12 +373,14 @@ class StackTraceView( object ): if thread is None: utils.UserMessage( 'No thread selected' ) elif thread.state == Thread.PAUSED: - self._session._connection.DoRequest( None, { - 'command': 'continue', - 'arguments': { - 'threadId': thread.id, - }, - } ) + self._session._connection.DoRequest( + lambda *_: self.OnContinued( { 'threadId': thread.id } ), + { + 'command': 'continue', + 'arguments': { + 'threadId': thread.id, + }, + } ) elif thread.state == Thread.RUNNING: self._session._connection.DoRequest( None, { 'command': 'pause',