Fix & Continue – Design View
Introduction
There are two new actions added to the debugger core:
and one action to JPDA debugger:
Actions Fix and Pop Topmost Call can be used by
multiple debugger engines (i.e. there is only one Fix action
and one Pop Topmost Call action visible in GUI) but
their functionality varies, depending on the current debugging
session.
Action Pop To Here is available only in JPDA debugger.
The following classes are added to package
org.netbeans.modules.debugger.support.actions:
FixAction
PopTopmostFrame
Two abstract methods are added to class AbstractDebugger:
public abstract void fix()
public
abstract void popTopmostFrame()
These actions must be defined by debugger engines. When action
FixAction is invoked, method fix() of the
current debugging session (Debugger.getCurrentDebugger())
is called. Similarly, when PopTopmostFrame is invoked,
method popTopmostFrame() of the current debugging
session is called.
State enabled/disabled
Both actions Fix and Pop Topmost Frame are
disabled when NetBeans is started. When a session is started or
switched, a current debugging session is asked about the actions'
state. To allow this, two methods are added to interface
org.netbeans.modules.debugger.State:
boolean isFixEnabled()
boolean
isPopTopmostFrameEnabled()
When the last session is finished, both actions become disabled.
JPDA Debugger
Each of the above actions (and action Pop To Here) may be
unavailable (disabled) during a whole debugging session if:
JDK used for running NetBeans supports the actions if the
following methods are available:
boolean
com.sun.jdi.VirtualMachine.redefineClasses(java.util.Map)
boolean
com.sun.jdi.ThreadReference.popFrame(com.sun.jdi.StackFrame)
During session startup, JPDA debugger looks up the methods
and remembers them if it finds some – the following fields are
added to class JPDADebugger:
java.lang.reflect.Method
redefineClasses
java.lang.reflect.Method popFrames
If some of the methods is null (i. e. not
found), a corresponding action will never be enabled. (These fields
are also used for invocation of the methods via reflection.)
JDK used for running a debuggee supports the actions if the
following methods return true:
boolean
com.sun.jdi.VirtualMachine.canRedefineClasses()
boolean
com.sun.jdi.VirtualMachine.canPopFrames()
Summary:
Action Fix is enabled if all of the
following is true:
– JPDADebugger.redefineClasses !=
null
– exactly one node is selected
– the
selected node has a DataObject cookie and the cookie's
primary file has MIME-type text/java.
Action Pop Topmost Call is enabled if all of
the following is true:
– JPDADebugger.popFrames !=
null
– current thread is suspended
–
current thread has at least two frames
Its state is updated on
the following events:
– session is switched
–
current session is started/stopped
– thread is switched
–
current thread is suspended/resumed
Implementation
Action Fix
Action Fix is invoked on a (selected) node:
If the node has a CompilerCookie, the node
is compiled (the process will be almost the same as in method
org.netbeans.modules.debugger.support.java.JavaDebugger.compile(DebuggerInfo)).
If the compilation fails, an error dialog is displayed
and the whole action is aborted.
A set of files representing the node is gathered (the
node has a DataObject and the DataObject
has a set of files – both primary and secondary).
If the set of files does not contain any .class
file, an error dialog is displayed and the whole action is aborted.
For each .class file, a corresponding
ReferenceType is requested from the remote JVM and the
pair (ReferenceType object, contents of the.class
file) is put into a table (java.util.Map). If a
ReferenceType object is not found in the JVM for any of
the .class files, the class name is remembered (added to a list of
unloaded classes). Finally, if all classes were loaded, a JDI
command (redefineClasses(Map))is invoked to replace
class definition(s). If at least one class were not loaded, a dialog
is displayed: The following classes are not loaded in the remote
JVM. Do you want to continue? - with options Continue
and Cancel. If the user selects Cancel, the whole
operation is aborted.
If an exception is thrown during call of
redefineClasses(Map), an exception dialog is displayed.
Action Pop Topmost Call
Simply calls the JDI command:
1) Get reference to
the JDI thread (the current thread).
2) Pop its topmost frame.
If some exception is thrown, displays an error dialog,
otherwise updates UI parts of the
debugger.
Action Pop To Here
Action Pop To Here is available only from a
contextual menu of nodes representing JPDA call stack frames. A new
class is added to represent these nodes –
JPDACallStackFrameNode:

Method getActions() adds a new action Pop
To Here to the default set of actions.
When the action is invoked, it pops the frame (represented
by the node) from a call stack (JPDACallStackFrame.threadS).