Added breakpoints support
This commit is contained in:
parent
6f64ff6fda
commit
07fb6eb21a
@ -185,6 +185,10 @@ function! s:f_debugger.setWriteAction(namespace,name,value) dict
|
||||
let self.writeActions[a:namespace][a:name]=a:value
|
||||
endfunction
|
||||
|
||||
function! s:f_debugger.addWriteAction(namespace,name,value) dict
|
||||
call add(self.writeActions[a:namespace][a:name],a:value)
|
||||
endfunction
|
||||
|
||||
function! vebugger#createDebugger(command)
|
||||
|
||||
let l:debugger=deepcopy(s:f_debugger)
|
||||
@ -257,7 +261,11 @@ function! vebugger#toggleLogBuffer()
|
||||
endfunction
|
||||
|
||||
function! vebugger#getActiveDebugger()
|
||||
if exists('s:debugger')
|
||||
return s:debugger
|
||||
else
|
||||
return {}
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! vebugger#setWriteAction(namespace,name,value)
|
||||
@ -266,6 +274,12 @@ function! vebugger#setWriteAction(namespace,name,value)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! vebugger#addWriteAction(namespace,name,value)
|
||||
if exists('s:debugger')
|
||||
call s:debugger.addWriteAction(a:namespace,a:name,a:value)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! vebugger#performWriteActions()
|
||||
if exists('s:debugger')
|
||||
call s:debugger.performWriteActions()
|
||||
@ -276,3 +290,8 @@ function! vebugger#setWriteActionAndPerform(namespace,name,value)
|
||||
call vebugger#setWriteAction(a:namespace,a:name,a:value)
|
||||
call vebugger#performWriteActions()
|
||||
endfunction
|
||||
|
||||
function! vebugger#addWriteActionAndPerform(namespace,name,value)
|
||||
call vebugger#addWriteAction(a:namespace,a:name,a:value)
|
||||
call vebugger#performWriteActions()
|
||||
endfunction
|
||||
|
@ -3,9 +3,14 @@ function! vebugger#jdb#start(entryClass,args)
|
||||
\has_key(a:args,'classpath')
|
||||
\? ' -classpath '.fnameescape(a:args.classpath)
|
||||
\: ''))
|
||||
let l:debugger.state.jdb={}
|
||||
if has_key(a:args,'srcpath')
|
||||
let l:debugger.state.std.srcpath=a:args.srcpath
|
||||
let l:debugger.state.jdb.srcpath=a:args.srcpath
|
||||
else
|
||||
let l:debugger.state.jdb.srcpath='.'
|
||||
endif
|
||||
let l:debugger.state.jdb.filesToClassesMap={}
|
||||
|
||||
call l:debugger.writeLine('stop on '.a:entryClass.'.main')
|
||||
call l:debugger.writeLine('run '.a:entryClass)
|
||||
call l:debugger.writeLine('monitor where')
|
||||
@ -13,9 +18,12 @@ function! vebugger#jdb#start(entryClass,args)
|
||||
call l:debugger.addReadHandler(function('s:readWhere'))
|
||||
|
||||
call l:debugger.setWriteHandler('std','flow',function('s:writeFlow'))
|
||||
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
|
||||
|
||||
call l:debugger.generateWriteActionsFromTemplate()
|
||||
|
||||
call l:debugger.std_addAllBreakpointActions(g:vebugger_breakpoints)
|
||||
|
||||
return l:debugger
|
||||
endfunction
|
||||
|
||||
@ -35,7 +43,7 @@ function! s:readWhere(pipeName,line,readResult,debugger)
|
||||
if 'out'==a:pipeName
|
||||
let l:matches=matchlist(a:line,'\v\s*\[(\d+)]\s*(\S+)\s*\(([^:]*):(\d*)\)')
|
||||
if 4<len(l:matches)
|
||||
let l:file=s:findFolderFromStackTrace(a:debugger.state.std.srcpath,l:matches[2]).'/'.l:matches[3]
|
||||
let l:file=s:findFolderFromStackTrace(a:debugger.state.jdb.srcpath,l:matches[2]).'/'.l:matches[3]
|
||||
let l:file=fnamemodify(l:file,':~:.')
|
||||
let l:frameNumber=str2nr(l:matches[1])
|
||||
if 1==l:frameNumber " first stackframe is the current location
|
||||
@ -63,3 +71,32 @@ function! s:writeFlow(writeAction,debugger)
|
||||
call a:debugger.writeLine('cont')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
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
|
||||
|
@ -1,6 +1,7 @@
|
||||
let g:vebugger_breakpoints=[]
|
||||
|
||||
function! vebugger#std#setStandardState(debugger)
|
||||
let a:debugger.state.std={
|
||||
\'srcpath':'.',
|
||||
\'location':{},
|
||||
\'callstack':[]}
|
||||
endfunction
|
||||
@ -13,7 +14,8 @@ endfunction
|
||||
|
||||
function! vebugger#std#setStandardWriteactionsTemplate(debugger)
|
||||
let a:debugger.writeActionsTemplate.std={
|
||||
\'flow':''}
|
||||
\'flow':'',
|
||||
\'breakpoints':[]}
|
||||
endfunction
|
||||
|
||||
function! vebugger#std#addStandardFunctions(debugger)
|
||||
@ -54,8 +56,13 @@ endfunction
|
||||
|
||||
|
||||
let s:standardFunctions={}
|
||||
function s:standardFunctions.relativeSrcPath(filename) dict
|
||||
return fnamemodify(self.state.std.srcpath.'/'.a:filename,':~:.')
|
||||
function! s:standardFunctions.addAllBreakpointActions(breakpoints) dict
|
||||
for l:breakpoint in a:breakpoints
|
||||
call self.addWriteAction('std','breakpoints',{
|
||||
\'action':'add',
|
||||
\'file':(l:breakpoint.file),
|
||||
\'line':(l:breakpoint.line)})
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
let s:standardThinkHandlers={}
|
||||
@ -92,17 +99,70 @@ endfunction
|
||||
|
||||
let s:standardCloseHandlers={}
|
||||
function! s:standardCloseHandlers.removeCurrentMarker(debugger) dict
|
||||
let a:debugger.state.std.location={}
|
||||
sign unplace 1
|
||||
endfunction
|
||||
|
||||
sign define vebugger_current text=->
|
||||
sign define vebugger_breakpoint text=** linehl=ColorColumn
|
||||
function! vebugger#std#updateMarksForFile(state,filename)
|
||||
if bufexists(a:filename)
|
||||
exe 'sign unplace * file='.fnameescape(a:filename)
|
||||
|
||||
for l:breakpoint in g:vebugger_breakpoints
|
||||
if l:breakpoint.file==a:filename
|
||||
exe 'sign place 2 name=vebugger_breakpoint line='.l:breakpoint.line.' file='.fnameescape(l:breakpoint.file)
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !empty(a:state)
|
||||
if !empty(a:state.std.location)
|
||||
if a:state.std.location.file==a:filename
|
||||
exe 'sign place 1 name=vebugger_current line='.a:state.std.location.line.' file='.fnameescape(a:filename)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
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)
|
||||
endfunction
|
||||
|
||||
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
|
||||
|
@ -8,6 +8,9 @@ command! -nargs=0 VBGstepOut call vebugger#setWriteActionAndPerform('std','flow'
|
||||
command! -nargs=0 VBGcontinue call vebugger#setWriteActionAndPerform('std','flow','continue')
|
||||
|
||||
command! -nargs=0 VBGtoggleLogBuffer call vebugger#toggleLogBuffer()
|
||||
command! -nargs=+ VBGtoggleBreakpoint call vebugger#std#toggleBreakpoint(<f-args>)
|
||||
command! -nargs=0 VBGtoggleBreakpointThisLine call vebugger#std#toggleBreakpoint(expand('%:~:.'),line('.'))
|
||||
command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints()
|
||||
|
||||
if exists('g:vebugger_leader')
|
||||
if !empty(g:vebugger_leader)
|
||||
@ -15,7 +18,9 @@ if exists('g:vebugger_leader')
|
||||
\'i':'VBGstepIn',
|
||||
\'o':'VBGstepOver',
|
||||
\'O':'VBGstepOut',
|
||||
\'c':'VBGcontinue'})
|
||||
\'c':'VBGcontinue',
|
||||
\'l':'VBGtoggleLogBuffer',
|
||||
\'b':'VBGtoggleBreakpointThisLine'})
|
||||
exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
||||
endfor
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user