From 5586d9e6947594cdb00528f496fe42dfbac388ff Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 5 Nov 2019 18:33:41 +0000 Subject: [PATCH] Allow setting exception breakpoints in debug config --- python3/vimspector/breakpoints.py | 37 ++++++++++++++++++---- python3/vimspector/debug_session.py | 2 ++ tests/testdata/cpp/simple/.vimspector.json | 11 +++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index e511b09..a24d1de 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -44,6 +44,7 @@ class ProjectBreakpoints( object ): self._line_breakpoints = defaultdict( list ) self._func_breakpoints = [] self._exception_breakpoints = None + self._configured_breakpoints = {} # FIXME: Remove this. Remove breakpoints nonesense from code.py 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 # re-ask the user every time for the sane info. + # FIXME: If the adapter type changes, we should probably forget this ? + def ListBreakpoints( self ): # FIXME: Handling of breakpoints is a mess, split between _codeView and this @@ -185,6 +188,10 @@ class ProjectBreakpoints( object ): self._breakpoints_handler = handler + def SetConfiguredBreakpoints( self, configured_breakpoints ): + self._configured_breakpoints = configured_breakpoints + + def SendBreakpoints( self, doneHandler = None ): assert self._breakpoints_handler is not None @@ -202,6 +209,9 @@ class ProjectBreakpoints( object ): 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(): 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' ): awaiting = awaiting + 1 self._connection.DoRequest( @@ -249,7 +261,7 @@ class ProjectBreakpoints( object ): ) if self._exception_breakpoints is None: - self._SetUpExceptionBreakpoints() + self._SetUpExceptionBreakpoints( self._configured_breakpoints ) if self._exception_breakpoints: awaiting = awaiting + 1 @@ -265,7 +277,7 @@ class ProjectBreakpoints( object ): doneHandler() - def _SetUpExceptionBreakpoints( self ): + def _SetUpExceptionBreakpoints( self, configured_breakpoints ): exception_breakpoint_filters = self._server_capabilities.get( 'exceptionBreakpointFilters', [] ) @@ -278,14 +290,27 @@ class ProjectBreakpoints( object ): # trigger requesting threads etc.). See the note in # debug_session.py:_Initialise for more detials exception_filters = [] + configured_filter_options = configured_breakpoints.get( 'exception', {} ) if exception_breakpoint_filters: for f in exception_breakpoint_filters: default_value = 'Y' if f.get( 'default' ) else 'N' - result = utils.AskForInput( - "Break on {} (Y/N/default: {})? ".format( f[ 'label' ], - default_value ), - default_value ) + 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( + "{}: Break on {} (Y/N/default: {})? ".format( f[ 'filter' ], + f[ 'label' ], + default_value ), + default_value ) if result == 'Y': exception_filters.append( f[ 'filter' ] ) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index a4a154d..25b1d5b 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -739,6 +739,8 @@ class DebugSession( object ): self._OnInitializeComplete() self._codeView.ClearBreakpoints() + self._breakpoints.SetConfiguredBreakpoints( + self._configuration.get( 'breakpoints', {} ) ) self._breakpoints.SendBreakpoints( onBreakpointsDone ) def OnEvent_thread( self, message ): diff --git a/tests/testdata/cpp/simple/.vimspector.json b/tests/testdata/cpp/simple/.vimspector.json index 9fa71d2..d7a4377 100644 --- a/tests/testdata/cpp/simple/.vimspector.json +++ b/tests/testdata/cpp/simple/.vimspector.json @@ -11,7 +11,18 @@ "environment": [], "externalConsole": true, "stopAtEntry": true, + "stopOnEntry": true, "MImode": "${VIMSPECTOR_MIMODE}" + }, + "breakpoints": { + "exception": { + "cpp_catch": "", + "cpp_throw": "", + "objc_catch": "", + "objc_throw": "", + "swift_catch": "", + "swift_throw": "" + } } } }