Handle debug and terminated events

Somewhat at least.
This commit is contained in:
Ben Jackson 2018-05-26 22:03:39 +01:00
commit eeabd00b4a
5 changed files with 86 additions and 12 deletions

View file

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

View file

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

View file

@ -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',

View file

@ -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',

View file

@ -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 = []