From 7a8f479f66a0ecadb9538949bd9eae053cf1055b Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 3 Apr 2021 19:55:19 +0100 Subject: [PATCH 1/4] Reset when closing the tab You can now kill vimspector sesssion by closing the vimspector session tab, rather than this causing an ugly backtrace --- python3/vimspector/debug_session.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 2f132f9..97257b8 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -405,27 +405,26 @@ class DebugSession( object ): def _Reset( self ): self._logger.info( "Debugging complete." ) - if self._uiTab: + if self._HasUI(): self._logger.debug( "Clearing down UI" ) - - del vim.vars[ 'vimspector_session_windows' ] vim.current.tabpage = self._uiTab - self._splash_screen = utils.HideSplash( self._api_prefix, self._splash_screen ) - self._stackTraceView.Reset() self._variablesView.Reset() self._outputView.Reset() self._codeView.Reset() + vim.command( 'au! VimspectorReset TabClose ' ) vim.command( 'tabclose!' ) - vim.command( 'doautocmd User VimspectorDebugEnded' ) - self._stackTraceView = None - self._variablesView = None - self._outputView = None - self._codeView = None - self._remote_term = None - self._uiTab = None + + del vim.vars[ 'vimspector_session_windows' ] + vim.command( 'doautocmd User VimspectorDebugEnded' ) + self._stackTraceView = None + self._variablesView = None + self._outputView = None + self._codeView = None + self._remote_term = None + self._uiTab = None # make sure that we're displaying signs in any still-open buffers self._breakpoints.UpdateUI() @@ -668,6 +667,10 @@ class DebugSession( object ): def _SetUpUI( self ): vim.command( 'tab split' ) self._uiTab = vim.current.tabpage + vim.command( 'augroup VimspectorReset' ) + vim.command( 'au TabClosed call vimspector#Reset()' ) + vim.command( 'augroup END' ) + mode = settings.Get( 'ui_mode' ) From f003d66d35bbe2e051080476344dc8f620d29dc0 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 3 Apr 2021 19:55:58 +0100 Subject: [PATCH 2/4] Don't crash if the custom handler can't be loaded --- python3/vimspector/debug_session.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 97257b8..deb3237 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -897,6 +897,7 @@ class DebugSession( object ): self._splash_screen, "Unable to start adapter" ) else: + handlers = [ self ] if 'custom_handler' in self._adapter: spec = self._adapter[ 'custom_handler' ] if isinstance( spec, dict ): @@ -905,10 +906,12 @@ class DebugSession( object ): else: module, cls = spec.rsplit( '.', 1 ) - CustomHandler = getattr( importlib.import_module( module ), cls ) - handlers = [ CustomHandler( self ), self ] - else: - handlers = [ self ] + try: + CustomHandler = getattr( importlib.import_module( module ), cls ) + handlers = [ CustomHandler( self ), self ] + except ImportError: + self._logger.exception( "Unable to load custom adapter %s", + spec ) self._connection = debug_adapter_connection.DebugAdapterConnection( handlers, From e7fb49f03de9cd6c57bf4ea236c228b6117437f4 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 4 Apr 2021 15:08:05 +0100 Subject: [PATCH 3/4] Start to add a test, but it's hitting deleting buffer that's in use [NULL]... --- autoload/vimspector/internal/state.vim | 10 ++++++ compiler/vimspector_test.vim | 4 ++- plugin/vimspector.vim | 5 +++ python3/vimspector/debug_session.py | 45 +++++++++++++++++--------- tests/tabpage.test.vim | 24 ++++++++++++++ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/autoload/vimspector/internal/state.vim b/autoload/vimspector/internal/state.vim index f1e690a..1c78a52 100644 --- a/autoload/vimspector/internal/state.vim +++ b/autoload/vimspector/internal/state.vim @@ -47,6 +47,16 @@ function! vimspector#internal#state#GetAPIPrefix() abort return s:prefix endfunction +function! vimspector#internal#state#TabClosed() abort + py3 << EOF + +if ( '_vimspector_session' in globals() and _vimspector_session + and not _vimspector_session._HasUI() ): + _vimspector_session.Reset( interactive = False ) + +EOF +endfunction + " Boilerplate {{{ let &cpoptions=s:save_cpo unlet s:save_cpo diff --git a/compiler/vimspector_test.vim b/compiler/vimspector_test.vim index d0c6def..8910506 100644 --- a/compiler/vimspector_test.vim +++ b/compiler/vimspector_test.vim @@ -155,7 +155,9 @@ if ! has( 'gui_running' ) " å is the right-option+q nnoremap å :cfirst " å is the right-option+a - nnoremap œ :FuncLine + nnoremap œ :cnext + " å is the right-option+f + nnoremap ƒ :FuncLine " Ω is the right-option+z nnoremap Ω :cprevious endif diff --git a/plugin/vimspector.vim b/plugin/vimspector.vim index 27ce473..5a6b556 100644 --- a/plugin/vimspector.vim +++ b/plugin/vimspector.vim @@ -145,9 +145,14 @@ augroup VimspectorUserAutoCmds augroup END " FIXME: Only register this _while_ debugging is active +let g:vimspector_resetting = 0 augroup Vimspector autocmd! autocmd BufNew * call vimspector#OnBufferCreated( expand( '' ) ) + autocmd TabClosed * + \ if !g:vimspector_resetting + \ | call vimspector#internal#state#TabClosed() + \ | endif augroup END " boilerplate {{{ diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index deb3237..0d6e76a 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -61,6 +61,7 @@ class DebugSession( object ): self._stackTraceView = None self._variablesView = None self._outputView = None + self._codeView = None self._breakpoints = breakpoints.ProjectBreakpoints() self._splash_screen = None self._remote_term = None @@ -404,27 +405,43 @@ class DebugSession( object ): self._Reset() def _Reset( self ): + vim.vars[ 'vimspector_resetting' ] = 1 self._logger.info( "Debugging complete." ) + + def ResetUI(): + if self._stackTraceView: + self._stackTraceView.Reset() + if self._variablesView: + self._variablesView.Reset() + if self._outputView: + self._outputView.Reset() + if self._codeView: + self._codeView.Reset() + + self._stackTraceView = None + self._variablesView = None + self._outputView = None + self._codeView = None + self._remote_term = None + self._uiTab = None + if self._HasUI(): self._logger.debug( "Clearing down UI" ) vim.current.tabpage = self._uiTab self._splash_screen = utils.HideSplash( self._api_prefix, self._splash_screen ) - self._stackTraceView.Reset() - self._variablesView.Reset() - self._outputView.Reset() - self._codeView.Reset() - vim.command( 'au! VimspectorReset TabClose ' ) + ResetUI() vim.command( 'tabclose!' ) + else: + ResetUI() + + try: + del vim.vars[ 'vimspector_session_windows' ] + except KeyError: + pass - del vim.vars[ 'vimspector_session_windows' ] vim.command( 'doautocmd User VimspectorDebugEnded' ) - self._stackTraceView = None - self._variablesView = None - self._outputView = None - self._codeView = None - self._remote_term = None - self._uiTab = None + vim.vars[ 'vimspector_resetting' ] = 0 # make sure that we're displaying signs in any still-open buffers self._breakpoints.UpdateUI() @@ -667,10 +684,6 @@ class DebugSession( object ): def _SetUpUI( self ): vim.command( 'tab split' ) self._uiTab = vim.current.tabpage - vim.command( 'augroup VimspectorReset' ) - vim.command( 'au TabClosed call vimspector#Reset()' ) - vim.command( 'augroup END' ) - mode = settings.Get( 'ui_mode' ) diff --git a/tests/tabpage.test.vim b/tests/tabpage.test.vim index 92b57e8..21d832e 100644 --- a/tests/tabpage.test.vim +++ b/tests/tabpage.test.vim @@ -6,6 +6,17 @@ function! ClearDown() call vimspector#test#setup#ClearDown() endfunction +let s:fn='../support/test/python/simple_python/main.py' + +function! s:StartDebugging() + exe 'edit ' . s:fn + call setpos( '.', [ 0, 23, 1 ] ) + call vimspector#ToggleBreakpoint() + call vimspector#LaunchWithSettings( { 'configuration': 'run' } ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 23, 1 ) +endfunction + + function! Test_Step_With_Different_Tabpage() lcd testdata/cpp/simple edit simple.cpp @@ -154,3 +165,16 @@ function! Test_All_Buffers_Deleted_Installer() au! Test_All_Buffers_Deleted_Installer %bwipe! endfunction + +function! Test_Close_Tab_No_Vimspector() + tabnew + q + %bwipe! +endfunction + +function! Test_Close_Tab_With_Vimspector() + call s:StartDebugging() + tabclose! + call vimspector#test#setup#WaitForReset() + %bwipe! +endfunction From d12c0897f207c07ee5232433d6b54ca0472c551e Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 4 Apr 2021 15:13:46 +0100 Subject: [PATCH 4/4] Udpate remote examples for docker/cpptools --- docs/configuration.md | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index a2864b1..a734a49 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -765,6 +765,8 @@ and have to tell cpptools a few more options. "remote": { "host": "${host}", "account": "${account}", + // or, alternatively "container": "${ContainerID}" + "runCommand": [ "gdbserver", "--once", @@ -772,14 +774,19 @@ and have to tell cpptools a few more options. "--disable-randomisation", "0.0.0.0:${port}", "%CMD%" - } + }, + "delay": "1000m" // optional }, "attach": { "remote": { "host": "${host}", "account": "${account}", + // or, alternatively "container": "${ContainerID}" + "pidCommand": [ - "/path/to/secret/script/GetPIDForService", "${ServiceName}" + // e.g. "/path/to/secret/script/GetPIDForService", "${ServiceName}" + // or... + "pgrep", "executable" ], "attachCommand": [ "gdbserver", @@ -796,12 +803,13 @@ and have to tell cpptools a few more options. // application never attaches, try using the following to manually // force the trap signal. // - "initCompleteCommand": [ - "kill", - "-TRAP", - "%PID%" - ] - } + // "initCompleteCommand": [ + // "kill", + // "-TRAP", + // "%PID%" + // ] + }, + "delay": "1000m" // optional } } }, @@ -811,22 +819,27 @@ and have to tell cpptools a few more options. "remote-cmdLine": [ "/path/to/the/remote/executable", "args..." ], "remote-request": "launch", "configuration": { - "request": "attach", // yes, attach! + "request": "launch", "program": "/path/to/the/local/executable", + "cwd": "${workspaceRoot}, "MIMode": "gdb", - "miDebuggerAddress": "${host}:${port}" + "miDebuggerServerAddress": "${host}:${port}", + "sourceFileMap#json": "{\"${RemoteRoot}\": \"${workspaceRoot}\"}" } }, "remote attach": { "adapter": "cpptools-remote", "remote-request": "attach", "configuration": { - "request": "attach", + "request": "launch", "program": "/path/to/the/local/executable", + "cwd": "${workspaceRoot}, "MIMode": "gdb", - "miDebuggerAddress": "${host}:${port}" + "miDebuggerServerAddress": "${host}:${port}", + "sourceFileMap#json": "{\"${RemoteRoot}\": \"${workspaceRoot}\"}" + } } } }