Skip to content

Commit

Permalink
Fix clear and toggle for data breakpoints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
puremourning committed Dec 12, 2024
1 parent 61867d4 commit d472636
Showing 1 changed file with 51 additions and 19 deletions.
70 changes: 51 additions & 19 deletions python3/vimspector/breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,13 @@ def ToggleBreakpointViewBreakpoint( self ):
return


# FIXME: what about instruction breakpoints
if bp.get( 'type' ) == 'F':
# FIXME: We don't really handle 'DISABLED' state for function breakpoints,
# so they are just deleted
self.ClearFunctionBreakpoint( bp.get( 'filename' ) )

# FIXME: what about data breakpoints
# FIXME: what about exception breakpoints
# FIXME: what about instruction breakpoints
elif bp.get( 'type' ) == 'D':
self.ToggleDataBreakpoint( bp[ 'session_id' ], bp[ 'data_id' ] )
else:
# This should find the breakpoint by the "current" line in lnum. If not,
# pass an empty options just in case we end up in "ADD" codepath.
Expand Down Expand Up @@ -361,6 +360,9 @@ def EditBreakpointOptionsViewBreakpoint( self ):
if not vbp:
return

if vbp.get( 'type' ) != 'L':
return

# Try to find the actual breakpoint
bp, index = self._FindLineBreakpoint( vbp.get( 'filename' ),
vbp.get( 'lnum' ) )
Expand Down Expand Up @@ -402,8 +404,11 @@ def ClearBreakpointViewBreakpoint( self ):
if not bp:
return

# FIXME: what about instruction breakpoints
if bp.get( 'type' ) == 'F':
self.ClearFunctionBreakpoint( bp.get( 'filename' ) )
elif bp.get( 'type' ) == 'D':
self.ClearDataBreakpoint( bp[ 'session_id' ], bp[ 'data_id' ] )
else:
self.ClearLineBreakpoint( bp.get( 'filename' ), bp.get( 'lnum' ) )

Expand Down Expand Up @@ -498,6 +503,8 @@ def BreakpointsAsQuickFix( self ):

qf.append( {
'filename': bp[ 'info' ][ 'description' ],
'data_id': bp[ 'info' ][ 'dataId' ],
'session_id': bp[ 'conn' ],
'lnum': 1,
'col': 1,
'type': 'D',
Expand Down Expand Up @@ -886,6 +893,29 @@ def AddDataBreakpoint( self,
self.UpdateUI()


def ToggleDataBreakpoint( self, session_id, data_id ):
for dbp in self._data_breakponts:
if dbp[ 'conn' ] != session_id:
continue
if dbp[ 'info' ][ 'dataId' ] != data_id:
continue

if dbp[ 'state' ] == 'ENABLED':
dbp[ 'state' ] = 'DISABLED'
else:
dbp[ 'state' ] = 'ENABLED'
self.UpdateUI()
return


def ClearDataBreakpoint( self, session_id, data_id ):
self._data_breakponts = [
item for item in self._data_breakponts
if item[ 'conn' ] != session_id or item[ 'info' ][ 'dataId' ] != data_id
]
self.UpdateUI()


def ClearUI( self ):
self._HideBreakpoints()
self._breakpoints_view.CloseBreakpoints()
Expand Down Expand Up @@ -1096,33 +1126,35 @@ def response_handler( conn, msg, bp_idxs = [] ):
breakpoints = []
bp_idxs = []
for bp in self._data_breakponts:
if bp[ 'state' ] != 'ENABLED':
continue
if bp[ 'conn' ] != connection.GetSessionId():
continue
if not bp[ 'info' ].get( 'dataId' ):
continue

bp.pop( 'server_bp', None )

if bp[ 'state' ] != 'ENABLED':
continue

data_bp = {}
data_bp.update( bp[ 'options' ] )
data_bp[ 'dataId' ] = bp[ 'info' ][ 'dataId' ]
bp_idxs.append( ( len( breakpoints ), bp ) )
breakpoints.append( data_bp )

if breakpoints:
self._awaiting_bp_responses += 1
connection.DoRequest(
lambda msg, conn=connection: response_handler( conn,
msg,
bp_idxs ),
{
'command': 'setDataBreakpoints',
'arguments': {
'breakpoints': breakpoints,
},
self._awaiting_bp_responses += 1
connection.DoRequest(
lambda msg, conn=connection: response_handler( conn,
msg,
bp_idxs ),
{
'command': 'setDataBreakpoints',
'arguments': {
'breakpoints': breakpoints,
},
failure_handler = response_received
)
},
failure_handler = response_received
)

if self._exception_breakpoints:
for connection in self._connections:
Expand Down

0 comments on commit d472636

Please sign in to comment.