Fix breakpoint event

Few problems:
 - we were passing a dict instead of a list of breakpoints
 - if the breakpoint had a source which was {} we crashed
 - we didn't support the 'removed' event
This commit is contained in:
Ben Jackson 2020-10-10 15:32:50 +01:00
commit 16f22b396f
3 changed files with 72 additions and 12 deletions

View file

@ -166,25 +166,29 @@ class CodeView( object ):
def AddBreakpoints( self, source, breakpoints ): def AddBreakpoints( self, source, breakpoints ):
for breakpoint in breakpoints: for breakpoint in breakpoints:
if 'source' not in breakpoint: source = breakpoint.get( 'source' ) or source
if source: if not source or 'path' not in source:
breakpoint[ 'source' ] = source self._logger.warn( 'missing source/path in breakpoint {0}'.format(
else: json.dumps( breakpoint ) ) )
self._logger.warn( 'missing source in breakpoint {0}'.format( continue
json.dumps( breakpoint ) ) )
continue
self._breakpoints[ breakpoint[ 'source' ][ 'path' ] ].append( breakpoint[ 'source' ] = source
breakpoint ) self._breakpoints[ source[ 'path' ] ].append( breakpoint )
self._logger.debug( 'Breakpoints at this point: {0}'.format( self._logger.debug( 'Breakpoints at this point: {0}'.format(
json.dumps( self._breakpoints, indent = 2 ) ) ) json.dumps( self._breakpoints, indent = 2 ) ) )
self.ShowBreakpoints() self.ShowBreakpoints()
def AddBreakpoint( self, breakpoint ):
self.AddBreakpoints( None, [ breakpoint ] )
def UpdateBreakpoint( self, bp ): def UpdateBreakpoint( self, bp ):
if 'id' not in bp: if 'id' not in bp:
self.AddBreakpoints( None, [ bp ] ) self.AddBreakpoint( bp )
return
for _, breakpoint_list in self._breakpoints.items(): for _, breakpoint_list in self._breakpoints.items():
for index, breakpoint in enumerate( breakpoint_list ): for index, breakpoint in enumerate( breakpoint_list ):
@ -194,7 +198,22 @@ class CodeView( object ):
return return
# Not found. Assume new # Not found. Assume new
self.AddBreakpoints( None, [ bp ] ) self.AddBreakpoint( bp )
def RemoveBreakpoint( self, bp ):
for _, breakpoint_list in self._breakpoints.items():
found_index = None
for index, breakpoint in enumerate( breakpoint_list ):
if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]:
found_index = index
break
if found_index is not None:
del breakpoint_list[ found_index ]
self.ShowBreakpoints()
return
def _UndisplaySigns( self ): def _UndisplaySigns( self ):
for sign_id in self._signs[ 'breakpoints' ]: for sign_id in self._signs[ 'breakpoints' ]:

View file

@ -1050,7 +1050,9 @@ class DebugSession( object ):
if reason == 'changed': if reason == 'changed':
self._codeView.UpdateBreakpoint( bp ) self._codeView.UpdateBreakpoint( bp )
elif reason == 'new': elif reason == 'new':
self._codeView.AddBreakpoints( None, bp ) self._codeView.AddBreakpoint( bp )
elif reason == 'removed':
self._codeView.RemoveBreakpoint( bp )
else: else:
utils.UserMessage( utils.UserMessage(
'Unrecognised breakpoint event (undocumented): {0}'.format( reason ), 'Unrecognised breakpoint event (undocumented): {0}'.format( reason ),

View file

@ -68,6 +68,45 @@
"CALCULATED_STR", "${CALCULATED_STR}" "CALCULATED_STR", "${CALCULATED_STR}"
] ]
} }
},
"lldb-vscode": {
"adapter": "lldb-vscode",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
"cwd": "${workspaceRoot}",
"externalConsole": false,
"MIMode": "lldb"
}
},
"CodeLLDB": {
"adapter": "CodeLLDB",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
"cwd": "${workspaceRoot}",
"expressions": "native"
}
}
},
"adapters": {
"lldb-vscode": {
"variables": {
"LLVM": {
"shell": "brew --prefix llvm"
}
},
"attach": {
"pidProperty": "pid",
"pidSelect": "ask"
},
"command": [
"${LLVM}/bin/lldb-vscode"
],
"env": {
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY": "YES"
},
"name": "lldb"
} }
} }
} }