Add attach-to-running-process mode for GDB
This commit is contained in:
parent
7383a2b65a
commit
b5cbffd7bc
@ -1,18 +1,31 @@
|
|||||||
|
function! vebugger#gdb#searchAndAttach(binaryFile)
|
||||||
|
let l:processId=vebugger#util#selectProcessOfFile(a:binaryFile)
|
||||||
|
if 0<l:processId
|
||||||
|
call vebugger#gdb#start(a:binaryFile,{'pid':l:processId})
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! vebugger#gdb#start(binaryFile,args)
|
function! vebugger#gdb#start(binaryFile,args)
|
||||||
let l:debugger=vebugger#std#startDebugger(
|
"let l:debugger=vebugger#std#startDebugger(
|
||||||
\(has_key(a:args,'command')
|
"\(has_key(a:args,'command')
|
||||||
\? (a:args.command)
|
"\? (a:args.command)
|
||||||
\: 'gdb -i mi --silent '.fnameescape(a:binaryFile)))
|
"\: 'gdb -i mi --silent '.fnameescape(a:binaryFile)))
|
||||||
|
|
||||||
|
let l:debugger=vebugger#std#startDebugger('gdb -i mi --silent '.fnameescape(a:binaryFile))
|
||||||
let l:debugger.state.gdb={}
|
let l:debugger.state.gdb={}
|
||||||
|
|
||||||
call l:debugger.writeLine("set args 1>&2")
|
|
||||||
|
|
||||||
let l:debugger.pipes.err.annotation = "err&prg\t\t"
|
let l:debugger.pipes.err.annotation = "err&prg\t\t"
|
||||||
call l:debugger.writeLine("set width 0")
|
call l:debugger.writeLine("set width 0")
|
||||||
call l:debugger.writeLine("define hook-stop\nwhere\nend")
|
call l:debugger.writeLine("define hook-stop\nwhere\nend")
|
||||||
|
|
||||||
call vebugger#std#openShellBuffer(l:debugger)
|
if get(a:args,'pid') "Attach to process
|
||||||
call l:debugger.writeLine("start")
|
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'))
|
call l:debugger.addReadHandler(function('s:readProgramOutput'))
|
||||||
@ -75,7 +88,7 @@ function! s:readWhere(pipeName,line,readResult,debugger)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:readFinish(pipeName,line,readResult,debugger)
|
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}
|
let a:readResult.std.programFinish={'finish':1}
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
33
autoload/vebugger/util.vim
Normal file
33
autoload/vebugger/util.vim
Normal file
@ -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<len(l:resultLines)
|
||||||
|
throw 'Too many matching processes found'
|
||||||
|
endif
|
||||||
|
let l:resultLines[0]=' '.l:resultLines[0]
|
||||||
|
for l:i in range(1,len(l:resultLines)-1)
|
||||||
|
let l:resultLines[l:i]=repeat(' ',3-len(l:i)).l:i.') '.(l:resultLines[l:i])
|
||||||
|
endfor
|
||||||
|
let l:chosenId=inputlist(l:resultLines)
|
||||||
|
if l:chosenId<1
|
||||||
|
\|| len(l:resultLines)<=l:chosenId
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
let l:chosenLine=l:resultLines[l:chosenId]
|
||||||
|
return str2nr(matchlist(l:chosenLine,'\v^\s*\d+\)\s+(\d+)')[1])
|
||||||
|
endfunction
|
@ -16,21 +16,11 @@ command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints()
|
|||||||
command! -nargs=1 VBGeval call vebugger#std#eval(<q-args>)
|
command! -nargs=1 VBGeval call vebugger#std#eval(<q-args>)
|
||||||
command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('<cword>'))
|
command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('<cword>'))
|
||||||
|
|
||||||
"Shamefully stolen from http://stackoverflow.com/a/6271254/794380
|
command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(vebugger#util#get_visual_selection())
|
||||||
function! s:get_visual_selection()
|
command! -range -nargs=0 VBGrawWriteSelectedText call vebugger#writeLine(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
|
|
||||||
|
|
||||||
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! -nargs=1 -complete=file VBGstartGDB call vebugger#gdb#start(<q-args>,{})
|
command! -nargs=1 -complete=file VBGstartGDB call vebugger#gdb#start(<q-args>,{})
|
||||||
|
command! -nargs=1 -complete=file VBGattachGDB call vebugger#gdb#searchAndAttach(<q-args>)
|
||||||
command! -nargs=1 -complete=file VBGstartPDB call vebugger#pdb#start(<q-args>,{})
|
command! -nargs=1 -complete=file VBGstartPDB call vebugger#pdb#start(<q-args>,{})
|
||||||
command! -nargs=1 -complete=file VBGstartRDebug call vebugger#rdebug#start(<q-args>,{})
|
command! -nargs=1 -complete=file VBGstartRDebug call vebugger#rdebug#start(<q-args>,{})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user