com.futureshocked.classloader
Class ApplicationDebugger

java.lang.Object
  extended by com.futureshocked.classloader.ApplicationDebugger

public class ApplicationDebugger
extends java.lang.Object

ApplicationDebugger provides an easy way to intercept and modify classes for debugging purposes.

To debug an application, a class name and a String array of arguments are passed in the constuctor, methods to intercept are specified using the addMethod() methods, and finally run() is called, which will invoke main() on the user specified class.


Field Summary
protected  java.lang.String[] args
          The String array passed to the main method of className
protected  java.lang.ClassLoader cl
          An instance of DebuggerClassLoader
protected  java.lang.String className
          The name of the class which contains the main() method to be invoked
protected  ClassTransforms ct
          Collection of InterceptedMethod
protected static int defaultDebugDepth
          The default maximum recursive depth for StaticDebugger.printDebugInformation
protected static int defaultRecursionDepth
          The default maximum recursive depth for limited recursion
protected  int maxDebugDepth
          The maximum recursive depth when StaticDebugger.printDebugInformation is called
protected  int maxRecursionDepth
          The maximum recursive depth when the limited recursion feature is used
protected  boolean verbose
          Prints debugging information when set to true
 
Constructor Summary
ApplicationDebugger(java.lang.String name, java.lang.String[] args)
          Constructor that will set maxDebugDepth and maxRecursiveDepth to their defaults.
ApplicationDebugger(java.lang.String name, java.lang.String[] args, int maxDebugDepth, int maxRecursionDepth)
          Constructor that will set maxDebugDepth and maxRecursiveDepth to user specified values.
 
Method Summary
 InterceptedMethod addCodeStyleMethod(java.lang.String code, boolean callStatic, boolean limitRecursion)
          An easier way to add a method to be intercepted by DebuggerClassLoader.
 InterceptedMethod addMethod(java.lang.String clazz, java.lang.String method, boolean callStatic, boolean limitRecursion)
          Adds a method to be intercepted by DebuggerClassLoader.
 InterceptedMethod addMethod(java.lang.String clazz, java.lang.String method, java.lang.String desc, boolean callStatic, boolean limitRecursion)
          Adds a method to be intercepted by DebuggerClassLoader.
 int getMaxDebugDepth()
           
 int getMaxRecursionDepth()
           
 boolean getVerbose()
           
static void main(java.lang.String[] args)
           
 void run()
          Creates a new classloader and invokes main on ApplicationDebugger.className.
 void setMaxDebugDepth(int depth)
           
 void setMaxRecursionDepth(int depth)
           
 void setVerbose(boolean verbose)
           
 void unloadClassLoader()
          Unloads the classloader - this will unload all classes loaded by the classloader, allowing any recompiled classes to be reloaded back into memory without restarting the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cl

protected java.lang.ClassLoader cl
An instance of DebuggerClassLoader


ct

protected ClassTransforms ct
Collection of InterceptedMethod


className

protected java.lang.String className
The name of the class which contains the main() method to be invoked


args

protected java.lang.String[] args
The String array passed to the main method of className


maxDebugDepth

protected int maxDebugDepth
The maximum recursive depth when StaticDebugger.printDebugInformation is called


defaultDebugDepth

protected static final int defaultDebugDepth
The default maximum recursive depth for StaticDebugger.printDebugInformation

See Also:
Constant Field Values

maxRecursionDepth

protected int maxRecursionDepth
The maximum recursive depth when the limited recursion feature is used


defaultRecursionDepth

protected static final int defaultRecursionDepth
The default maximum recursive depth for limited recursion

See Also:
Constant Field Values

verbose

protected boolean verbose
Prints debugging information when set to true

Constructor Detail

ApplicationDebugger

public ApplicationDebugger(java.lang.String name,
                           java.lang.String[] args)
Constructor that will set maxDebugDepth and maxRecursiveDepth to their defaults.

Parameters:
name - Class name to be loaded, must contain a main method.
args - Arguments to be passed to the main method.

ApplicationDebugger

public ApplicationDebugger(java.lang.String name,
                           java.lang.String[] args,
                           int maxDebugDepth,
                           int maxRecursionDepth)
Constructor that will set maxDebugDepth and maxRecursiveDepth to user specified values.

Parameters:
name - Class name to be loaded, must contain a main method.
args - Arguments to be passed to the main method.
maxDebugDepth - Maximum depth for StaticDebugger.
maxRecursionDepth - Maximum recusion depth for limited recursion.
Method Detail

run

public void run()
         throws java.lang.Exception
Creates a new classloader and invokes main on ApplicationDebugger.className.

Throws:
java.lang.Exception - Most likely from the user specified application, though it might be a ClassNotFound exception.

unloadClassLoader

public void unloadClassLoader()
Unloads the classloader - this will unload all classes loaded by the classloader, allowing any recompiled classes to be reloaded back into memory without restarting the application.


addMethod

public InterceptedMethod addMethod(java.lang.String clazz,
                                   java.lang.String method,
                                   boolean callStatic,
                                   boolean limitRecursion)
Adds a method to be intercepted by DebuggerClassLoader. Since description is not specified, this InterceptedMethod will match all overloaded methods that match this method name.

Parameters:
clazz - The name of the class the method belongs to. Should include full package name too.
method - The name of the method to be intercepted.
callStatic - true to add a call to StaticDebugger.printDebugInformation.
limitRecursion - true to limit the amount of times this method may call itself.
Returns:
an InterceptedMethod that will match these values.

addMethod

public InterceptedMethod addMethod(java.lang.String clazz,
                                   java.lang.String method,
                                   java.lang.String desc,
                                   boolean callStatic,
                                   boolean limitRecursion)
Adds a method to be intercepted by DebuggerClassLoader. desc must be in the correct format, see the ASM documentation for details.

Parameters:
clazz - The name of the class the method belongs to. Should include full package name too.
method - The name of the method to be intercepted.
desc - The description of the method, per ASM specs.
For example, a method like 'public void testMethod(String name, int count)' has a description of:
"(Ljava.lang.String;I)V".
callStatic - true to add a call to StaticDebugger.printDebugInformation.
limitRecursion - true to limit the amount of times this method may call itself.
Returns:
an InterceptedMethod that will match these values.

addCodeStyleMethod

public InterceptedMethod addCodeStyleMethod(java.lang.String code,
                                            boolean callStatic,
                                            boolean limitRecursion)
An easier way to add a method to be intercepted by DebuggerClassLoader. This allows the user to not worry about the description - the method declaration from the code may simply entered as code. One important thing to note is the full package name must be entered for all Objects.

Parameters:
code - A method declaration as taken from the code, but with package names added for all Objects.
ie: "void testMethod(java.lang.String arg1, com.user.package.MyObject arg2)".
callStatic - callStatic true to add a call to StaticDebugger.printDebugInformation.
limitRecursion - true to limit the amount of times this method may call itself.
Returns:
an InterceptedMethod that will match these values.

getMaxDebugDepth

public int getMaxDebugDepth()

setMaxDebugDepth

public void setMaxDebugDepth(int depth)

getMaxRecursionDepth

public int getMaxRecursionDepth()

setMaxRecursionDepth

public void setMaxRecursionDepth(int depth)

setVerbose

public void setVerbose(boolean verbose)

getVerbose

public boolean getVerbose()

main

public static void main(java.lang.String[] args)