Added statement execution for GDB.

Only supports setting variables and executing functions, because that's
what GDB supports(via different commands)(I think - didn't find anything
else...)
This commit is contained in:
IdanArye 2014-05-16 23:58:02 +03:00
parent b5cbffd7bc
commit 75cee7c51f
3 changed files with 35 additions and 0 deletions

View File

@ -37,6 +37,7 @@ function! vebugger#gdb#start(binaryFile,args)
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
call l:debugger.setWriteHandler('std','closeDebugger',function('s:closeDebugger'))
call l:debugger.setWriteHandler('std','evaluateExpressions',function('s:requestEvaluateExpression'))
call l:debugger.setWriteHandler('std','executeStatements',function('s:executeStatements'))
call l:debugger.generateWriteActionsFromTemplate()
@ -125,6 +126,20 @@ function! s:requestEvaluateExpression(writeAction,debugger)
endfor
endfunction
function! s:executeStatements(writeAction,debugger)
for l:evalAction in a:writeAction
if has_key(l:evalAction,'statement')
let l:statement=l:evalAction.statement
let l:statement=substitute(l:statement,'\v;\s*$','','') "remove trailing `;`
if l:statement=~'\v^[^(]+\=.+'
call a:debugger.writeLine('set '.l:statement)
else
call a:debugger.writeLine('call '.l:statement)
endif
endif
endfor
endfunction
function! s:readEvaluatedExpressions(pipeName,line,readResult,debugger) dict
if 'out'==a:pipeName
if has_key(self,'nextExpressionToBePrinted')

View File

@ -24,6 +24,7 @@ function! vebugger#std#setStandardWriteactionsTemplate(debugger)
\'flow':'',
\'breakpoints':[],
\'evaluateExpressions':[],
\'executeStatements':[],
\'removeAfterDisplayed':[],
\'closeDebugger':''}
endfunction
@ -119,6 +120,13 @@ function! s:standardFunctions.eval(expression) dict
call self.performWriteActions()
endfunction
"Executes a statement in the debugged program
function! s:standardFunctions.execute(statement) dict
call self.addWriteAction('std','executeStatements',{
\'statement':(a:statement)})
call self.performWriteActions()
endfunction
let s:standardThinkHandlers={}
function! s:standardThinkHandlers.addProgramOutputToShell(readResult,debugger) dict
let l:programOutput=a:readResult.std.programOutput
@ -272,3 +280,10 @@ function! vebugger#std#eval(expression)
call l:debugger.std_eval(a:expression)
endif
endfunction
function! vebugger#std#execute(statement)
let l:debugger=vebugger#getActiveDebugger()
if !empty(l:debugger) && !empty(l:debugger.std_eval)
call l:debugger.std_execute(a:statement)
endif
endfunction

View File

@ -15,8 +15,10 @@ command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints()
command! -nargs=1 VBGeval call vebugger#std#eval(<q-args>)
command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('<cword>'))
command! -nargs=1 VBGexecute call vebugger#std#execute(<q-args>)
command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(vebugger#util#get_visual_selection())
command! -range -nargs=0 VBGexecuteSelectedText call vebugger#std#execute(vebugger#util#get_visual_selection())
command! -range -nargs=0 VBGrawWriteSelectedText call vebugger#writeLine(vebugger#util#get_visual_selection())
command! -nargs=1 -complete=file VBGstartGDB call vebugger#gdb#start(<q-args>,{})
@ -36,12 +38,15 @@ if exists('g:vebugger_leader')
\'B':'VBGclearBreakpints',
\'e':'VBGevalWordUnderCursor',
\'E':'exe "VBGeval ".input("VBG-Eval> ")',
\'x':'exe "VBGexecute ".getline(".")',
\'X':'exe "VBGexecute ".input("VBG-Exec> ")',
\'w':'exe "VBGrawWrite ".getline(".")',
\'W':'exe "VBGrawWrite ".input("VBG> ")'})
exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
endfor
for s:mapping in items({
\'e':'VBGevalSelectedText',
\'x':'VBGexecuteSelectedText',
\'w':'VBGrawWriteSelectedText'})
exe 'vnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
endfor