annotate agent/src/share/classes/sun/jvm/hotspot/DebugServer.java @ 1913:3b2dea75431e

6984311: JSR 292 needs optional bootstrap method parameters Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands. Reviewed-by: twisti
author jrose
date Sat, 30 Oct 2010 13:08:23 -0700
parents c18cbe5936b8
children f6f3bb0ee072
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.dbx.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public class DebugServer {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 System.out.println("usage: java " + getClass().getName() + " <pid> [server id]");
a61af66fc99e Initial load
duke
parents:
diff changeset
35 System.out.println(" or: java " + getClass().getName() + " <executable> <core> [server id]");
a61af66fc99e Initial load
duke
parents:
diff changeset
36 System.out.println("\"pid\" must be the process ID of a HotSpot process.");
a61af66fc99e Initial load
duke
parents:
diff changeset
37 System.out.println("If reading a core file, \"executable\" must (currently) be the");
a61af66fc99e Initial load
duke
parents:
diff changeset
38 System.out.println("full path name to the precise java executable which generated");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 System.out.println("the core file (not, on Solaris, the \"java\" wrapper script in");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 System.out.println("the \"bin\" subdirectory of the JDK.)");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 System.out.println("The \"server id\" is a unique name for a specific remote debuggee.");
a61af66fc99e Initial load
duke
parents:
diff changeset
42 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 new DebugServer().run(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private void run(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if ((args.length < 1) || (args.length > 3)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Attempt to handle "-h" or "-help"
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if (args[0].startsWith("-")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 int pid = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 boolean usePid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 String coreFileName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // FIXME: would be nice to pick this up from the core file
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // somehow, but that doesn't look possible. Should at least figure
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // it out from a path to the JDK.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 String javaExecutableName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 String serverID = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 usePid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // either we have pid and server id or exec file and core file
a61af66fc99e Initial load
duke
parents:
diff changeset
80 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 usePid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 serverID = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
84 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 pid = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 usePid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 javaExecutableName = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
88 coreFileName = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
93 javaExecutableName = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
94 coreFileName = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
95 serverID = args[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
96 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // should not happend, taken care already.
a61af66fc99e Initial load
duke
parents:
diff changeset
100 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 final HotSpotAgent agent = new HotSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (usePid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 System.err.println("Attaching to process ID " + pid + " and starting RMI services, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 agent.startServer(pid, serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 System.err.println("Attaching to core " + coreFileName +
a61af66fc99e Initial load
duke
parents:
diff changeset
110 " from executable " + javaExecutableName + " and starting RMI services, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
111 agent.startServer(javaExecutableName, coreFileName, serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (usePid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 System.err.print("Error attaching to process or starting server: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
117 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 System.err.print("Error attaching to core file or starting server: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // shutdown hook to clean-up the server in case of forced exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
125 Runtime.getRuntime().addShutdownHook(new java.lang.Thread(
a61af66fc99e Initial load
duke
parents:
diff changeset
126 new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 agent.shutdownServer();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
131 System.err.println("Debugger attached and RMI services started.");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }