1 package jde.debugger.command;
2 import java.util.Iterator;
5 import com.sun.jdi.IncompatibleThreadStateException;
6 import com.sun.jdi.InvalidStackFrameException;
7 import com.sun.jdi.ObjectCollectedException;
8 import com.sun.jdi.ObjectReference;
9 import com.sun.jdi.StackFrame;
10 import com.sun.jdi.ThreadReference;
11 import com.sun.jdi.Value;
12 import jde.debugger.Etc;
13 import jde.debugger.JDEException;
14 import jde.debugger.Rep;
19 * Gets the "this" object of a specified stack frame.
24 * get_this threadID stackFrameIndex
29 * (jde-dbo-command-result cmd_id {@link Rep#getObjectRep(ObjectReference) detailed-object-info})
34 * <li> Note that stackFrameIndex = 0 corresponds to the
36 * <li> The threadID and stackFrameIndex can be got from the
37 * 'get_threads' command.
41 * @author Paul Kinnucan
42 * @version $Revision: 1.4 $
43 * @copyright Copyright (c) 2000, 2001, 2003 Paul Kinnucan
45 public class GetThis extends DebugProcessCommand {
49 * @exception jde.debugger.JDEException <description>
51 public void doCommand() throws JDEException {
53 boolean weSuspendedThread = false;
54 ThreadReference tRef = null;
56 if (m_args.size() != 2)
57 throw new JDEException("Insufficient arguments");
61 Long uniqueID = Etc.safeGetLong(m_args.remove(0), "thread ID");
62 int frameIndex = Etc.safeGetint(m_args.remove(0), "frame index");
63 Object oRef = m_debugger.getStore().get(uniqueID);
66 throw new JDEException("No such thread exists");
67 } else if (!(oRef instanceof ThreadReference)) {
68 throw new JDEException("Object is not a thread");
71 tRef = (ThreadReference) oRef;
73 if (!tRef.isSuspended()) {
75 weSuspendedThread = true;
78 StackFrame frame = null;
80 frame = tRef.frame(frameIndex);
81 } catch (IncompatibleThreadStateException ex) {
82 throw new JDEException("Thread is not suspended");
83 } catch (IndexOutOfBoundsException ex) {
84 throw new JDEException("Invalid frame");
85 } catch (ObjectCollectedException ex) {
86 throw new JDEException("The frame has already been garbage collected");
90 throw new JDEException("Error ascertaining frame");
93 ObjectReference thisObj = null;
95 thisObj = frame.thisObject();
96 } catch (InvalidStackFrameException ex) {
97 throw new JDEException("Invalid stack frame.");
100 if (thisObj != null) {
101 // Keep track of this object, for future reference from the UI
102 m_debugger.getStore().put(thisObj);
104 // store the fields in this object that themselves are objects in the
105 // ObjectStore, since the user may query for more information about those.
106 Map fieldValues = thisObj.getValues(thisObj.referenceType().visibleFields());
108 Iterator iter = fieldValues.values().iterator();
109 while (iter.hasNext()) {
110 Value value = (Value) iter.next();
112 if (value instanceof ObjectReference) {
113 ObjectReference obj = (ObjectReference) value;
115 // Debug.printIf(Debug.EVENTS, "storing field with ID: " + obj.uniqueID() +
116 // " of type: " + obj.referenceType().name());
117 m_debugger.getStore().put((ObjectReference) value);
121 // XXX - report 'this' to the GUI
124 m_debugger.signalCommandResult(m_cmdID,
125 Rep.getObjectRep(thisObj, true),
129 if (weSuspendedThread && (tRef != null)) tRef.resume();
134 public Object clone() {return new GetThis();}
139 * $Log: GetThis.java,v $
140 * Revision 1.4 2003/01/15 05:56:26 paulk
141 * Add Petter Mahlen's changes.
143 * Revision 1.3 2001/03/24 05:42:36 paulk
144 * Updated to reflect reorganization of debugger code.
146 * Revision 1.2 2000/08/14 02:42:16 paulk
147 * DebugCommandFactory.java
149 * Revision 1.1 2000/04/10 05:35:23 paulk
155 // End of GetTbis.java