com.bluemarsh.jswat.util
Class VariableUtils

java.lang.Object
  |
  +--com.bluemarsh.jswat.util.VariableUtils

public class VariableUtils
extends java.lang.Object

Class VariableUtils provides utility methods for getting Field objects and Value objects from an object in the debuggee VM.

Author:
Nathan Fiedler

Constructor Summary
VariableUtils()
           
 
Method Summary
protected static com.sun.jdi.Field getField(com.sun.jdi.ObjectReference obj, java.lang.String field)
          Retrieves an object's field, given the reference to the object and the name of the field to fetch.
protected static com.sun.jdi.Field getField(com.sun.jdi.ReferenceType clazz, java.lang.String field)
          Retrieves a class's field, given the reference to the class and the name of the field to fetch.
static FieldAndValue getField(java.lang.String expr, com.sun.jdi.ThreadReference thread, int frameNum)
          Retrieves the named variable, using the top stack frame of the given thread.
static com.sun.jdi.Value getValue(java.lang.String expr, com.sun.jdi.ThreadReference thread, int index)
          Retrieves the named variable, using the stack frame of the given thread.
protected static com.sun.jdi.Value getValue(com.sun.jdi.Value val, java.lang.String name)
          Retrieves an object's field value, given the reference to the object and the name of the field to fetch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableUtils

public VariableUtils()
Method Detail

getField

protected static com.sun.jdi.Field getField(com.sun.jdi.ObjectReference obj,
                                            java.lang.String field)
                                     throws com.sun.jdi.ClassNotPreparedException,
                                            java.lang.NoSuchFieldException,
                                            com.sun.jdi.ObjectCollectedException
Retrieves an object's field, given the reference to the object and the name of the field to fetch.
Parameters:
obj - Current value (must be an ObjectReference).
field - Name of the field to look up.
Returns:
New Field as grabbed from the object.
Throws:
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

getField

protected static com.sun.jdi.Field getField(com.sun.jdi.ReferenceType clazz,
                                            java.lang.String field)
                                     throws com.sun.jdi.ClassNotPreparedException,
                                            java.lang.NoSuchFieldException
Retrieves a class's field, given the reference to the class and the name of the field to fetch.
Parameters:
clazz - Class in which to find named field.
field - Name of the field to look up.
Returns:
New Field as grabbed from the class.
Throws:
com.sun.jdi.ClassNotPreparedException - Thrown if the class is not loaded.
java.lang.NoSuchFieldException - Thrown if the field was not found in the class.

getField

public static FieldAndValue getField(java.lang.String expr,
                                     com.sun.jdi.ThreadReference thread,
                                     int frameNum)
                              throws com.sun.jdi.AbsentInformationException,
                                     com.sun.jdi.ClassNotPreparedException,
                                     FieldNotObjectException,
                                     java.lang.IllegalThreadStateException,
                                     com.sun.jdi.IncompatibleThreadStateException,
                                     com.sun.jdi.InvalidStackFrameException,
                                     com.sun.jdi.NativeMethodException,
                                     java.lang.NoSuchFieldException,
                                     com.sun.jdi.ObjectCollectedException
Retrieves the named variable, using the top stack frame of the given thread.
Parameters:
expr - Expression referring to variable or object.
thread - ThreadReference from which to find variable.
frameNum - Frame number in which to look for field.
Returns:
instance of FieldAndValue holding the field, its value, and the object containing the field. May also be a local variable and its value, if return value's 'field' field is null.
Throws:
com.sun.jdi.AbsentInformationException - Thrown if class doesn't have local variable info.
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
FieldNotObjectException - Thrown if a non-object is encountered.
java.lang.IllegalThreadStateException - Thrown if thread is not currently running.
com.sun.jdi.IncompatibleThreadStateException - Thrown if thread is not suspended.
com.sun.jdi.InvalidStackFrameException - Thrown if index is out of bounds.
com.sun.jdi.NativeMethodException - Thrown if the method is native and has no variables.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

getValue

protected static com.sun.jdi.Value getValue(com.sun.jdi.Value val,
                                            java.lang.String name)
                                     throws com.sun.jdi.ClassNotPreparedException,
                                            java.lang.NoSuchFieldException,
                                            com.sun.jdi.ObjectCollectedException
Retrieves an object's field value, given the reference to the object and the name of the field to fetch.
Parameters:
val - Current value (must be an ObjectReference).
name - Name of the field to look up.
Returns:
New Value as grabbed from the 'field'. Value can be null.
Throws:
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

getValue

public static com.sun.jdi.Value getValue(java.lang.String expr,
                                         com.sun.jdi.ThreadReference thread,
                                         int index)
                                  throws com.sun.jdi.AbsentInformationException,
                                         com.sun.jdi.ClassNotPreparedException,
                                         FieldNotObjectException,
                                         com.sun.jdi.IncompatibleThreadStateException,
                                         java.lang.IllegalThreadStateException,
                                         com.sun.jdi.InvalidStackFrameException,
                                         com.sun.jdi.NativeMethodException,
                                         java.lang.NoSuchFieldException,
                                         com.sun.jdi.ObjectCollectedException
Retrieves the named variable, using the stack frame of the given thread.
Parameters:
expr - Expression referring to variable or object.
thread - ThreadReference from which to find variable.
index - Index into stack frames to find variable.
Returns:
The Value referred to by 'expr'. Could possibly be null.
Throws:
com.sun.jdi.AbsentInformationException - Thrown if class doesn't have local variable info.
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
FieldNotObjectException - Thrown if a non-object is encountered.
java.lang.IllegalThreadStateException - Thrown if thread is not currently running.
com.sun.jdi.IncompatibleThreadStateException - Thrown if thread is not suspended.
com.sun.jdi.InvalidStackFrameException - Thrown if index is out of bounds.
com.sun.jdi.NativeMethodException - Thrown if current stack frame is a native method.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.