2013-12-25 13:33:12 -05:00
|
|
|
function! vebugger#jdb#start(entryClass,args)
|
2014-01-17 18:21:02 -05:00
|
|
|
let l:debugger=vebugger#std#startDebugger(
|
|
|
|
\(has_key(a:args,'command')
|
|
|
|
\? (a:args.command)
|
|
|
|
\: 'jdb')
|
|
|
|
\.(has_key(a:args,'classpath')
|
2013-12-25 13:33:12 -05:00
|
|
|
\? ' -classpath '.fnameescape(a:args.classpath)
|
|
|
|
\: ''))
|
2013-12-28 15:23:33 -05:00
|
|
|
let l:debugger.state.jdb={}
|
2013-12-25 13:33:12 -05:00
|
|
|
if has_key(a:args,'srcpath')
|
2013-12-28 15:23:33 -05:00
|
|
|
let l:debugger.state.jdb.srcpath=a:args.srcpath
|
|
|
|
else
|
|
|
|
let l:debugger.state.jdb.srcpath='.'
|
2013-12-25 13:33:12 -05:00
|
|
|
endif
|
2013-12-28 15:23:33 -05:00
|
|
|
let l:debugger.state.jdb.filesToClassesMap={}
|
|
|
|
|
2013-12-25 13:33:12 -05:00
|
|
|
call l:debugger.writeLine('stop on '.a:entryClass.'.main')
|
|
|
|
call l:debugger.writeLine('run '.a:entryClass)
|
|
|
|
call l:debugger.writeLine('monitor where')
|
|
|
|
|
|
|
|
call l:debugger.addReadHandler(function('s:readWhere'))
|
2014-02-08 15:58:34 -05:00
|
|
|
call l:debugger.addReadHandler(function('s:readException'))
|
2014-01-17 17:36:13 -05:00
|
|
|
call l:debugger.addReadHandler(function('s:readEvaluatedExpressions'))
|
2013-12-25 13:33:12 -05:00
|
|
|
|
2013-12-27 16:52:57 -05:00
|
|
|
call l:debugger.setWriteHandler('std','flow',function('s:writeFlow'))
|
2013-12-28 15:23:33 -05:00
|
|
|
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
|
2014-01-17 17:36:13 -05:00
|
|
|
call l:debugger.setWriteHandler('std','evaluateExpressions',function('s:requestEvaluateExpression'))
|
2013-12-27 16:52:57 -05:00
|
|
|
|
|
|
|
call l:debugger.generateWriteActionsFromTemplate()
|
|
|
|
|
2013-12-28 15:23:33 -05:00
|
|
|
call l:debugger.std_addAllBreakpointActions(g:vebugger_breakpoints)
|
|
|
|
|
2013-12-25 13:33:12 -05:00
|
|
|
return l:debugger
|
|
|
|
endfunction
|
|
|
|
|
2013-12-27 15:19:29 -05:00
|
|
|
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
|
|
|
|
|
2013-12-25 13:33:12 -05:00
|
|
|
function! s:readWhere(pipeName,line,readResult,debugger)
|
|
|
|
if 'out'==a:pipeName
|
2013-12-27 15:19:29 -05:00
|
|
|
let l:matches=matchlist(a:line,'\v\s*\[(\d+)]\s*(\S+)\s*\(([^:]*):(\d*)\)')
|
|
|
|
if 4<len(l:matches)
|
2013-12-28 15:23:33 -05:00
|
|
|
let l:file=s:findFolderFromStackTrace(a:debugger.state.jdb.srcpath,l:matches[2]).'/'.l:matches[3]
|
2013-12-27 16:09:58 -05:00
|
|
|
let l:file=fnamemodify(l:file,':~:.')
|
|
|
|
let l:frameNumber=str2nr(l:matches[1])
|
|
|
|
if 1==l:frameNumber " first stackframe is the current location
|
2013-12-27 15:19:29 -05:00
|
|
|
let a:readResult.std.location={
|
|
|
|
\'file':(l:file),
|
2014-01-17 18:21:02 -05:00
|
|
|
\'line':str2nr(l:matches[4])}
|
2013-12-27 15:19:29 -05:00
|
|
|
endif
|
2013-12-27 16:09:58 -05:00
|
|
|
let a:readResult.std.callstack={
|
|
|
|
\'clearOld':('1'==l:frameNumber),
|
|
|
|
\'add':'after',
|
|
|
|
\'file':(l:file),
|
2014-01-17 18:21:02 -05:00
|
|
|
\'line':str2nr(l:matches[4])}
|
2013-12-25 13:33:12 -05:00
|
|
|
endif
|
2013-12-27 16:52:57 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2014-02-08 15:58:34 -05:00
|
|
|
function! s:readException(pipeName,line,readResult,debugger)
|
|
|
|
if 'out'==a:pipeName
|
|
|
|
let l:matches=matchlist(a:line,'\vException occurred:\s+(\S+)')
|
|
|
|
if 1<len(l:matches)
|
|
|
|
let a:readResult.std.exception={
|
|
|
|
\'message':(l:matches[1])}
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-12-27 16:52:57 -05:00
|
|
|
function! s:writeFlow(writeAction,debugger)
|
|
|
|
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('step up')
|
|
|
|
elseif 'continue'==a:writeAction
|
|
|
|
call a:debugger.writeLine('cont')
|
|
|
|
endif
|
2013-12-25 13:33:12 -05:00
|
|
|
endfunction
|
2013-12-28 15:23:33 -05:00
|
|
|
|
|
|
|
function! s:getClassNameFromFile(filename)
|
|
|
|
let l:className=fnamemodify(a:filename,':t:r') " Get only the name of the file, without path or extension
|
|
|
|
for l:line in readfile(a:filename)
|
|
|
|
let l:matches=matchlist(l:line,'\vpackage\s+(%(\w|\.)+)\s*;')
|
|
|
|
if 1<len(l:matches)
|
|
|
|
return l:matches[1].'.'.l:className
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return l:className
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:writeBreakpoints(writeAction,debugger)
|
|
|
|
for l:breakpoint in a:writeAction
|
|
|
|
let l:class=''
|
|
|
|
if has_key(a:debugger.state.jdb.filesToClassesMap,l:breakpoint.file)
|
|
|
|
let l:class=a:debugger.state.jdb.filesToClassesMap[l:breakpoint.file]
|
|
|
|
else
|
|
|
|
let l:class=s:getClassNameFromFile(l:breakpoint.file)
|
|
|
|
let a:debugger.state.jdb.filesToClassesMap[l:breakpoint.file]=l:class
|
|
|
|
endif
|
|
|
|
|
|
|
|
if 'add'==(l:breakpoint.action)
|
|
|
|
call a:debugger.writeLine('stop at '.l:class.':'.l:breakpoint.line)
|
|
|
|
elseif 'remove'==l:breakpoint.action
|
|
|
|
call a:debugger.writeLine('clear '.l:class.':'.l:breakpoint.line)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
2014-01-17 17:36:13 -05:00
|
|
|
|
|
|
|
function! s:requestEvaluateExpression(writeAction,debugger)
|
|
|
|
for l:evalAction in a:writeAction
|
|
|
|
call a:debugger.writeLine('eval '.l:evalAction.expression)
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:readEvaluatedExpressions(pipeName,line,readResult,debugger)
|
|
|
|
if 'out'==a:pipeName
|
|
|
|
let l:matches=matchlist(a:line,'\v^%(\s*%(%(%(\w|\.)+)\[\d+\] )+)? ([^=]+) \= (.*)$')
|
|
|
|
if 3<len(l:matches)
|
|
|
|
let l:expression=l:matches[1]
|
|
|
|
let l:value=l:matches[2]
|
|
|
|
let a:readResult.std.evaluatedExpression={
|
2014-01-17 18:21:02 -05:00
|
|
|
\'expression':(l:expression),
|
|
|
|
\'value':(l:value)}
|
2014-01-17 17:36:13 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|