Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / VMUtil.java
1 package jde.debugger;
2
3 import java.util.Iterator;
4 import java.util.List;
5
6 import com.sun.jdi.Bootstrap;
7 import com.sun.jdi.VirtualMachine;
8 import com.sun.jdi.connect.Connector;
9 import com.sun.jdi.VMDisconnectedException;
10
11
12 /**
13  * Contains a couple of static functions that simplify managing
14  * virtual machines. Some kind of rearrangement between this class and
15  * the {@link Debugger} class should probably be made - this class
16  * doesn't feel so meaningful at the moment, whereas the methods for
17  * launching/attaching/listening to VMs in the Debugger class are
18  * messy. Something for the future.
19  *
20  * <p>
21  * Created: Tue Jan 08 18:49:28 2002
22  *
23  * @author Petter Måhlén
24  * @version 1.0
25  */
26
27 public class VMUtil {
28     private static List s_connectors = Bootstrap.virtualMachineManager().allConnectors();
29
30     private VMUtil() {
31     }
32     
33     /**
34      * Gets a connector.
35      *
36      * @param type connector class name
37      *
38      */    
39     public static final Connector getConnector(String name) {
40         Iterator iter = s_connectors.iterator();
41         while (iter.hasNext()) {
42             Connector connector = (Connector)iter.next();
43             if (connector.name().equals(name)) {
44                 return connector;
45             }
46         }
47         return null;
48     }
49
50
51     /**
52      * Shut down the indicated virtual machine.
53      *
54      * @param vm a <code>VirtualMachine</code> value
55      */
56     public static void shutdown(VirtualMachine vm) {
57         /*
58          * taken from the original (Amit Kumar) DebuggeeProcess.shutdown()
59          *
60          * XXX
61          * As far as I can understand, vm.dispose() doesn't terminate the process
62          * that is being debugged. It seems to me as if doing so would be necessary
63          * (otherwise the VM process should be orphaned), so this needs to be
64          * analysed. / Petter
65          */
66         
67         // isolate the process first
68         Process process = null;
69         if (vm != null) {
70             try {
71                 process = vm.process();
72                 vm.dispose();
73             }
74             catch (VMDisconnectedException e) {
75                 // If it's already disconnected, no problem, so just ignore it.
76             }
77         }
78         
79         if (process != null) {
80             process.destroy();
81             // XXX sun's jdb implementation works a lot to make sure
82             // the stderr and stdout are dumped before killing
83             // things. i'm not sure how important it is, or even how
84             // well it works (given i can't test it)
85             // sooo, if the reader finds bugs with the output handling
86             // on finish, lemme know. (comment by Amit Kumar)
87         }
88     }
89
90 }// VMUtil