From eeabd00b4a3abda1fe92cf868a68f576f6a7fd6b Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 26 May 2018 22:03:39 +0100 Subject: [PATCH] Handle debug and terminated events Somewhat at least. --- python3/vimspector/code.py | 26 +++++++- .../vimspector/debug_adapter_connection.py | 3 + python3/vimspector/debug_session.py | 61 +++++++++++++++---- python3/vimspector/stack_trace.py | 4 ++ python3/vimspector/variables.py | 4 ++ 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 39a8309..d4d6e20 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -81,7 +81,6 @@ class CodeView( object ): vim.command( 'sign unplace {0}'.format( self._signs[ 'vimspectorPC' ] ) ) self._signs[ 'vimspectorPC' ] = None - # TODO: You know what, move breakpoint handling out of here into its own # thing. It really doesn't directly relate to the code view. def AddBreakpoints( self, source, breakpoints ): @@ -100,6 +99,31 @@ class CodeView( object ): self._logger.debug( 'Breakpoints at this point: {0}'.format( json.dumps( self._breakpoints, indent = 2 ) ) ) + def UpdateBreakpoint( self, bp ): + if 'id' not in bp: + self.AddBreakpoints( None, [ bp ] ) + + for _, breakpoint_list in self._breakpoints.items(): + for index, breakpoint in enumerate( breakpoint_list ): + if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]: + breakpoint_list[ index ] = bp + return + + # Not found. Assume new + self.AddBreakpoints( None, [ bp ] ) + + def DeleteBreakpoint( self, bp ): + if 'id' not in bp: + return + + for _, breakpoint_list in self._breakpoints.items(): + for index, breakpoint in enumerate( breakpoint_list ): + if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]: + del breakpoint_list[ index ] + return + + # Not found. Shrug. + def _UndisplaySigns( self ): for sign_id in self._signs[ 'breakpoints' ]: vim.command( 'sign unplace {0}'.format( sign_id ) ) diff --git a/python3/vimspector/debug_adapter_connection.py b/python3/vimspector/debug_adapter_connection.py index a09fc9f..75793d2 100644 --- a/python3/vimspector/debug_adapter_connection.py +++ b/python3/vimspector/debug_adapter_connection.py @@ -126,3 +126,6 @@ class DebugAdapterConnection( object ): method = 'OnEvent_' + message[ 'event' ] if method in dir( self._handler ): getattr( self._handler, method )( message ) + else: + utils.UserMessage( 'Unhandled event: {0}'.format( message[ 'event' ] ), + persist = True ) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 4ec2d3f..271fb6f 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -242,6 +242,45 @@ class DebugSession( object ): self._SendBreakpoints() + def OnEvent_thread( self, message ): + # TODO: set self_currentThread ? Not really that useful I guess as the + # stopped event basically gives us this. + pass + + def OnEvent_breakpoint( self, message ): + # Useful: + # + # /** The reason for the event. + # Values: 'changed', 'new', 'removed', etc. + # */ + + reason = message[ 'body' ][ 'reason' ] + bp = message[ 'body' ][ 'breakpoint' ] + if reason == 'changed': + self._codeView.UpdateBreakpoint( bp ) + elif reason == 'new': + self._codeView.AddBreakpoints( None, bp ) + elif reason == 'removed': + # TODO + pass + else: + utils.UserMessage( + 'Unrecognised breakpoint event (undocumented): {0}'.format( reason ), + persist = True ) + + + def OnEvent_terminated( self, message ): + utils.UserMessage( "The program was terminated because: {0}".format( + message.get( 'body', {} ).get( 'reason', "No specific reason" ) ) ) + + self._codeView.Clear() + self._stackTraceView.Clear() + self._variablesView.Clear() + + with utils.ModifiableScratchBuffer( self._threadsBuffer ): + self._threadsBuffer[:] = None + + def _SendBreakpoints( self ): for file_name, line_breakpoints in self._breakpoints.items(): breakpoints = [] @@ -276,17 +315,17 @@ class DebugSession( object ): ) # TODO: Remove this! - self._connection.DoRequest( - functools.partial( self._UpdateBreakpoints, None ), - { - 'command': 'setFunctionBreakpoints', - 'arguments': { - 'breakpoints': [ - { 'name': 'main' }, - ], - }, - } - ) + # self._connection.DoRequest( + # functools.partial( self._UpdateBreakpoints, None ), + # { + # 'command': 'setFunctionBreakpoints', + # 'arguments': { + # 'breakpoints': [ + # { 'name': 'main' }, + # ], + # }, + # } + # ) self._connection.DoRequest( None, { 'command': 'configurationDone', diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index 4b010f4..6d67fe3 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -30,6 +30,10 @@ class StackTraceView( object ): self._line_to_frame = {} + def Clear( self ): + with utils.ModifiableScratchBuffer( self._buf ): + self._buf[:] = None + def LoadStackTrace( self, thread_id ): self._connection.DoRequest( self._PrintStackTrace, { 'command': 'stackTrace', diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 1d26b8f..831e0ab 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -39,6 +39,10 @@ class VariablesView( object ): utils.SetUpScratchBuffer( self._buf ) + def Clear( self ): + with utils.ModifiableScratchBuffer( self._buf ): + self._buf[:] = None + def LoadScopes( self, frame ): def scopes_consumer( message ): self._scopes = []