edu.rice.cs.drjava.model.debug
Class DebugManager

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.debug.DebugManager

public class DebugManager
extends Object

An integrated debugger which attaches to the Interactions JVM using Sun's Java Platform Debugger Architecture (JPDA/JDI) interface.

Version:
$Id: DebugManager.java,v 1.44 2002/09/13 22:55:34 csreis Exp $

Inner Class Summary
protected  class DebugManager.EventNotifier
          Class model for notifying listeners of an event.
 class DebugManager.StackData
           
 class DebugManager.ThreadData
           
 class DebugManager.WatchData
          Class for keeping track of watched fields and variables.
static class DebugManager.WatchUndefinedValue
           
 
Field Summary
private  gj.util.Vector _breakpoints
          Vector of all current Breakpoints, with and without EventRequests.
private  com.sun.jdi.request.EventRequestManager _eventManager
          Manages all event requests in JDI.
private  LinkedList _listeners
          Provides a way for the DebugManager to communicate with the view.
private  GlobalModel _model
          Reference to DrJava's model.
private  PendingRequestManager _pendingRequestManager
          Keeps track of any DebugActions whose classes have not yet been loaded, so that EventRequests can be created when the correct ClassPrepareEvent occurs.
private  com.sun.jdi.ThreadReference _thread
          The Thread that the DebugManager is currently analyzing.
private  com.sun.jdi.VirtualMachine _vm
          VirtualMachine of the interactions JVM.
private  gj.util.Vector _watches
          Vector of all current Watches
static int STEP_INTO
           
static int STEP_OUT
           
static int STEP_OVER
           
 
Constructor Summary
DebugManager(GlobalModel model)
          Builds a new DebugManager to debug code in the Interactions JVM, using the JPDA/JDI interfaces.
 
Method Summary
private  void _attachToVM()
          Handles the details of attaching to the InteractionsJVM.
private  String _getValue(com.sun.jdi.Value value)
          Takes a jdi Value and gets its String representation
private  void _updateWatches()
           
 void addListener(DebugListener listener)
          Adds a listener to this DebugManager.
 void addWatch(String field)
          Adds a watch on the given field or variable.
 void clearCurrentStepRequest()
          Called from interactionsEnded in MainFrame in order to clear any current StepRequests that remain.
(package private)  void currThreadDied()
          Notifies all listeneres that the current thread has died.
(package private)  void currThreadResumed()
          Notifies all listeners that the current thread has been resumed.
(package private)  void currThreadSuspended()
          Notifies all listeners that the current thread has been suspended.
 gj.util.Vector getBreakpoints()
          Returns a Vector that contains all of the Breakpoint objects that all open documents contain.
 gj.util.Vector getCurrentStackFrameData()
          Returns a Vector of StackData for the current thread or null if the current thread is null TO DO: Config option for hiding DrJava subset of stack trace
(package private)  com.sun.jdi.ThreadReference getCurrentThread()
          Returns the debugger's currently active thread.
 gj.util.Vector getCurrentThreadData()
          Returns a Vector of ThreadData or null if the vm is null
(package private)  com.sun.jdi.request.EventRequestManager getEventRequestManager()
          Returns the current EventRequestManager from JDI, or null if startup() has not been called.
(package private)  String getPackageDir(String className)
          Returns the relative directory (from the source root) that the source file with this qualifed name will be in, given its package.
(package private)  PendingRequestManager getPendingRequestManager()
          Returns the pending request manager used by the debugger.
(package private)  gj.util.Vector getReferenceTypes(String className)
          Returns the loaded ReferenceTypes for the given class name, or null if the class could not be found.
(package private)  gj.util.Vector getReferenceTypes(String className, int lineNumber)
          Returns the loaded ReferenceTypes for the given class name, or null if the class could not be found.
 gj.util.Vector getWatches()
          Returns all currently watched fields and variables.
 boolean isReady()
          Returns the status of the debugger
(package private)  void notifyDebuggerShutdown()
          Notifies all listeneres that the debugger has shut down.
(package private)  void notifyDebuggerStarted()
          Notifies all listeneres that the debugger has started.
protected  void notifyListeners(DebugManager.EventNotifier n)
          Lets the listeners know some event has taken place.
(package private)  void notifyStepRequested()
          Notifies all listeneres that a step has been requested.
 void printBreakpoints()
          Prints the list of breakpoints in the current session of DrJava, both pending resolved Breakpoints are listed
(package private)  void printMessage(String message)
          Prints a message in the Interactions Pane.
(package private)  void reachedBreakpoint(com.sun.jdi.request.BreakpointRequest request)
          Called when a breakpoint is reached.
 void removeAllBreakpoints()
          Removes all the breakpoints from the manager's vector of breakpoints.
 void removeAllWatches()
          Removes all watches on existing fields and variables.
 void removeBreakpoint(Breakpoint breakpoint)
          Removes a breakpoint.
 void removeListener(DebugListener listener)
           
 void removeWatch(int index)
          Removes the watch at the given index.
 void removeWatch(String field)
          Removes any watches on the given field or variable.
 void resume()
          Resumes execution of the currently loaded document.
(package private)  void scrollToSource(com.sun.jdi.event.LocatableEvent e)
          Takes the location of event e, opens the document corresponding to its class and centers the definition pane's view on the appropriate line number
 void setBreakpoint(Breakpoint breakpoint)
          Sets a breakpoint.
(package private)  void setCurrentThread(com.sun.jdi.ThreadReference thread)
          Sets the debugger's currently active thread.
 void shutdown()
          Disconnects the debugger from the Interactions JVM and cleans up any state.
 void startup()
          Attaches the debugger to the Interactions JVM to prepare for debugging.
 void step(int flag)
          Steps into the execution of the currently loaded document.
 void suspend()
          Suspends execution of the currently running document.
 void toggleBreakpoint(OpenDefinitionsDocument doc, int offset, int lineNum)
          Toggles whether a breakpoint is set at the given line in the given document.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

STEP_INTO

public static final int STEP_INTO

STEP_OVER

public static final int STEP_OVER

STEP_OUT

public static final int STEP_OUT

_model

private GlobalModel _model
Reference to DrJava's model.

_vm

private com.sun.jdi.VirtualMachine _vm
VirtualMachine of the interactions JVM.

_eventManager

private com.sun.jdi.request.EventRequestManager _eventManager
Manages all event requests in JDI.

_breakpoints

private gj.util.Vector _breakpoints
Vector of all current Breakpoints, with and without EventRequests.

_watches

private gj.util.Vector _watches
Vector of all current Watches

_pendingRequestManager

private PendingRequestManager _pendingRequestManager
Keeps track of any DebugActions whose classes have not yet been loaded, so that EventRequests can be created when the correct ClassPrepareEvent occurs.

_listeners

private LinkedList _listeners
Provides a way for the DebugManager to communicate with the view.

_thread

private com.sun.jdi.ThreadReference _thread
The Thread that the DebugManager is currently analyzing.
Constructor Detail

DebugManager

public DebugManager(GlobalModel model)
Builds a new DebugManager to debug code in the Interactions JVM, using the JPDA/JDI interfaces. Does not actually connect to the InteractionsJVM until startup().
Method Detail

startup

public void startup()
             throws DebugException
Attaches the debugger to the Interactions JVM to prepare for debugging.

_attachToVM

private void _attachToVM()
                  throws DebugException
Handles the details of attaching to the InteractionsJVM.

shutdown

public void shutdown()
Disconnects the debugger from the Interactions JVM and cleans up any state.

isReady

public boolean isReady()
Returns the status of the debugger

getEventRequestManager

com.sun.jdi.request.EventRequestManager getEventRequestManager()
Returns the current EventRequestManager from JDI, or null if startup() has not been called.

getPendingRequestManager

PendingRequestManager getPendingRequestManager()
Returns the pending request manager used by the debugger.

setCurrentThread

void setCurrentThread(com.sun.jdi.ThreadReference thread)
Sets the debugger's currently active thread.

getCurrentThread

com.sun.jdi.ThreadReference getCurrentThread()
Returns the debugger's currently active thread.

getReferenceTypes

gj.util.Vector getReferenceTypes(String className)
Returns the loaded ReferenceTypes for the given class name, or null if the class could not be found. Makes no attempt to load the class if it is not already loaded.

If custom class loaders are in use, multiple copies of the class may be loaded, so all are returned.


getReferenceTypes

gj.util.Vector getReferenceTypes(String className,
                                 int lineNumber)
Returns the loaded ReferenceTypes for the given class name, or null if the class could not be found. Makes no attempt to load the class if it is not already loaded. If the lineNumber is not DebugAction.ANY_LINE, ensures that the returned ReferenceTypes contain the given lineNumber, searching through inner classes if necessary. If no inner classes contain the line number, null is returned.

If custom class loaders are in use, multiple copies of the class may be loaded, so all are returned.


suspend

public void suspend()
Suspends execution of the currently running document.

resume

public void resume()
Resumes execution of the currently loaded document.

step

public void step(int flag)
          throws DebugException
Steps into the execution of the currently loaded document.

clearCurrentStepRequest

public void clearCurrentStepRequest()
Called from interactionsEnded in MainFrame in order to clear any current StepRequests that remain.

addWatch

public void addWatch(String field)
Adds a watch on the given field or variable.
Parameters:
field - the name of the field we will watch

removeWatch

public void removeWatch(String field)
Removes any watches on the given field or variable.
Parameters:
field - the name of the field we will watch

removeWatch

public void removeWatch(int index)
Removes the watch at the given index.
Parameters:
index - Index of the watch to remove

removeAllWatches

public void removeAllWatches()
Removes all watches on existing fields and variables.

toggleBreakpoint

public void toggleBreakpoint(OpenDefinitionsDocument doc,
                             int offset,
                             int lineNum)
                      throws DebugException
Toggles whether a breakpoint is set at the given line in the given document.
Parameters:
doc - Document in which to set or remove the breakpoint
offset - Start offset on the line to set the breakpoint
lineNumber - Line on which to set or remove the breakpoint

setBreakpoint

public void setBreakpoint(Breakpoint breakpoint)
Sets a breakpoint.
Parameters:
breakpoint - The new breakpoint to set

removeBreakpoint

public void removeBreakpoint(Breakpoint breakpoint)
Removes a breakpoint. Called from ToggleBreakpoint -- even with BPs that are not active.
Parameters:
breakpoint - The breakpoint to remove.
className - the name of the class the BP is being removed from.

removeAllBreakpoints

public void removeAllBreakpoints()
Removes all the breakpoints from the manager's vector of breakpoints.

reachedBreakpoint

void reachedBreakpoint(com.sun.jdi.request.BreakpointRequest request)
Called when a breakpoint is reached. The Breakpoint object itself should be stored in the "debugAction" property on the request.
Parameters:
request - The BreakPointRequest reached by the debugger

getBreakpoints

public gj.util.Vector getBreakpoints()
Returns a Vector that contains all of the Breakpoint objects that all open documents contain.

printBreakpoints

public void printBreakpoints()
Prints the list of breakpoints in the current session of DrJava, both pending resolved Breakpoints are listed

getWatches

public gj.util.Vector getWatches()
Returns all currently watched fields and variables.

getCurrentThreadData

public gj.util.Vector getCurrentThreadData()
Returns a Vector of ThreadData or null if the vm is null

getCurrentStackFrameData

public gj.util.Vector getCurrentStackFrameData()
Returns a Vector of StackData for the current thread or null if the current thread is null TO DO: Config option for hiding DrJava subset of stack trace

scrollToSource

void scrollToSource(com.sun.jdi.event.LocatableEvent e)
Takes the location of event e, opens the document corresponding to its class and centers the definition pane's view on the appropriate line number
Parameters:
e - should be a LocatableEvent

getPackageDir

String getPackageDir(String className)
Returns the relative directory (from the source root) that the source file with this qualifed name will be in, given its package. Returns the empty string for classes without packages.
Parameters:
className - The fully qualified class name

printMessage

void printMessage(String message)
Prints a message in the Interactions Pane.
Parameters:
message - Message to display

_updateWatches

private void _updateWatches()

_getValue

private String _getValue(com.sun.jdi.Value value)
Takes a jdi Value and gets its String representation
Parameters:
value - the Value whose value is requested
Returns:
the String representation of the Value

currThreadSuspended

void currThreadSuspended()
Notifies all listeners that the current thread has been suspended.

currThreadResumed

void currThreadResumed()
Notifies all listeners that the current thread has been resumed.

currThreadDied

void currThreadDied()
Notifies all listeneres that the current thread has died.

notifyDebuggerShutdown

void notifyDebuggerShutdown()
Notifies all listeneres that the debugger has shut down.

notifyDebuggerStarted

void notifyDebuggerStarted()
Notifies all listeneres that the debugger has started.

notifyStepRequested

void notifyStepRequested()
Notifies all listeneres that a step has been requested.

addListener

public void addListener(DebugListener listener)
Adds a listener to this DebugManager.
Parameters:
listener - a listener that reacts on events generated by the DebugManager

removeListener

public void removeListener(DebugListener listener)

notifyListeners

protected void notifyListeners(DebugManager.EventNotifier n)
Lets the listeners know some event has taken place.
Parameters:
EventNotifier - n tells the listener what happened