Skip to content

Commit d472636

Browse files
committed
Fix clear and toggle for data breakpoints
Store the connection ID and data ID in the "qf" hack, then handle these commands trivially. Fix a bug where we never cleared out data breakpoints if there were none.
1 parent 61867d4 commit d472636

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

python3/vimspector/breakpoints.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,13 @@ def ToggleBreakpointViewBreakpoint( self ):
302302
return
303303

304304

305+
# FIXME: what about instruction breakpoints
305306
if bp.get( 'type' ) == 'F':
306307
# FIXME: We don't really handle 'DISABLED' state for function breakpoints,
307308
# so they are just deleted
308309
self.ClearFunctionBreakpoint( bp.get( 'filename' ) )
309-
310-
# FIXME: what about data breakpoints
311-
# FIXME: what about exception breakpoints
312-
# FIXME: what about instruction breakpoints
310+
elif bp.get( 'type' ) == 'D':
311+
self.ToggleDataBreakpoint( bp[ 'session_id' ], bp[ 'data_id' ] )
313312
else:
314313
# This should find the breakpoint by the "current" line in lnum. If not,
315314
# pass an empty options just in case we end up in "ADD" codepath.
@@ -361,6 +360,9 @@ def EditBreakpointOptionsViewBreakpoint( self ):
361360
if not vbp:
362361
return
363362

363+
if vbp.get( 'type' ) != 'L':
364+
return
365+
364366
# Try to find the actual breakpoint
365367
bp, index = self._FindLineBreakpoint( vbp.get( 'filename' ),
366368
vbp.get( 'lnum' ) )
@@ -402,8 +404,11 @@ def ClearBreakpointViewBreakpoint( self ):
402404
if not bp:
403405
return
404406

407+
# FIXME: what about instruction breakpoints
405408
if bp.get( 'type' ) == 'F':
406409
self.ClearFunctionBreakpoint( bp.get( 'filename' ) )
410+
elif bp.get( 'type' ) == 'D':
411+
self.ClearDataBreakpoint( bp[ 'session_id' ], bp[ 'data_id' ] )
407412
else:
408413
self.ClearLineBreakpoint( bp.get( 'filename' ), bp.get( 'lnum' ) )
409414

@@ -498,6 +503,8 @@ def BreakpointsAsQuickFix( self ):
498503

499504
qf.append( {
500505
'filename': bp[ 'info' ][ 'description' ],
506+
'data_id': bp[ 'info' ][ 'dataId' ],
507+
'session_id': bp[ 'conn' ],
501508
'lnum': 1,
502509
'col': 1,
503510
'type': 'D',
@@ -886,6 +893,29 @@ def AddDataBreakpoint( self,
886893
self.UpdateUI()
887894

888895

896+
def ToggleDataBreakpoint( self, session_id, data_id ):
897+
for dbp in self._data_breakponts:
898+
if dbp[ 'conn' ] != session_id:
899+
continue
900+
if dbp[ 'info' ][ 'dataId' ] != data_id:
901+
continue
902+
903+
if dbp[ 'state' ] == 'ENABLED':
904+
dbp[ 'state' ] = 'DISABLED'
905+
else:
906+
dbp[ 'state' ] = 'ENABLED'
907+
self.UpdateUI()
908+
return
909+
910+
911+
def ClearDataBreakpoint( self, session_id, data_id ):
912+
self._data_breakponts = [
913+
item for item in self._data_breakponts
914+
if item[ 'conn' ] != session_id or item[ 'info' ][ 'dataId' ] != data_id
915+
]
916+
self.UpdateUI()
917+
918+
889919
def ClearUI( self ):
890920
self._HideBreakpoints()
891921
self._breakpoints_view.CloseBreakpoints()
@@ -1096,33 +1126,35 @@ def response_handler( conn, msg, bp_idxs = [] ):
10961126
breakpoints = []
10971127
bp_idxs = []
10981128
for bp in self._data_breakponts:
1099-
if bp[ 'state' ] != 'ENABLED':
1100-
continue
11011129
if bp[ 'conn' ] != connection.GetSessionId():
11021130
continue
11031131
if not bp[ 'info' ].get( 'dataId' ):
11041132
continue
11051133

1134+
bp.pop( 'server_bp', None )
1135+
1136+
if bp[ 'state' ] != 'ENABLED':
1137+
continue
1138+
11061139
data_bp = {}
11071140
data_bp.update( bp[ 'options' ] )
11081141
data_bp[ 'dataId' ] = bp[ 'info' ][ 'dataId' ]
11091142
bp_idxs.append( ( len( breakpoints ), bp ) )
11101143
breakpoints.append( data_bp )
11111144

1112-
if breakpoints:
1113-
self._awaiting_bp_responses += 1
1114-
connection.DoRequest(
1115-
lambda msg, conn=connection: response_handler( conn,
1116-
msg,
1117-
bp_idxs ),
1118-
{
1119-
'command': 'setDataBreakpoints',
1120-
'arguments': {
1121-
'breakpoints': breakpoints,
1122-
},
1145+
self._awaiting_bp_responses += 1
1146+
connection.DoRequest(
1147+
lambda msg, conn=connection: response_handler( conn,
1148+
msg,
1149+
bp_idxs ),
1150+
{
1151+
'command': 'setDataBreakpoints',
1152+
'arguments': {
1153+
'breakpoints': breakpoints,
11231154
},
1124-
failure_handler = response_received
1125-
)
1155+
},
1156+
failure_handler = response_received
1157+
)
11261158

11271159
if self._exception_breakpoints:
11281160
for connection in self._connections:

0 commit comments

Comments
 (0)