Merge pull request #15 from puremourning/clear-breakpoints

Add ClearBreakpoints API
This commit is contained in:
mergify[bot] 2019-04-28 09:53:47 +00:00 committed by GitHub
commit 60e9e3e2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 155 additions and 19 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ tests/debuglog
test.log
gadgets/
*.pyc
*.dSYM

View file

@ -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

View file

@ -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

View file

@ -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',

View file

@ -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 )

View file

@ -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<CR>' )
edit testdata/cpp/simple/simple.cpp
call feedkeys( "/printf\<CR>", '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( "\<F9>", '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( "\<F9>", '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( "\<F9>", '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( "\<F9>", '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( "\<F5>", 'x' )
call vimspector#Reset()
call vimspector#ClearBreakpoints()
lcd -
bwipeout!
endfunction

View file

@ -1,7 +0,0 @@
#include <iostream>
int main( int argc, char ** )
{
printf( "this is a test %d", argc );
return 0;
}

1
tests/testdata/cpp/simple/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
simple

View file

@ -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}"
}
}
}
}

7
tests/testdata/cpp/simple/Makefile vendored Normal file
View file

@ -0,0 +1,7 @@
CXXFLAGS=-g -O0
simple: simple.cpp
clean:
rm -f simple
rm -rf simple.dSYM

18
tests/testdata/cpp/simple/simple.cpp vendored Normal file
View file

@ -0,0 +1,18 @@
#include <iostream>
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;
}