2014-02-07 17:51:13 -05:00
|
|
|
function! vebugger#gdb#start(binaryFile,args)
|
2014-06-23 18:46:03 -04:00
|
|
|
let l:debugger=vebugger#std#startDebugger(shellescape(vebugger#util#getToolFullPath('gdb',get(a:args,'version'),'gdb'))
|
2014-05-23 10:43:01 -04:00
|
|
|
\.' -i mi --silent '.fnameescape(a:binaryFile))
|
2014-02-07 17:51:13 -05:00
|
|
|
let l:debugger.state.gdb={}
|
|
|
|
|
2014-05-16 10:42:22 -04:00
|
|
|
|
|
|
|
let l:debugger.pipes.err.annotation = "err&prg\t\t"
|
2014-02-08 15:58:34 -05:00
|
|
|
call l:debugger.writeLine("set width 0")
|
2014-02-07 17:51:13 -05:00
|
|
|
call l:debugger.writeLine("define hook-stop\nwhere\nend")
|
2014-05-16 10:42:22 -04:00
|
|
|
|
2014-05-16 16:31:09 -04:00
|
|
|
if get(a:args,'pid') "Attach to process
|
|
|
|
call l:debugger.writeLine('attach '.string(a:args.pid))
|
2015-02-15 00:45:00 -05:00
|
|
|
elseif has_key(a:args,'con') "Attach to gdbserver
|
|
|
|
call l:debugger.writeLine('target remote '.a:args.con)
|
2014-05-16 16:31:09 -04:00
|
|
|
else
|
2014-05-17 12:23:15 -04:00
|
|
|
call l:debugger.writeLine('set args '.vebugger#util#commandLineArgsForProgram(a:args).' 1>&2')
|
2014-05-22 10:21:31 -04:00
|
|
|
if !has('win32')
|
|
|
|
call vebugger#std#openShellBuffer(l:debugger)
|
|
|
|
endif
|
2014-06-23 17:05:51 -04:00
|
|
|
|
|
|
|
if has_key(a:args,'entry')
|
|
|
|
call l:debugger.writeLine('tbreak '.a:args.entry)
|
|
|
|
call l:debugger.writeLine('run')
|
|
|
|
else
|
|
|
|
call l:debugger.writeLine('start')
|
|
|
|
endif
|
2014-05-16 16:31:09 -04:00
|
|
|
end
|
2014-02-07 17:51:13 -05:00
|
|
|
|
2014-05-16 10:42:22 -04:00
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
call l:debugger.addReadHandler(function('vebugger#gdb#_readProgramOutput'))
|
|
|
|
call l:debugger.addReadHandler(function('vebugger#gdb#_readWhere'))
|
|
|
|
call l:debugger.addReadHandler(function('vebugger#gdb#_readFinish'))
|
|
|
|
call l:debugger.addReadHandler(function('vebugger#gdb#_readEvaluatedExpressions'))
|
2014-02-07 17:51:13 -05:00
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
call l:debugger.setWriteHandler('std','flow',function('vebugger#gdb#_writeFlow'))
|
|
|
|
call l:debugger.setWriteHandler('std','breakpoints',function('vebugger#gdb#_writeBreakpoints'))
|
|
|
|
call l:debugger.setWriteHandler('std','closeDebugger',function('vebugger#gdb#_closeDebugger'))
|
|
|
|
call l:debugger.setWriteHandler('std','evaluateExpressions',function('vebugger#gdb#_requestEvaluateExpression'))
|
|
|
|
call l:debugger.setWriteHandler('std','executeStatements',function('vebugger#gdb#_executeStatements'))
|
2014-02-07 17:51:13 -05:00
|
|
|
|
|
|
|
call l:debugger.generateWriteActionsFromTemplate()
|
|
|
|
|
|
|
|
call l:debugger.std_addAllBreakpointActions(g:vebugger_breakpoints)
|
|
|
|
|
|
|
|
return l:debugger
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:findFolderFromStackTrace(src,nameFromStackTrace)
|
|
|
|
let l:path=a:src
|
|
|
|
for l:dirname in split(a:nameFromStackTrace,'\.')
|
|
|
|
let l:nextPath=l:path.'/'.fnameescape(l:dirname)
|
|
|
|
if empty(glob(l:nextPath))
|
|
|
|
return l:path
|
|
|
|
endif
|
|
|
|
let l:path=l:nextPath
|
|
|
|
endfor
|
|
|
|
return l:path
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_readProgramOutput(pipeName,line,readResult,debugger)
|
2014-05-16 10:42:22 -04:00
|
|
|
if 'err'==a:pipeName
|
|
|
|
\&&a:line!~'\v^[=~*&^]'
|
|
|
|
\&&a:line!~'\V(gdb)'
|
|
|
|
let a:readResult.std.programOutput={'line':a:line}
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_readWhere(pipeName,line,readResult,debugger)
|
2014-02-07 17:51:13 -05:00
|
|
|
if 'out'==a:pipeName
|
2014-08-29 17:40:21 -04:00
|
|
|
"let l:matches=matchlist(a:line,'\v^\~"#(\d+)\s+(.+)\s+\(.*\)\s+at\s+([^:]+):(\d+)')
|
|
|
|
let l:matches=matchlist(a:line,'\v^\*stopped.*fullname\=\"([^"]+)\",line\=\"(\d+)"')
|
|
|
|
if 2<len(l:matches)
|
|
|
|
let l:file=l:matches[1]
|
2014-02-07 17:51:13 -05:00
|
|
|
let l:file=fnamemodify(l:file,':~:.')
|
2014-08-29 17:40:21 -04:00
|
|
|
let a:readResult.std.location={
|
2014-02-07 17:51:13 -05:00
|
|
|
\'file':(l:file),
|
2014-08-29 17:40:21 -04:00
|
|
|
\'line':str2nr(l:matches[2])}
|
2014-02-07 17:51:13 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_readFinish(pipeName,line,readResult,debugger)
|
2014-05-16 16:31:09 -04:00
|
|
|
if a:line=~'\c\V\^~"[Inferior \.\*exited normally]'
|
2014-02-07 17:51:13 -05:00
|
|
|
let a:readResult.std.programFinish={'finish':1}
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_writeFlow(writeAction,debugger)
|
2014-02-07 17:51:13 -05:00
|
|
|
if 'stepin'==a:writeAction
|
|
|
|
call a:debugger.writeLine('step')
|
|
|
|
elseif 'stepover'==a:writeAction
|
|
|
|
call a:debugger.writeLine('next')
|
|
|
|
elseif 'stepout'==a:writeAction
|
|
|
|
call a:debugger.writeLine('finish')
|
|
|
|
elseif 'continue'==a:writeAction
|
|
|
|
call a:debugger.writeLine('continue')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_closeDebugger(writeAction,debugger)
|
2014-02-07 17:51:13 -05:00
|
|
|
call a:debugger.writeLine('quit')
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_writeBreakpoints(writeAction,debugger)
|
2014-02-07 17:51:13 -05:00
|
|
|
for l:breakpoint in a:writeAction
|
|
|
|
if 'add'==(l:breakpoint.action)
|
|
|
|
call a:debugger.writeLine('break '.fnameescape(l:breakpoint.file).':'.l:breakpoint.line)
|
|
|
|
elseif 'remove'==l:breakpoint.action
|
|
|
|
call a:debugger.writeLine('clear '.fnameescape(l:breakpoint.file).':'.l:breakpoint.line)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_requestEvaluateExpression(writeAction,debugger)
|
2014-02-07 17:51:13 -05:00
|
|
|
for l:evalAction in a:writeAction
|
|
|
|
call a:debugger.writeLine('print '.l:evalAction.expression)
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_executeStatements(writeAction,debugger)
|
2014-05-16 16:58:02 -04:00
|
|
|
for l:evalAction in a:writeAction
|
|
|
|
if has_key(l:evalAction,'statement')
|
2014-05-19 12:57:36 -04:00
|
|
|
"Use eval to run the statement - but first we need to remove the ;
|
|
|
|
call a:debugger.writeLine('print '.substitute(l:evalAction.statement,'\v;\s*$','',''))
|
2014-05-16 16:58:02 -04:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2015-01-23 19:12:49 -05:00
|
|
|
function! vebugger#gdb#_readEvaluatedExpressions(pipeName,line,readResult,debugger) dict
|
2014-02-07 17:51:13 -05:00
|
|
|
if 'out'==a:pipeName
|
2014-05-16 10:42:22 -04:00
|
|
|
if has_key(self,'nextExpressionToBePrinted')
|
|
|
|
let l:matches=matchlist(a:line,'\v^\~"\$(\d+) \= (.*)"$')
|
|
|
|
if 2<len(l:matches)
|
|
|
|
let l:expression=l:matches[1]
|
|
|
|
let l:value=l:matches[2]
|
|
|
|
let a:readResult.std.evaluatedExpression={
|
|
|
|
\'expression':self.nextExpressionToBePrinted,
|
|
|
|
\'value':(s:unescapeString(l:value))}
|
|
|
|
endif
|
|
|
|
call remove(self,'nextExpressionToBePrinted')
|
|
|
|
else
|
|
|
|
let l:matches=matchlist(a:line,'\v^\&"print (.{-})(\\r)?(\\n)?"$')
|
|
|
|
if 1<len(l:matches)
|
|
|
|
let self.nextExpressionToBePrinted=s:unescapeString(l:matches[1])
|
|
|
|
endif
|
2014-02-07 17:51:13 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
2014-05-16 10:42:22 -04:00
|
|
|
|
|
|
|
function! s:unescapeString(str)
|
|
|
|
let l:result=a:str
|
|
|
|
let l:result=substitute(l:result,'\\"','"','g')
|
|
|
|
let l:result=substitute(l:result,'\\t',"\t",'g')
|
|
|
|
return l:result
|
|
|
|
endfunction
|