org.kohsuke.youdebug
Class VM

java.lang.Object
  extended by org.kohsuke.youdebug.VM
All Implemented Interfaces:
groovy.lang.GroovyObject, Closeable

public class VM
extends Object
implements groovy.lang.GroovyObject, Closeable

Debugger view of a Virtual machine.

Author:
Kohsuke Kawaguchi

Field Summary
static ExceptionBreakpointModifier CAUGHT
           
static ExceptionBreakpointModifier UNCAUGHT
           
 
Constructor Summary
VM(com.sun.jdi.VirtualMachine vm)
           
 
Method Summary
 com.sun.jdi.ReferenceType _(Class c)
          Short hand for {@link #ref(Class)
 com.sun.jdi.ReferenceType _(String c)
          Short hand for {@link #ref(String)
 Object _new(Class c, Object args)
          Creates a new instance of the given type in the remote JVM.
 Object _new(com.sun.jdi.ReferenceType t, Object args)
           
 Object _new(String c, Object args)
          Creates a new instance of the given type in the remote JVM.
 com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(Class c, String fieldName, groovy.lang.Closure body)
          Same as accessWatchpoint(c.name,fieldName,body)
 com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(com.sun.jdi.Field f, groovy.lang.Closure body)
          Sets a breakpoint that fires when the specified field is read.
 com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(String className, String fieldName, groovy.lang.Closure body)
          Sets a breakpoint that fires when the specified field of the specified class is read.
 BundledBreakpointRequest breakpoint(Class className, int line, groovy.lang.Closure c)
          Same as breakpoint(String, int, Closure) except you specify the class by using a reference to the class in this JVM.
 BundledBreakpointRequest breakpoint(com.sun.jdi.ReferenceType type, int line, groovy.lang.Closure body)
          Same as breakpoint(String, int, Closure) except you specify the class by using a remote reference ReferenceType.
 BundledBreakpointRequest breakpoint(String className, int line, groovy.lang.Closure body)
          Sets a break point at the specified line in the specified class, and if it hits, invoke the closure.
 com.sun.jdi.request.ClassPrepareRequest classPrepare(Class clazz, groovy.lang.Closure c)
          Same as classPrepare(String, Closure) except you specify the class by using a reference to the class in this JVM.
 com.sun.jdi.request.ClassPrepareRequest classPrepare(String name, groovy.lang.Closure body)
          Sets a break point to be fired when a class of the specified name is loaded into the JVM.
 void close()
          Shuts down the connection.
static VM current()
          Can be called during event dispatching to obtain the current VM instance.
 void dispatchEvents()
          Dispatches events received from the target JVM until the connection is closed, the remote JVM exits, or the thread ges interrupted.
 void dumpAllThreads()
          Short for dumpAllThreads(System.out)
 void dumpAllThreads(PrintStream out)
          Dumps information about all the threads in the target JVM to the specified object.
 void dumpAllThreads(PrintWriter out)
          Dumps information about all the threads in the target JVM to the specified object.
 void dumpHeap(String path)
          Instructs the target JVM to create a heap dump.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(Class exceptionClass, groovy.lang.Closure c)
          Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(Class exceptionClass, Collection modifiers, groovy.lang.Closure c)
          Same as #exceptionBreakpoint(String, Collection, Closure) except you specify the exception type by a local class of the same name.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(com.sun.jdi.ReferenceType exceptionClass, groovy.lang.Closure c)
          Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(com.sun.jdi.ReferenceType exceptionClass, Collection modifiers, groovy.lang.Closure body)
          Same as #exceptionBreakpoint(String, Collection, Closure) except you specify the exception type by a remote reference of the type.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(String exceptionClass, groovy.lang.Closure c)
          Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.
 com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(String className, Collection modifiers, groovy.lang.Closure c)
          Sets a break point that hits upon an exception.
 void execute(File script)
          Executes the specified YouDebug script.
 void execute(groovy.lang.GroovyCodeSource script)
          Executes the specified YouDebug script.
 void execute(groovy.lang.GroovyCodeSource script, Map variables)
          Executes the given YouDebug script.
 void execute(InputStream script)
          Executes the specified YouDebug script.
 void execute(URL script)
          Executes the specified YouDebug script.
 com.sun.jdi.request.ClassPrepareRequest forEachClass(String className, groovy.lang.Closure body)
          Executes the given closure for each class of the given name.
 com.sun.jdi.event.Event getCurrentEvent()
          Returns the current debugger event that we are dispatching.
 com.sun.jdi.ThreadReference getCurrentThread()
          Returns the thread that raised the current event.
static org.kohsuke.youdebug.Key getHANDLER()
           
 groovy.lang.MetaClass getMetaClass()
           
 Object getProperty(String name)
           
 ThreadList getThreads()
          Gets the list of all threads.
 com.sun.jdi.VirtualMachine getVirtualMachine()
          Access to the underlying JDI VirtualMachine object.
 Object invokeMethod(String name, Object args)
           
 com.sun.jdi.ReferenceType loadClass(Class c)
           
 com.sun.jdi.ReferenceType loadClass(String c)
          Instead of just resolving an existing class, load the specified class in the target JVM and returns its reference.
 com.sun.jdi.request.MethodEntryRequest methodEntryBreakpoint(com.sun.jdi.ReferenceType type, String methodName, groovy.lang.Closure body)
           
 com.sun.jdi.request.MethodEntryRequest methodEntryBreakpoint(String type, String methodName, groovy.lang.Closure body)
           
 com.sun.jdi.request.MethodExitRequest methodExitBreakpoint(com.sun.jdi.ReferenceType type, String methodName, groovy.lang.Closure body)
           
 com.sun.jdi.request.MethodExitRequest methodExitBreakpoint(String type, String methodName, groovy.lang.Closure body)
           
 com.sun.jdi.request.AccessWatchpointRequest modificationWatchpoint(Class c, String fieldName, groovy.lang.Closure body)
          Same as modificationWatchpoint(c.name,fieldName,body)
 com.sun.jdi.request.ModificationWatchpointRequest modificationWatchpoint(com.sun.jdi.Field f, groovy.lang.Closure body)
          Sets a breakpoint that fires when the specified field is updated.
 com.sun.jdi.request.AccessWatchpointRequest modificationWatchpoint(String className, String fieldName, groovy.lang.Closure body)
          Sets a breakpoint that fires when the specified field of the specified class is updated.
 com.sun.jdi.ReferenceType ref(Class c)
          Resolves the same class on the target JVM.
 com.sun.jdi.ReferenceType ref(String className)
          Resolves a class by the name.
 void resume()
           
 void setMetaClass(groovy.lang.MetaClass metaClass)
           
 void setProperty(String name, Object value)
           
 void suspend()
           
 void withFrozenWorld(groovy.lang.Closure c)
          Executes the given closure by suspending the VM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAUGHT

public static final ExceptionBreakpointModifier CAUGHT

UNCAUGHT

public static final ExceptionBreakpointModifier UNCAUGHT
Constructor Detail

VM

public VM(com.sun.jdi.VirtualMachine vm)
Method Detail

getHANDLER

public static final org.kohsuke.youdebug.Key getHANDLER()

getThreads

public ThreadList getThreads()
Gets the list of all threads.

Returns:
this list is live and concurrecy safe.

getVirtualMachine

public com.sun.jdi.VirtualMachine getVirtualMachine()
Access to the underlying JDI VirtualMachine object. Use this method when you want to go down to JDI.

Returns:
never null.

getCurrentThread

public com.sun.jdi.ThreadReference getCurrentThread()
Returns the thread that raised the current event. For example, if the caller is a closure for a break point, this method returns the thread that hit the breakpoint.


getCurrentEvent

public com.sun.jdi.event.Event getCurrentEvent()
Returns the current debugger event that we are dispatching.


dispatchEvents

public void dispatchEvents()
                    throws InterruptedException
Dispatches events received from the target JVM until the connection is closed, the remote JVM exits, or the thread ges interrupted.

Throws:
InterruptedException

classPrepare

public com.sun.jdi.request.ClassPrepareRequest classPrepare(String name,
                                                            groovy.lang.Closure body)
Sets a break point to be fired when a class of the specified name is loaded into the JVM.

The closure will get the ReferenceType object as a parameter, which represents a newly loaded class.

 classPrepare("org.acme.FooBar") { t ->
 ...
 }
 


classPrepare

public com.sun.jdi.request.ClassPrepareRequest classPrepare(Class clazz,
                                                            groovy.lang.Closure c)
Same as classPrepare(String, Closure) except you specify the class by using a reference to the class in this JVM.


breakpoint

public BundledBreakpointRequest breakpoint(String className,
                                           int line,
                                           groovy.lang.Closure body)
                                    throws com.sun.jdi.AbsentInformationException
Sets a break point at the specified line in the specified class, and if it hits, invoke the closure.

Throws:
com.sun.jdi.AbsentInformationException

breakpoint

public BundledBreakpointRequest breakpoint(Class className,
                                           int line,
                                           groovy.lang.Closure c)
                                    throws com.sun.jdi.AbsentInformationException
Same as breakpoint(String, int, Closure) except you specify the class by using a reference to the class in this JVM.

Throws:
com.sun.jdi.AbsentInformationException

breakpoint

public BundledBreakpointRequest breakpoint(com.sun.jdi.ReferenceType type,
                                           int line,
                                           groovy.lang.Closure body)
                                    throws com.sun.jdi.AbsentInformationException
Same as breakpoint(String, int, Closure) except you specify the class by using a remote reference ReferenceType.

Throws:
com.sun.jdi.AbsentInformationException

exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(com.sun.jdi.ReferenceType exceptionClass,
                                                                Collection modifiers,
                                                                groovy.lang.Closure body)
Same as #exceptionBreakpoint(String, Collection, Closure) except you specify the exception type by a remote reference of the type.


exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(String className,
                                                                Collection modifiers,
                                                                groovy.lang.Closure c)
Sets a break point that hits upon an exception.
 exceptionBreakpoint(className) { e ->
 // e references the exception that is thrown
 }
 

Parameters:
modifiers - Optionally specify the kind of exceptions (caught or uncaught) that you want to catch. If this is null or empty, both kinds of exceptions are caught.

exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(Class exceptionClass,
                                                                Collection modifiers,
                                                                groovy.lang.Closure c)
Same as #exceptionBreakpoint(String, Collection, Closure) except you specify the exception type by a local class of the same name.


exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(Class exceptionClass,
                                                                groovy.lang.Closure c)
Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.


exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(com.sun.jdi.ReferenceType exceptionClass,
                                                                groovy.lang.Closure c)
Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.


exceptionBreakpoint

public com.sun.jdi.request.ExceptionRequest exceptionBreakpoint(String exceptionClass,
                                                                groovy.lang.Closure c)
Short for exceptionBreakpoint(exceptionClass,null,c), to get notified for both kinds of exceptions.


methodEntryBreakpoint

public com.sun.jdi.request.MethodEntryRequest methodEntryBreakpoint(com.sun.jdi.ReferenceType type,
                                                                    String methodName,
                                                                    groovy.lang.Closure body)

methodEntryBreakpoint

public com.sun.jdi.request.MethodEntryRequest methodEntryBreakpoint(String type,
                                                                    String methodName,
                                                                    groovy.lang.Closure body)

methodExitBreakpoint

public com.sun.jdi.request.MethodExitRequest methodExitBreakpoint(com.sun.jdi.ReferenceType type,
                                                                  String methodName,
                                                                  groovy.lang.Closure body)

methodExitBreakpoint

public com.sun.jdi.request.MethodExitRequest methodExitBreakpoint(String type,
                                                                  String methodName,
                                                                  groovy.lang.Closure body)

accessWatchpoint

public com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(com.sun.jdi.Field f,
                                                                    groovy.lang.Closure body)
Sets a breakpoint that fires when the specified field is read.


accessWatchpoint

public com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(String className,
                                                                    String fieldName,
                                                                    groovy.lang.Closure body)
Sets a breakpoint that fires when the specified field of the specified class is read.


accessWatchpoint

public com.sun.jdi.request.AccessWatchpointRequest accessWatchpoint(Class c,
                                                                    String fieldName,
                                                                    groovy.lang.Closure body)
Same as accessWatchpoint(c.name,fieldName,body)


modificationWatchpoint

public com.sun.jdi.request.ModificationWatchpointRequest modificationWatchpoint(com.sun.jdi.Field f,
                                                                                groovy.lang.Closure body)
Sets a breakpoint that fires when the specified field is updated.


modificationWatchpoint

public com.sun.jdi.request.AccessWatchpointRequest modificationWatchpoint(String className,
                                                                          String fieldName,
                                                                          groovy.lang.Closure body)
Sets a breakpoint that fires when the specified field of the specified class is updated.


modificationWatchpoint

public com.sun.jdi.request.AccessWatchpointRequest modificationWatchpoint(Class c,
                                                                          String fieldName,
                                                                          groovy.lang.Closure body)
Same as modificationWatchpoint(c.name,fieldName,body)


ref

public com.sun.jdi.ReferenceType ref(String className)
Resolves a class by the name. TODO: use the current thread and classloader to try to disambiguate in a multi-classloader situation


ref

public com.sun.jdi.ReferenceType ref(Class c)
Resolves the same class on the target JVM.


_

public com.sun.jdi.ReferenceType _(Class c)
Short hand for {@link #ref(Class)


_

public com.sun.jdi.ReferenceType _(String c)
Short hand for {@link #ref(String)


_new

public Object _new(Class c,
                   Object args)
Creates a new instance of the given type in the remote JVM.


_new

public Object _new(String c,
                   Object args)
Creates a new instance of the given type in the remote JVM.


_new

public Object _new(com.sun.jdi.ReferenceType t,
                   Object args)

loadClass

public com.sun.jdi.ReferenceType loadClass(String c)
Instead of just resolving an existing class, load the specified class in the target JVM and returns its reference.


loadClass

public com.sun.jdi.ReferenceType loadClass(Class c)

forEachClass

public com.sun.jdi.request.ClassPrepareRequest forEachClass(String className,
                                                            groovy.lang.Closure body)
Executes the given closure for each class of the given name.

The closure gets a ReferenceType object as a parameter. It'll be invoked immediately for all the loaded class (of the given name), and then whenever a new class of the given name is loaded, the closure will be re-invoked.

Returns:
A EventRequest that can be used to cancel future invcocations.

close

public void close()
Shuts down the connection.

Specified by:
close in interface Closeable

execute

public void execute(InputStream script)
             throws InterruptedException
Executes the specified YouDebug script. The method blocks until the debug connection is closed.

Throws:
InterruptedException

execute

public void execute(File script)
             throws InterruptedException
Executes the specified YouDebug script. The method blocks until the debug connection is closed.

Throws:
InterruptedException

execute

public void execute(URL script)
             throws InterruptedException
Executes the specified YouDebug script. The method blocks until the debug connection is closed.

Throws:
InterruptedException

execute

public void execute(groovy.lang.GroovyCodeSource script)
             throws InterruptedException
Executes the specified YouDebug script. The method blocks until the debug connection is closed.

Throws:
InterruptedException

execute

public void execute(groovy.lang.GroovyCodeSource script,
                    Map variables)
             throws InterruptedException
Executes the given YouDebug script.

Parameters:
script - The script to execute.
variables - Additional variables to be exposed to the script. This is useful for passing information between the script and the calling program.
Throws:
InterruptedException

dumpAllThreads

public void dumpAllThreads()
                    throws com.sun.jdi.IncompatibleThreadStateException
Short for dumpAllThreads(System.out)

Throws:
com.sun.jdi.IncompatibleThreadStateException

dumpAllThreads

public void dumpAllThreads(PrintStream out)
                    throws com.sun.jdi.IncompatibleThreadStateException
Dumps information about all the threads in the target JVM to the specified object.

Throws:
com.sun.jdi.IncompatibleThreadStateException

dumpAllThreads

public void dumpAllThreads(PrintWriter out)
                    throws com.sun.jdi.IncompatibleThreadStateException
Dumps information about all the threads in the target JVM to the specified object.

Throws:
com.sun.jdi.IncompatibleThreadStateException

suspend

public void suspend()

resume

public void resume()

withFrozenWorld

public void withFrozenWorld(groovy.lang.Closure c)
Executes the given closure by suspending the VM. At the exit of the scope the VM will be resumed.


dumpHeap

public void dumpHeap(String path)
Instructs the target JVM to create a heap dump. The dump will be created on the file system of the target JVM.


current

public static VM current()
Can be called during event dispatching to obtain the current VM instance.


getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface groovy.lang.GroovyObject

setMetaClass

public void setMetaClass(groovy.lang.MetaClass metaClass)
Specified by:
setMetaClass in interface groovy.lang.GroovyObject

invokeMethod

public Object invokeMethod(String name,
                           Object args)
Specified by:
invokeMethod in interface groovy.lang.GroovyObject

getProperty

public Object getProperty(String name)
Specified by:
getProperty in interface groovy.lang.GroovyObject

setProperty

public void setProperty(String name,
                        Object value)
Specified by:
setProperty in interface groovy.lang.GroovyObject


Copyright © 2013. All rights reserved.