Finally fix breakpoint bugs
This commit is contained in:
parent
9fc0a16912
commit
1e54e457d4
5 changed files with 63 additions and 28 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
import abc
|
||||||
import vim
|
import vim
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -23,6 +24,16 @@ import json
|
||||||
from vimspector import utils
|
from vimspector import utils
|
||||||
|
|
||||||
|
|
||||||
|
class ServerBreakpointHandler( object ):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def ClearBreakpoints( self ):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def AddBreakpoints( self, source, message ):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProjectBreakpoints( object ):
|
class ProjectBreakpoints( object ):
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
self._connection = None
|
self._connection = None
|
||||||
|
|
@ -118,21 +129,26 @@ class ProjectBreakpoints( object ):
|
||||||
return
|
return
|
||||||
|
|
||||||
found_bp = False
|
found_bp = False
|
||||||
|
action = 'New'
|
||||||
for index, bp in enumerate( self._line_breakpoints[ file_name ] ):
|
for index, bp in enumerate( self._line_breakpoints[ file_name ] ):
|
||||||
if bp[ 'line' ] == line:
|
if bp[ 'line' ] == line:
|
||||||
found_bp = True
|
found_bp = True
|
||||||
if bp[ 'state' ] == 'ENABLED':
|
if bp[ 'state' ] == 'ENABLED' and not self._connection:
|
||||||
bp[ 'state' ] = 'DISABLED'
|
bp[ 'state' ] = 'DISABLED'
|
||||||
|
action = 'Disable'
|
||||||
else:
|
else:
|
||||||
if 'sign_id' in bp:
|
if 'sign_id' in bp:
|
||||||
vim.command( 'sign unplace {0} group=VimspectorBP'.format(
|
vim.command( 'sign unplace {0} group=VimspectorBP'.format(
|
||||||
bp[ 'sign_id' ] ) )
|
bp[ 'sign_id' ] ) )
|
||||||
del self._line_breakpoints[ file_name ][ index ]
|
del self._line_breakpoints[ file_name ][ index ]
|
||||||
|
action = 'Delete'
|
||||||
|
break
|
||||||
|
|
||||||
self._logger.debug( "Toggle found bp at {}:{} ? {}".format(
|
self._logger.debug( "Toggle found bp at {}:{} ? {} ({})".format(
|
||||||
file_name,
|
file_name,
|
||||||
line,
|
line,
|
||||||
found_bp ) )
|
found_bp,
|
||||||
|
action ) )
|
||||||
|
|
||||||
if not found_bp:
|
if not found_bp:
|
||||||
self._line_breakpoints[ file_name ].append( {
|
self._line_breakpoints[ file_name ].append( {
|
||||||
|
|
@ -172,13 +188,10 @@ class ProjectBreakpoints( object ):
|
||||||
|
|
||||||
|
|
||||||
def SendBreakpoints( self ):
|
def SendBreakpoints( self ):
|
||||||
if not self._breakpoints_handler:
|
assert self._breakpoints_handler is not None
|
||||||
def handler( source, msg ):
|
|
||||||
return self._ShowBreakpoints()
|
|
||||||
|
|
||||||
assert False
|
# Clear any existing breakpoints prior to sending new ones
|
||||||
else:
|
self._breakpoints_handler.ClearBreakpoints()
|
||||||
handler = self._breakpoints_handler
|
|
||||||
|
|
||||||
for file_name, line_breakpoints in self._line_breakpoints.items():
|
for file_name, line_breakpoints in self._line_breakpoints.items():
|
||||||
breakpoints = []
|
breakpoints = []
|
||||||
|
|
@ -199,7 +212,7 @@ class ProjectBreakpoints( object ):
|
||||||
}
|
}
|
||||||
|
|
||||||
self._connection.DoRequest(
|
self._connection.DoRequest(
|
||||||
lambda msg: handler( source, msg ),
|
lambda msg: self._breakpoints_handler.AddBreakpoints( source, msg ),
|
||||||
{
|
{
|
||||||
'command': 'setBreakpoints',
|
'command': 'setBreakpoints',
|
||||||
'arguments': {
|
'arguments': {
|
||||||
|
|
@ -212,7 +225,7 @@ class ProjectBreakpoints( object ):
|
||||||
|
|
||||||
if self._server_capabilities.get( 'supportsFunctionBreakpoints' ):
|
if self._server_capabilities.get( 'supportsFunctionBreakpoints' ):
|
||||||
self._connection.DoRequest(
|
self._connection.DoRequest(
|
||||||
lambda msg: handler( None, msg ),
|
lambda msg: self._breakpoints_handler.AddBreakpoints( None, msg ),
|
||||||
{
|
{
|
||||||
'command': 'setFunctionBreakpoints',
|
'command': 'setFunctionBreakpoints',
|
||||||
'arguments': {
|
'arguments': {
|
||||||
|
|
|
||||||
|
|
@ -183,14 +183,20 @@ class DebugSession( object ):
|
||||||
self._outputView.ConnectionUp( self._connection )
|
self._outputView.ConnectionUp( self._connection )
|
||||||
self._breakpoints.ConnectionUp( self._connection )
|
self._breakpoints.ConnectionUp( self._connection )
|
||||||
|
|
||||||
def update_breakpoints( source, message ):
|
class Handler( breakpoints.ServerBreakpointHandler ):
|
||||||
|
def __init__( self, codeView ):
|
||||||
|
self.codeView = codeView
|
||||||
|
|
||||||
|
def ClearBreakpoints( self ):
|
||||||
|
self.codeView.ClearBreakpoints()
|
||||||
|
|
||||||
|
def AddBreakpoints( self, source, message ):
|
||||||
if 'body' not in message:
|
if 'body' not in message:
|
||||||
return
|
return
|
||||||
self._codeView.AddBreakpoints( source,
|
self.codeView.AddBreakpoints( source,
|
||||||
message[ 'body' ][ 'breakpoints' ] )
|
message[ 'body' ][ 'breakpoints' ] )
|
||||||
self._codeView.ShowBreakpoints()
|
|
||||||
|
|
||||||
self._breakpoints.SetBreakpointsHandler( update_breakpoints )
|
self._breakpoints.SetBreakpointsHandler( Handler( self._codeView ) )
|
||||||
|
|
||||||
if self._connection:
|
if self._connection:
|
||||||
self._StopDebugAdapter( start )
|
self._StopDebugAdapter( start )
|
||||||
|
|
|
||||||
|
|
@ -182,14 +182,25 @@ function Test_DisableBreakpointWhileDebugging()
|
||||||
|
|
||||||
" Remove the breakpoint
|
" Remove the breakpoint
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 16 )
|
call WaitForAssert( {->
|
||||||
|
\ vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode',
|
||||||
|
\ 16 )
|
||||||
|
\ } )
|
||||||
|
|
||||||
" Add the breakpoint
|
" Add the breakpoint
|
||||||
call feedkeys( "\<F9>", 'xt' )
|
call feedkeys( "\<F9>", 'xt' )
|
||||||
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
call WaitForAssert( {->
|
||||||
|
\ vimspector#test#signs#AssertSignGroupSingletonAtLine(
|
||||||
\ 'VimspectorCode',
|
\ 'VimspectorCode',
|
||||||
\ 16,
|
\ 16,
|
||||||
\ 'vimspectorBP' )
|
\ 'vimspectorBP' )
|
||||||
|
\ } )
|
||||||
|
|
||||||
|
" Run to breakpoint
|
||||||
|
call setpos( '.', [ 0, 15, 1 ] )
|
||||||
|
call feedkeys( "\<F5>", 'xt' )
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 16, 1 )
|
||||||
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 16 )
|
||||||
|
|
||||||
call vimspector#Reset()
|
call vimspector#Reset()
|
||||||
call WaitForAssert( {->
|
call WaitForAssert( {->
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ function! vimspector#test#signs#AssertSignGroupSingletonAtLine( group,
|
||||||
|
|
||||||
return assert_equal( 1,
|
return assert_equal( 1,
|
||||||
\ len( signs ),
|
\ len( signs ),
|
||||||
\ 'Num buffers named %' ) &&
|
\ 'Num buffers named %' ) ||
|
||||||
\ assert_equal( 1,
|
\ assert_equal( 1,
|
||||||
\ len( signs[ 0 ].signs ),
|
\ len( signs[ 0 ].signs ),
|
||||||
\ 'Num signs in ' . a:group . ' at ' . a:line ) &&
|
\ 'Num signs in ' . a:group . ' at ' . a:line ) ||
|
||||||
\ assert_equal( a:sign_name,
|
\ assert_equal( a:sign_name,
|
||||||
\ signs[ 0 ].signs[ 0 ].name,
|
\ signs[ 0 ].signs[ 0 ].name,
|
||||||
\ 'Sign in group ' . a:group . ' at ' . a:line )
|
\ 'Sign in group ' . a:group . ' at ' . a:line )
|
||||||
|
|
@ -64,7 +64,7 @@ function! vimspector#test#signs#AssertSignGroupEmptyAtLine( group, line ) abort
|
||||||
|
|
||||||
return assert_equal( 1,
|
return assert_equal( 1,
|
||||||
\ len( signs ),
|
\ len( signs ),
|
||||||
\ 'Num buffers named %' ) &&
|
\ 'Num buffers named %' ) ||
|
||||||
\ assert_equal( 0,
|
\ assert_equal( 0,
|
||||||
\ len( signs[ 0 ].signs ),
|
\ len( signs[ 0 ].signs ),
|
||||||
\ 'Num signs in ' . a:group . ' at ' . a:line )
|
\ 'Num signs in ' . a:group . ' at ' . a:line )
|
||||||
|
|
@ -77,7 +77,7 @@ function! vimspector#test#signs#AssertSignGroupEmpty( group ) abort
|
||||||
\ } )
|
\ } )
|
||||||
return assert_equal( 1,
|
return assert_equal( 1,
|
||||||
\ len( signs ),
|
\ len( signs ),
|
||||||
\ 'Num buffers named %' ) &&
|
\ 'Num buffers named %' ) ||
|
||||||
\ assert_equal( 0,
|
\ assert_equal( 0,
|
||||||
\ len( signs[ 0 ].signs ),
|
\ len( signs[ 0 ].signs ),
|
||||||
\ 'Num signs in ' . a:group )
|
\ 'Num signs in ' . a:group )
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,11 @@ func RunTheTest(test)
|
||||||
try
|
try
|
||||||
let s:test = a:test
|
let s:test = a:test
|
||||||
let s:testid = g:testpath . ':' . a:test
|
let s:testid = g:testpath . ':' . a:test
|
||||||
|
let test_filesafe = substitute( a:test, ')', '_', 'g' )
|
||||||
|
let test_filesafe = substitute( test_filesafe, '(', '_', 'g' )
|
||||||
|
let test_filesafe = substitute( test_filesafe, ',', '_', 'g' )
|
||||||
|
let test_filesafe = substitute( test_filesafe, ':', '_', 'g' )
|
||||||
|
let s:testid_filesafe = g:testpath . '_' . test_filesafe
|
||||||
au VimLeavePre * call EarlyExit(s:test)
|
au VimLeavePre * call EarlyExit(s:test)
|
||||||
exe 'call ' . a:test
|
exe 'call ' . a:test
|
||||||
au! VimLeavePre
|
au! VimLeavePre
|
||||||
|
|
@ -203,7 +208,7 @@ func AfterTheTest()
|
||||||
let v:errors = []
|
let v:errors = []
|
||||||
|
|
||||||
let log = readfile( expand( '~/.vimspector.log' ) )
|
let log = readfile( expand( '~/.vimspector.log' ) )
|
||||||
let logfile = s:testid . '.vimspector.log'
|
let logfile = s:testid_filesafe . '.vimspector.log'
|
||||||
call writefile( log, logfile, 's' )
|
call writefile( log, logfile, 's' )
|
||||||
call add( s:messages, 'Wrote log for failed test: ' . logfile )
|
call add( s:messages, 'Wrote log for failed test: ' . logfile )
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue