diff --git a/autoload/vebugger/gdb.vim b/autoload/vebugger/gdb.vim index d4c6bbd..c61c442 100644 --- a/autoload/vebugger/gdb.vim +++ b/autoload/vebugger/gdb.vim @@ -1,18 +1,31 @@ +function! vebugger#gdb#searchAndAttach(binaryFile) + let l:processId=vebugger#util#selectProcessOfFile(a:binaryFile) + if 0&2") let l:debugger.pipes.err.annotation = "err&prg\t\t" call l:debugger.writeLine("set width 0") call l:debugger.writeLine("define hook-stop\nwhere\nend") - call vebugger#std#openShellBuffer(l:debugger) - call l:debugger.writeLine("start") + if get(a:args,'pid') "Attach to process + call l:debugger.writeLine('attach '.string(a:args.pid)) + else + call l:debugger.writeLine("set args 1>&2") + call vebugger#std#openShellBuffer(l:debugger) + call l:debugger.writeLine('start') + end call l:debugger.addReadHandler(function('s:readProgramOutput')) @@ -75,7 +88,7 @@ function! s:readWhere(pipeName,line,readResult,debugger) endfunction function! s:readFinish(pipeName,line,readResult,debugger) - if a:line=~'\c\V\^"[Inferior \.\*exited normally]' + if a:line=~'\c\V\^~"[Inferior \.\*exited normally]' let a:readResult.std.programFinish={'finish':1} endif endfunction diff --git a/autoload/vebugger/util.vim b/autoload/vebugger/util.vim new file mode 100644 index 0000000..52fc1ab --- /dev/null +++ b/autoload/vebugger/util.vim @@ -0,0 +1,33 @@ + +"Shamefully stolen from http://stackoverflow.com/a/6271254/794380 +function! vebugger#util#get_visual_selection() + " Why is this not a built-in Vim script function?! + let [lnum1, col1] = getpos("'<")[1:2] + let [lnum2, col2] = getpos("'>")[1:2] + let lines = getline(lnum1, lnum2) + let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] + let lines[0] = lines[0][col1 - 1:] + return join(lines, "\n") +endfunction + +function! vebugger#util#selectProcessOfFile(ofFile) + let l:fileName=fnamemodify(a:ofFile,':t') + let l:resultLines=split(vimproc#system('ps -o pid,user,comm,start,state,tt -C '.fnameescape(l:fileName)),'\r\n\|\n\|\r') + if len(l:resultLines)<=1 + throw 'No matching process found' + endif + if &lines) command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('')) -"Shamefully stolen from http://stackoverflow.com/a/6271254/794380 -function! s:get_visual_selection() - " Why is this not a built-in Vim script function?! - let [lnum1, col1] = getpos("'<")[1:2] - let [lnum2, col2] = getpos("'>")[1:2] - let lines = getline(lnum1, lnum2) - let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] - let lines[0] = lines[0][col1 - 1:] - return join(lines, "\n") -endfunction - -command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(s:get_visual_selection()) -command! -range -nargs=0 VBGrawWriteSelectedText call vebugger#writeLine(s:get_visual_selection()) +command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(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(,{}) +command! -nargs=1 -complete=file VBGattachGDB call vebugger#gdb#searchAndAttach() command! -nargs=1 -complete=file VBGstartPDB call vebugger#pdb#start(,{}) command! -nargs=1 -complete=file VBGstartRDebug call vebugger#rdebug#start(,{})