diff --git a/.gitignore b/.gitignore index a29bc85..a000f4e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ tests/debuglog test.log gadgets/ *.pyc +*.dSYM diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index c3138c7..093ab52 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -38,6 +38,10 @@ function! vimspector#Restart() abort py3 _vimspector_session.Restart() endfunction +function! vimspector#ClearBreakpoints() abort + py3 _vimspector_session.ClearBreakpoints() +endfunction + function! vimspector#ToggleBreakpoint() abort py3 _vimspector_session.ToggleBreakpoint() endfunction diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a6d15da..ac7ea59 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,8 +15,13 @@ jobs: - bash: vim --version displayName: 'Print vim version information' + - bash: cd tests/testdata/cpp/simple && make + displayName: 'Build test cpp program' + - bash: ./run_tests displayName: 'Run the tests' + env: + VIMSPECTOR_MIMODE: gdb - job: 'macos' pool: @@ -31,5 +36,10 @@ jobs: - bash: vim --version displayName: 'Print vim version information' + - bash: cd tests/testdata/cpp/simple && make + displayName: 'Build test cpp program' + - bash: ./run_tests displayName: 'Run the tests' + env: + VIMSPECTOR_MIMODE: lldb diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index 0cc1d06..18cb308 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -29,10 +29,10 @@ class ProjectBreakpoints( object ): # These are the user-entered breakpoints. self._line_breakpoints = defaultdict( list ) self._func_breakpoints = [] + self._exceptionBreakpoints = None # FIXME: Remove this. Remove breakpoints nonesense from code.py self._breakpoints_handler = None - self._exceptionBreakpoints = None self._server_capabilities = {} self._next_sign_id = 1 @@ -92,6 +92,14 @@ class ProjectBreakpoints( object ): vim.eval( 'setqflist( {} )'.format( json.dumps( qf ) ) ) + def ClearBreakpoints( self ): + # These are the user-entered breakpoints. + self._line_breakpoints = defaultdict( list ) + self._func_breakpoints = [] + self._exceptionBreakpoints = None + + self.UpdateUI() + def ToggleBreakpoint( self ): line, column = vim.current.window.cursor file_name = vim.current.buffer.name @@ -211,6 +219,7 @@ class ProjectBreakpoints( object ): } ) + def _SetUpExceptionBreakpoints( self ): exceptionBreakpointFilters = self._server_capabilities.get( 'exceptionBreakpointFilters', diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 5acef40..5c7fa74 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -724,5 +724,8 @@ class DebugSession( object ): def ToggleBreakpoint( self ): return self._breakpoints.ToggleBreakpoint() + def ClearBreakpoints( self ): + return self._breakpoints.ClearBreakpoints() + def AddFunctionBreakpoint( self, function ): return self._breakpoints.AddFunctionBreakpoint( function ) diff --git a/tests/breakpoints.test.vim b/tests/breakpoints.test.vim index 1b21d60..d0ed81e 100644 --- a/tests/breakpoints.test.vim +++ b/tests/breakpoints.test.vim @@ -31,6 +31,10 @@ function! Test_Mappings_Are_Added_HUMAN() call assert_true( hasmapto( 'vimspector#StepOut()' ) ) endfunction +function! SetUp_Test_Mappings_Are_Added_VISUAL_STUDIO() + let g:vimspector_enable_mappings = 'VISUAL_STUDIO' +endfunction + function! Test_Mappings_Are_Added_VISUAL_STUDIO() call assert_true( hasmapto( 'vimspector#Continue()' ) ) call assert_false( hasmapto( 'vimspector#Launch()' ) ) @@ -49,8 +53,8 @@ endfunction function! Test_Signs_Placed_Using_API_Are_Shown() " We need a real file - edit testdata/cpp/simple.cpp - call feedkeys( '/printf' ) + edit testdata/cpp/simple/simple.cpp + call feedkeys( "/printf\", 'x' ) " Set breakpoint call vimspector#ToggleBreakpoint() @@ -62,9 +66,9 @@ function! Test_Signs_Placed_Using_API_Are_Shown() \ 'line': line( '.' ) \ } ) - call assert_true( len( signs ) == 1 ) - call assert_true( len( signs[ 0 ].signs ) == 1 ) - call assert_true( signs[ 0 ].signs[ 0 ].name == 'vimspectorBP' ) + call assert_equal( 1, len( signs ) ) + call assert_equal( 1, len( signs[ 0 ].signs ) ) + call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name ) " Disable breakpoint call vimspector#ToggleBreakpoint() @@ -74,9 +78,9 @@ function! Test_Signs_Placed_Using_API_Are_Shown() \ 'line': line( '.' ) \ } ) - call assert_true( len( signs ) == 1 ) - call assert_true( len( signs[ 0 ].signs ) == 1 ) - call assert_true( signs[ 0 ].signs[ 0 ].name == 'vimspectorBPDisabled' ) + call assert_equal( 1, len( signs ) ) + call assert_equal( 1, len( signs[ 0 ].signs ) ) + call assert_equal( 'vimspectorBPDisabled', signs[ 0 ].signs[ 0 ].name ) " Remove breakpoint call vimspector#ToggleBreakpoint() @@ -86,8 +90,76 @@ function! Test_Signs_Placed_Using_API_Are_Shown() \ 'line': line( '.' ) \ } ) - call assert_true( len( signs ) == 1 ) - call assert_true( len( signs[ 0 ].signs ) == 0 ) + call assert_equal( 1, len( signs ) ) + call assert_equal( 0, len( signs[ 0 ].signs ) ) - " TODO: Use the screen dump test ? + call vimspector#ClearBreakpoints() + bwipeout! +endfunction + +function! SetUp_Test_Use_Mappings_HUMAN() + let g:vimspector_enable_mappings = 'HUMAN' +endfunction + +function! Test_Use_Mappings_HUMAN() + lcd testdata/cpp/simple + edit simple.cpp + + 15 + call assert_equal( 15, line( '.' ) ) + + " Add the breakpoing + call feedkeys( "\", 'x' ) + + let signs = sign_getplaced( '.', { + \ 'group': 'VimspectorBP', + \ 'line': line( '.' ) + \ } ) + + call assert_equal( 1, len( signs ), 1 ) + call assert_equal( 1, len( signs[ 0 ].signs ), 1 ) + call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name ) + + " Disable the breakpoint + call feedkeys( "\", 'x' ) + + let signs = sign_getplaced( '.', { + \ 'group': 'VimspectorBP', + \ 'line': line( '.' ) + \ } ) + call assert_equal( 1, len( signs ), 1 ) + call assert_equal( 1, len( signs[ 0 ].signs ), 1 ) + call assert_equal( 'vimspectorBPDisabled', signs[ 0 ].signs[ 0 ].name ) + + " Delete the breakpoint + call feedkeys( "\", 'x' ) + + let signs = sign_getplaced( '.', { + \ 'group': 'VimspectorBP', + \ 'line': line( '.' ) + \ } ) + call assert_equal( 1, len( signs ), 1 ) + call assert_equal( 0, len( signs[ 0 ].signs ) ) + + " Add it again + call feedkeys( "\", 'x' ) + + let signs = sign_getplaced( '.', { + \ 'group': 'VimspectorBP', + \ 'line': line( '.' ) + \ } ) + + call assert_equal( 1, len( signs ), 1 ) + call assert_equal( 1, len( signs[ 0 ].signs ), 1 ) + call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name ) + + " Here we go. Start Debugging + call feedkeys( "\", 'x' ) + + call vimspector#Reset() + + call vimspector#ClearBreakpoints() + + lcd - + bwipeout! endfunction diff --git a/tests/testdata/cpp/simple.cpp b/tests/testdata/cpp/simple.cpp deleted file mode 100644 index e3e623a..0000000 --- a/tests/testdata/cpp/simple.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main( int argc, char ** ) -{ - printf( "this is a test %d", argc ); - return 0; -} diff --git a/tests/testdata/cpp/simple/.gitignore b/tests/testdata/cpp/simple/.gitignore new file mode 100644 index 0000000..ab23474 --- /dev/null +++ b/tests/testdata/cpp/simple/.gitignore @@ -0,0 +1 @@ +simple diff --git a/tests/testdata/cpp/simple/.vimspector.json b/tests/testdata/cpp/simple/.vimspector.json new file mode 100644 index 0000000..c1d9552 --- /dev/null +++ b/tests/testdata/cpp/simple/.vimspector.json @@ -0,0 +1,18 @@ +{ + "configurations": { + "cpptools-run": { + "adapter": "vscode-cpptools", + "configuration": { + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/simple", + "args": [], + "cwd": "${workspaceRoot}", + "environment": [], + "externalConsole": true, + "stopAtEntry": true, + "MImode": "${VIMSPECTOR_MIMODE}" + } + } + } +} diff --git a/tests/testdata/cpp/simple/Makefile b/tests/testdata/cpp/simple/Makefile new file mode 100644 index 0000000..c554c2b --- /dev/null +++ b/tests/testdata/cpp/simple/Makefile @@ -0,0 +1,7 @@ +CXXFLAGS=-g -O0 + +simple: simple.cpp + +clean: + rm -f simple + rm -rf simple.dSYM diff --git a/tests/testdata/cpp/simple/simple.cpp b/tests/testdata/cpp/simple/simple.cpp new file mode 100644 index 0000000..5ca675c --- /dev/null +++ b/tests/testdata/cpp/simple/simple.cpp @@ -0,0 +1,18 @@ +#include + +namespace +{ + void foo( int bar ) + { + int unused; + + printf( "%d\n", bar ); + } +} + +int main( int argc, char ** ) +{ + printf( "this is a test %d\n", argc ); + foo( argc ); + return 0; +}