From 7d1703ca32f5e6d9d28c4aaa6abd25e850accc20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20M=C3=A5rtensson?= Date: Wed, 11 Apr 2018 15:56:47 +0200 Subject: [PATCH] add support for attaching JDB to a running process --- autoload/vebugger/jdb.vim | 18 ++++++++++++++---- doc/vebugger.txt | 9 +++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/autoload/vebugger/jdb.vim b/autoload/vebugger/jdb.vim index 319fe3a..494d5ff 100644 --- a/autoload/vebugger/jdb.vim +++ b/autoload/vebugger/jdb.vim @@ -1,6 +1,7 @@ function! vebugger#jdb#start(entryClass,args) let l:debugger=vebugger#std#startDebugger(shellescape(vebugger#util#getToolFullPath('jdb',get(a:args,'version'),'jdb')) - \.(has_key(a:args,'classpath') ? ' -classpath '.fnameescape(a:args.classpath) : '')) + \.(has_key(a:args,'classpath') && !has_key(a:args,'attach') ? ' -classpath '.fnameescape(a:args.classpath) : '') + \.(has_key(a:args,'attach') ? ' -attach '.shellescape(a:args.attach) : '')) let l:debugger.state.jdb={} if has_key(a:args,'srcpath') let l:debugger.state.jdb.srcpath=a:args.srcpath @@ -9,10 +10,14 @@ function! vebugger#jdb#start(entryClass,args) endif let l:debugger.state.jdb.filesToClassesMap={} - call l:debugger.writeLine('stop on '.a:entryClass.'.main') - call l:debugger.writeLine('run '.a:entryClass.' '.vebugger#util#commandLineArgsForProgram(a:args)) + if !has_key(a:args,'attach') + call l:debugger.writeLine('stop on '.a:entryClass.'.main') + call l:debugger.writeLine('run '.a:entryClass.' '.vebugger#util#commandLineArgsForProgram(a:args)) + else + call l:debugger.writeLine('run') + endif call l:debugger.writeLine('monitor where') - if !has('win32') + if !has('win32') && !has_key(a:args,'attach') call vebugger#std#openShellBuffer(l:debugger) endif @@ -33,6 +38,11 @@ function! vebugger#jdb#start(entryClass,args) return l:debugger endfunction +function! vebugger#jdb#attach(address,args) + let a:args.attach = a:address + call vebugger#jdb#start('', a:args) +endfunction + function! vebugger#jdb#_readProgramOutput(pipeName,line,readResult,debugger) dict if 'out'==a:pipeName if a:line=~'\v^\> \>' diff --git a/doc/vebugger.txt b/doc/vebugger.txt index 697c3c6..d119363 100644 --- a/doc/vebugger.txt +++ b/doc/vebugger.txt @@ -212,6 +212,15 @@ file - it's the name of the class to run. The supported extra arguments are: * "classpath": Where to look for class files * "srcpath": Where to look for source files. You can have multiple srcpaths, passed as a list * "version": The version of the debugger to run + +Alternatively, to attach to a running process you can use *vebugger#jdb#attach* +> + call vebugger#jdb#attach('8000',{ + \'srcpath':'src'}) +< +The first argument here is the the address to attach to, e.g. 127.0.0.1:8000 +or just 8000. It does not support the "args" or "classpath" arguments. + If you don't supply "classpath" and "srcpath", Vebugger will assume you are using the current directory for source files and class files.