diff --git a/autoload/vebugger.vim b/autoload/vebugger.vim index e1ec249..1cd80c1 100644 --- a/autoload/vebugger.vim +++ b/autoload/vebugger.vim @@ -1,199 +1,199 @@ "Read and return all new lines from a Vebugger pipe object. function! s:readNewLinesFromPipe(pipeObject) - "read - let l:text=a:pipeObject.pipe.read(1000,0) - while 0 if exists('b:debugger') | call b:debugger.kill() | endif - setlocal buftype=nofile - setlocal bufhidden=wipe - let a:debugger.shellBuffer=bufnr('') - silent file Vebugger:Shell - wincmd p + if has_key(a:debugger,'shellBuffer') + if -1 if exists('b:debugger') | call b:debugger.kill() | endif + setlocal buftype=nofile + setlocal bufhidden=wipe + let a:debugger.shellBuffer=bufnr('') + silent file Vebugger:Shell + wincmd p endfunction let s:standardFunctions={} "Write a line to the shell buffer function! s:standardFunctions.addLineToShellBuffer(line) dict - if has_key(self,'shellBuffer') - let l:bufwin=bufwinnr(self.shellBuffer) - if -1 @@ -240,83 +240,75 @@ sign define vebugger_breakpoint text=** linehl=ColorColumn "Update all the marks(currently executed line and breakpoints) for a file function! vebugger#std#updateMarksForFile(state,filename) - let l:filename=fnamemodify(a:filename,":p") - if bufexists(l:filename) - exe 'sign unplace 1 file='.fnameescape(fnamemodify(l:filename,':p')) - exe 'sign unplace 2 file='.fnameescape(fnamemodify(l:filename,':p')) + let l:filename=fnamemodify(a:filename,":p") + if bufexists(l:filename) + exe 'sign unplace 1 file='.fnameescape(fnamemodify(l:filename,':p')) + exe 'sign unplace 2 file='.fnameescape(fnamemodify(l:filename,':p')) - for l:breakpoint in g:vebugger_breakpoints - if fnamemodify(l:breakpoint.file,':p')==fnamemodify(a:filename,':p') - exe 'sign place 2 name=vebugger_breakpoint line='.l:breakpoint.line.' file='.fnameescape(fnamemodify(l:breakpoint.file,':p')) - endif - endfor + for l:breakpoint in g:vebugger_breakpoints + if fnamemodify(l:breakpoint.file,':p')==fnamemodify(a:filename,':p') + exe 'sign place 2 name=vebugger_breakpoint line='.l:breakpoint.line.' file='.fnameescape(fnamemodify(l:breakpoint.file,':p')) + endif + endfor - if !empty(a:state) - if !empty(a:state.std.location) - if fnamemodify(a:state.std.location.file,':p')==fnamemodify(a:filename,':p') - exe 'sign place 1 name=vebugger_current line='.a:state.std.location.line.' file='.fnameescape(fnamemodify(l:filename,':p')) - endif - endif - endif - endif + if !empty(a:state) + if !empty(a:state.std.location) + if fnamemodify(a:state.std.location.file,':p')==fnamemodify(a:filename,':p') + exe 'sign place 1 name=vebugger_current line='.a:state.std.location.line.' file='.fnameescape(fnamemodify(l:filename,':p')) + endif + endif + endif + endif endfunction "Toggle a breakpoint on and off function! vebugger#std#toggleBreakpoint(file,line) - let l:debugger=vebugger#getActiveDebugger() - let l:debuggerState=empty(l:debugger) - \? {} - \: l:debugger.state - for l:i in range(len(g:vebugger_breakpoints)) - let l:breakpoint=g:vebugger_breakpoints[l:i] - if l:breakpoint.file==a:file && l:breakpoint.line==a:line - call remove(g:vebugger_breakpoints,l:i) - call vebugger#addWriteActionAndPerform('std','breakpoints',{ - \'action':'remove', - \'file':(a:file), - \'line':(a:line)}) - call vebugger#std#updateMarksForFile(l:debuggerState,a:file) - return - endif - endfor - call add(g:vebugger_breakpoints,{'file':(a:file),'line':(a:line)}) - call vebugger#addWriteActionAndPerform('std','breakpoints',{ - \'action':'add', - \'file':(a:file), - \'line':(a:line)}) - call vebugger#std#updateMarksForFile(l:debuggerState,a:file) + let l:debugger=vebugger#getActiveDebugger() + let l:debuggerState=empty(l:debugger) + \? {} + \: l:debugger.state + for l:i in range(len(g:vebugger_breakpoints)) + let l:breakpoint=g:vebugger_breakpoints[l:i] + if l:breakpoint.file==a:file && l:breakpoint.line==a:line + call remove(g:vebugger_breakpoints,l:i) + if !empty(l:debugger) + call l:debugger.addWriteActionAndPerform('std','breakpoints',{ + \'action':'remove', + \'file':(a:file), + \'line':(a:line)}) + endif + call vebugger#std#updateMarksForFile(l:debuggerState,a:file) + return + endif + endfor + call add(g:vebugger_breakpoints,{'file':(a:file),'line':(a:line)}) + if !empty(l:debugger) + call l:debugger.addWriteActionAndPerform('std','breakpoints',{ + \'action':'add', + \'file':(a:file), + \'line':(a:line)}) + endif + call vebugger#std#updateMarksForFile(l:debuggerState,a:file) endfunction "Clear all breakpoints function! vebugger#std#clearBreakpoints() - let l:debugger=vebugger#getActiveDebugger() - let l:debuggerState=empty(l:debugger) ? {} : l:debugger.state - let l:files=[] - for l:breakpoint in g:vebugger_breakpoints - if index(l:files,l:breakpoint.file)<0 - call add(l:files,l:breakpoint.file) - endif - call vebugger#addWriteAction('std','breakpoints',extend({'action':'remove'},l:breakpoint)) - endfor - call vebugger#performWriteActions() - let g:vebugger_breakpoints=[] - for l:file in l:files - call vebugger#std#updateMarksForFile(l:debuggerState,l:file) - endfor -endfunction - -"Ask the active debugger to evaluate an expression -function! vebugger#std#eval(expression) - let l:debugger=vebugger#getActiveDebugger() - if !empty(l:debugger) && !empty(l:debugger.std_eval) - call l:debugger.std_eval(a:expression) - endif -endfunction - -"Ask the active debugger to execute a statement -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 + let l:debugger=vebugger#getActiveDebugger() + let l:debuggerState=empty(l:debugger) ? {} : l:debugger.state + let l:files=[] + for l:breakpoint in g:vebugger_breakpoints + if index(l:files,l:breakpoint.file)<0 + call add(l:files,l:breakpoint.file) + endif + if !empty(l:debugger) + call l:debugger.addWriteAction('std','breakpoints',extend({'action':'remove'},l:breakpoint)) + endif + endfor + if !empty(l:debugger) + call l:debugger.performWriteActions() + endif + let g:vebugger_breakpoints=[] + for l:file in l:files + call vebugger#std#updateMarksForFile(l:debuggerState,l:file) + endfor endfunction diff --git a/plugin/vebugger.vim b/plugin/vebugger.vim index 6f9449d..b78bcb5 100644 --- a/plugin/vebugger.vim +++ b/plugin/vebugger.vim @@ -1,25 +1,25 @@ -command! -nargs=1 VBGrawWrite call vebugger#writeLine() +command! -nargs=1 VBGrawWrite call vebugger#userAction('writeLine', ) command! -nargs=0 VBGkill call vebugger#killDebugger() -command! -nargs=0 VBGstepIn call vebugger#setWriteActionAndPerform('std','flow','stepin') -command! -nargs=0 VBGstepOver call vebugger#setWriteActionAndPerform('std','flow','stepover') -command! -nargs=0 VBGstepOut call vebugger#setWriteActionAndPerform('std','flow','stepout') -command! -nargs=0 VBGcontinue call vebugger#setWriteActionAndPerform('std','flow','continue') +command! -nargs=0 VBGstepIn call vebugger#userAction('setWriteActionAndPerform', 'std', 'flow', 'stepin') +command! -nargs=0 VBGstepOver call vebugger#userAction('setWriteActionAndPerform', 'std', 'flow', 'stepover') +command! -nargs=0 VBGstepOut call vebugger#userAction('setWriteActionAndPerform', 'std', 'flow', 'stepout') +command! -nargs=0 VBGcontinue call vebugger#userAction('setWriteActionAndPerform', 'std', 'flow', 'continue') -command! -nargs=0 VBGtoggleTerminalBuffer call vebugger#toggleTerminalBuffer() +command! -nargs=0 VBGtoggleTerminalBuffer call vebugger#userAction('toggleTerminalBuffer') command! -nargs=+ -complete=file VBGtoggleBreakpoint call vebugger#std#toggleBreakpoint() command! -nargs=0 VBGtoggleBreakpointThisLine call vebugger#std#toggleBreakpoint(expand('%:~:.'),line('.')) command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints() -command! -nargs=1 VBGeval call vebugger#std#eval() -command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('')) -command! -nargs=1 VBGexecute call vebugger#std#execute() +command! -nargs=1 VBGeval call vebugger#userAction('std_eval', ) +command! -nargs=0 VBGevalWordUnderCursor call vebugger#userAction('std_eval', expand('')) +command! -nargs=1 VBGexecute call vebugger#userAction('std_execute', ) -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! -range -nargs=0 VBGevalSelectedText call vebugger#userAction('std_eval', vebugger#util#get_visual_selection()) +command! -range -nargs=0 VBGexecuteSelectedText call vebugger#userAction('std_execute', vebugger#util#get_visual_selection()) +command! -range -nargs=0 VBGrawWriteSelectedText call vebugger#userAction('writeLine', vebugger#util#get_visual_selection()) command! -nargs=+ -complete=file VBGstartGDB call vebugger#gdb#start([][0],{'args':[][1:]}) function! s:attachGDB(...)