Allow setting exception breakpoints in debug config

This commit is contained in:
Ben Jackson 2019-11-05 18:33:41 +00:00
commit 5586d9e694
3 changed files with 44 additions and 6 deletions

View file

@ -44,6 +44,7 @@ class ProjectBreakpoints( object ):
self._line_breakpoints = defaultdict( list ) self._line_breakpoints = defaultdict( list )
self._func_breakpoints = [] self._func_breakpoints = []
self._exception_breakpoints = None self._exception_breakpoints = None
self._configured_breakpoints = {}
# FIXME: Remove this. Remove breakpoints nonesense from code.py # FIXME: Remove this. Remove breakpoints nonesense from code.py
self._breakpoints_handler = None self._breakpoints_handler = None
@ -73,6 +74,8 @@ class ProjectBreakpoints( object ):
# NOTE: we don't reset self._exception_breakpoints because we don't want to # NOTE: we don't reset self._exception_breakpoints because we don't want to
# re-ask the user every time for the sane info. # re-ask the user every time for the sane info.
# FIXME: If the adapter type changes, we should probably forget this ?
def ListBreakpoints( self ): def ListBreakpoints( self ):
# FIXME: Handling of breakpoints is a mess, split between _codeView and this # FIXME: Handling of breakpoints is a mess, split between _codeView and this
@ -185,6 +188,10 @@ class ProjectBreakpoints( object ):
self._breakpoints_handler = handler self._breakpoints_handler = handler
def SetConfiguredBreakpoints( self, configured_breakpoints ):
self._configured_breakpoints = configured_breakpoints
def SendBreakpoints( self, doneHandler = None ): def SendBreakpoints( self, doneHandler = None ):
assert self._breakpoints_handler is not None assert self._breakpoints_handler is not None
@ -202,6 +209,9 @@ class ProjectBreakpoints( object ):
doneHandler() doneHandler()
# TODO: add the _configured_breakpoints to line_breakpoints
# TODO: the line numbers might have changed since pressing the F9 key!
for file_name, line_breakpoints in self._line_breakpoints.items(): for file_name, line_breakpoints in self._line_breakpoints.items():
breakpoints = [] breakpoints = []
for bp in line_breakpoints: for bp in line_breakpoints:
@ -233,6 +243,8 @@ class ProjectBreakpoints( object ):
} }
) )
# TODO: Add the _configured_breakpoints to function breakpoints
if self._server_capabilities.get( 'supportsFunctionBreakpoints' ): if self._server_capabilities.get( 'supportsFunctionBreakpoints' ):
awaiting = awaiting + 1 awaiting = awaiting + 1
self._connection.DoRequest( self._connection.DoRequest(
@ -249,7 +261,7 @@ class ProjectBreakpoints( object ):
) )
if self._exception_breakpoints is None: if self._exception_breakpoints is None:
self._SetUpExceptionBreakpoints() self._SetUpExceptionBreakpoints( self._configured_breakpoints )
if self._exception_breakpoints: if self._exception_breakpoints:
awaiting = awaiting + 1 awaiting = awaiting + 1
@ -265,7 +277,7 @@ class ProjectBreakpoints( object ):
doneHandler() doneHandler()
def _SetUpExceptionBreakpoints( self ): def _SetUpExceptionBreakpoints( self, configured_breakpoints ):
exception_breakpoint_filters = self._server_capabilities.get( exception_breakpoint_filters = self._server_capabilities.get(
'exceptionBreakpointFilters', 'exceptionBreakpointFilters',
[] ) [] )
@ -278,12 +290,25 @@ class ProjectBreakpoints( object ):
# trigger requesting threads etc.). See the note in # trigger requesting threads etc.). See the note in
# debug_session.py:_Initialise for more detials # debug_session.py:_Initialise for more detials
exception_filters = [] exception_filters = []
configured_filter_options = configured_breakpoints.get( 'exception', {} )
if exception_breakpoint_filters: if exception_breakpoint_filters:
for f in exception_breakpoint_filters: for f in exception_breakpoint_filters:
default_value = 'Y' if f.get( 'default' ) else 'N' default_value = 'Y' if f.get( 'default' ) else 'N'
if f[ 'filter' ] in configured_filter_options:
result = configured_filter_options[ f[ 'filter' ] ]
if isinstance( result, bool ):
result = 'Y' if result else 'N'
if not isinstance( result, str) or result not in ( 'Y', 'N', '' ):
raise ValueError(
f"Invalid value for exception breakpoint filter '{f}': "
f"'{result}'. Must be boolean, 'Y', 'N' or '' (default)" )
else:
result = utils.AskForInput( result = utils.AskForInput(
"Break on {} (Y/N/default: {})? ".format( f[ 'label' ], "{}: Break on {} (Y/N/default: {})? ".format( f[ 'filter' ],
f[ 'label' ],
default_value ), default_value ),
default_value ) default_value )

View file

@ -739,6 +739,8 @@ class DebugSession( object ):
self._OnInitializeComplete() self._OnInitializeComplete()
self._codeView.ClearBreakpoints() self._codeView.ClearBreakpoints()
self._breakpoints.SetConfiguredBreakpoints(
self._configuration.get( 'breakpoints', {} ) )
self._breakpoints.SendBreakpoints( onBreakpointsDone ) self._breakpoints.SendBreakpoints( onBreakpointsDone )
def OnEvent_thread( self, message ): def OnEvent_thread( self, message ):

View file

@ -11,7 +11,18 @@
"environment": [], "environment": [],
"externalConsole": true, "externalConsole": true,
"stopAtEntry": true, "stopAtEntry": true,
"stopOnEntry": true,
"MImode": "${VIMSPECTOR_MIMODE}" "MImode": "${VIMSPECTOR_MIMODE}"
},
"breakpoints": {
"exception": {
"cpp_catch": "",
"cpp_throw": "",
"objc_catch": "",
"objc_throw": "",
"swift_catch": "",
"swift_throw": ""
}
} }
} }
} }