Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / DebugThread.java
1 package jde.debugger.command;
2
3
4 import com.sun.jdi.IncompatibleThreadStateException;
5 import com.sun.jdi.ThreadReference;
6 import jde.debugger.Etc;
7 import jde.debugger.JDEException;
8 import jde.debugger.Rep;
9 import jde.debugger.JDE;
10
11
12
13 /**
14  * Stops the VM and debug the specified thread.
15  * <p>
16  *
17  * <b>Syntax:</b>
18  * <pre>
19  * debug_thread threadID
20  * </pre>
21  *
22  * Copyright (c) 2000, 2001, 2003    Paul Kinnucan
23  *  
24  * @author Raffael Herzog
25  * @author Paul Kinnucan
26  * @version $Revision: 1.3 $
27  */
28 public class DebugThread extends DebugProcessCommand {
29     
30   /**
31    *
32    * @exception jde.debugger.JDEException <description>
33    */
34   public void doCommand() throws JDEException {
35         
36     if (m_args.size() < 1)
37       throw new JDEException("Insufficient arguments");
38         
39     // find the thread to debug
40     Long uniqueID = Etc.safeGetLong(m_args.remove(0), "thread ID");
41         
42     ThreadReference tRef = (ThreadReference) m_debugger.getStore().get(uniqueID);
43         
44     // it should exist
45     if (tRef == null) {
46       throw new JDEException("Invalid thread ID or the thread is dead");
47     }
48         
49     // suspend the whole vm
50     m_debugger.getVM().suspend();
51         
52     // simulate a step event
53     try {
54       final String locationRep = Rep.getLocationRep(tRef.frame(0).location());
55       final String lispForm    = "(list '"
56         +EVENT_STEP_COMPLETED
57         +" "+locationRep
58         +")";
59             
60       JDE.signal(m_debugger.getProcID(), EVENTSET, 
61                  "\"thread\" " + 
62                  Rep.getThreadRep(tRef) + BR + lispForm);
63       m_debugger.signalCommandResult(m_cmdID, null, CMD_OK);
64     }
65     catch ( IncompatibleThreadStateException exc ) {
66       // this should never happen...
67       throw new JDEException(exc.toString());
68     }
69   }
70
71   public Object clone() {return new DebugThread();}
72   
73 } // DebugThread
74
75 /*
76  * $Log: DebugThread.java,v $
77  * Revision 1.3  2003/01/15 05:56:26  paulk
78  * Add Petter Mahlen's changes.
79  *
80  * Revision 1.2  2001/07/07 04:51:35  paulk
81  * Removed DOS line endings.
82  *
83  * Revision 1.1  2001/07/06 02:04:50  paulk
84  * Initial revision.
85  *
86  *
87  *
88  */
89
90 // End of DebugThread.java