Merge pull request #279 from puremourning/breakpoint-event

Fix breakpoint event
This commit is contained in:
mergify[bot] 2020-10-10 15:29:38 +00:00 committed by GitHub
commit 1eb9933e2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 135 additions and 22 deletions

View file

@ -183,7 +183,7 @@ function! vimspector#Evaluate( expr ) abort
return
endif
py3 _vimspector_session.ShowOutput( 'Console' )
py3 _vimspector_session.EvaluateConsole( vim.eval( 'a:expr' ) )
py3 _vimspector_session.EvaluateConsole( vim.eval( 'a:expr' ), True )
endfunction
function! vimspector#EvaluateConsole( expr ) abort
@ -192,7 +192,7 @@ function! vimspector#EvaluateConsole( expr ) abort
endif
stopinsert
setlocal nomodified
py3 _vimspector_session.EvaluateConsole( vim.eval( 'a:expr' ) )
py3 _vimspector_session.EvaluateConsole( vim.eval( 'a:expr' ), False )
endfunction
function! vimspector#ShowOutput( ... ) abort

View file

@ -166,25 +166,29 @@ class CodeView( object ):
def AddBreakpoints( self, source, breakpoints ):
for breakpoint in breakpoints:
if 'source' not in breakpoint:
if source:
breakpoint[ 'source' ] = source
else:
self._logger.warn( 'missing source in breakpoint {0}'.format(
json.dumps( breakpoint ) ) )
continue
source = breakpoint.get( 'source' ) or source
if not source or 'path' not in source:
self._logger.warn( 'missing source/path in breakpoint {0}'.format(
json.dumps( breakpoint ) ) )
continue
self._breakpoints[ breakpoint[ 'source' ][ 'path' ] ].append(
breakpoint )
breakpoint[ 'source' ] = source
self._breakpoints[ source[ 'path' ] ].append( breakpoint )
self._logger.debug( 'Breakpoints at this point: {0}'.format(
json.dumps( self._breakpoints, indent = 2 ) ) )
self.ShowBreakpoints()
def AddBreakpoint( self, breakpoint ):
self.AddBreakpoints( None, [ breakpoint ] )
def UpdateBreakpoint( self, bp ):
if 'id' not in bp:
self.AddBreakpoints( None, [ bp ] )
self.AddBreakpoint( bp )
return
for _, breakpoint_list in self._breakpoints.items():
for index, breakpoint in enumerate( breakpoint_list ):
@ -194,7 +198,22 @@ class CodeView( object ):
return
# Not found. Assume new
self.AddBreakpoints( None, [ bp ] )
self.AddBreakpoint( bp )
def RemoveBreakpoint( self, bp ):
for _, breakpoint_list in self._breakpoints.items():
found_index = None
for index, breakpoint in enumerate( breakpoint_list ):
if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]:
found_index = index
break
if found_index is not None:
del breakpoint_list[ found_index ]
self.ShowBreakpoints()
return
def _UndisplaySigns( self ):
for sign_id in self._signs[ 'breakpoints' ]:

View file

@ -467,9 +467,10 @@ class DebugSession( object ):
expression )
@IfConnected()
def EvaluateConsole( self, expression ):
def EvaluateConsole( self, expression, verbose ):
self._outputView.Evaluate( self._stackTraceView.GetCurrentFrame(),
expression )
expression,
verbose )
@IfConnected()
def DeleteWatch( self ):
@ -1050,7 +1051,9 @@ class DebugSession( object ):
if reason == 'changed':
self._codeView.UpdateBreakpoint( bp )
elif reason == 'new':
self._codeView.AddBreakpoints( None, bp )
self._codeView.AddBreakpoint( bp )
elif reason == 'removed':
self._codeView.RemoveBreakpoint( bp )
else:
utils.UserMessage(
'Unrecognised breakpoint event (undocumented): {0}'.format( reason ),

View file

@ -260,14 +260,18 @@ class DAPOutputView( OutputView ):
# Don't clear because output is probably still useful
self._connection = None
def Evaluate( self, frame, expression ):
self._Print( 'Console', [ 'Evaluating: ' + expression ] )
def Evaluate( self, frame, expression, verbose ):
if verbose:
self._Print( 'Console', f"Evaluating: { expression }" )
def print_result( message ):
result = message[ 'body' ][ 'result' ]
if result is None:
result = '<no result>'
self._Print( 'Console', f' Result: { result }' )
self._Print( 'Console', result.splitlines() )
def print_failure( reason, msg ):
self._Print( 'Console', reason.splitlines() )
request = {
'command': 'evaluate',
@ -280,4 +284,6 @@ class DAPOutputView( OutputView ):
if frame:
request[ 'arguments' ][ 'frameId' ] = frame[ 'id' ]
self._connection.DoRequest( print_result, request )
self._connection.DoRequest( print_result,
request,
print_failure )

View file

@ -68,6 +68,45 @@
"CALCULATED_STR", "${CALCULATED_STR}"
]
}
},
"lldb-vscode": {
"adapter": "lldb-vscode",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
"cwd": "${workspaceRoot}",
"externalConsole": false,
"MIMode": "lldb"
}
},
"CodeLLDB": {
"adapter": "CodeLLDB",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
"cwd": "${workspaceRoot}",
"expressions": "native"
}
}
},
"adapters": {
"lldb-vscode": {
"variables": {
"LLVM": {
"shell": "brew --prefix llvm"
}
},
"attach": {
"pidProperty": "pid",
"pidSelect": "ask"
},
"command": [
"${LLVM}/bin/lldb-vscode"
],
"env": {
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY": "YES"
},
"name": "lldb"
}
}
}

View file

@ -499,7 +499,7 @@ function Test_EvaluateConsole()
call WaitForAssert( {->
\ assert_equal(
\ [
\ ' Result: 1'
\ '1'
\ ],
\ getbufline( bufnr( 'vimspector.Console' ), '$', '$' )
\ )
@ -511,7 +511,7 @@ function Test_EvaluateConsole()
\ assert_equal(
\ [
\ 'Evaluating: t.i',
\ ' Result: 1'
\ '1'
\ ],
\ getbufline( bufnr( 'vimspector.Console' ), len-1, '$' )
\ )
@ -522,3 +522,49 @@ function Test_EvaluateConsole()
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function Test_EvaluatePromptConsole()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 27, 1 )
VimspectorShowOutput
call assert_equal( bufnr( 'vimspector.Console' ),
\ winbufnr( g:vimspector_session_windows.output ) )
call feedkeys( "it.i\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '1'
\ ],
\ getbufline( bufnr( 'vimspector.Console' ), '$', '$' )
\ )
\ } )
let len = getbufinfo( 'vimspector.Console' )[ 0 ].linecount
call WaitForAssert( {->
\ assert_equal(
\ [
\ '> t.i',
\ '',
\ '1'
\ ],
\ getbufline( bufnr( 'vimspector.Console' ), len-2, '$' )
\ )
\ } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer(
\ 'vimspector.Console', len, v:null )
call vimspector#test#setup#Reset()
%bwipe!
endfunction