annotate agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
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, 2006, 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 java.io.PrintStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.rmi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.dbx.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.proc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.remote.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.win32.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.debugger.windbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.debugger.linux.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 /** <P> This class wraps much of the basic functionality and is the
a61af66fc99e Initial load
duke
parents:
diff changeset
44 * highest-level factory for VM data structures. It makes it simple
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * to start up the debugging system. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
46 *
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * <P> FIXME: need to add a way to configure the paths to dbx and the
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * DSO from the outside. However, this should work for now for
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * internal use. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
50 *
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * <P> FIXME: especially with the addition of remote debugging, this
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * has turned into a mess; needs rethinking. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
53 */
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public class HotSpotAgent {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private JVMDebugger debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private MachineDescription machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private TypeDataBase db;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private String os;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private String cpu;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private String fileSep;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // The system can work in several ways:
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // - Attaching to local process
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // - Attaching to local core file
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // - Connecting to remote debug server
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // - Starting debug server for process
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // - Starting debug server for core file
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // These are options for the "client" side of things
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private static final int PROCESS_MODE = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private static final int CORE_FILE_MODE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private static final int REMOTE_MODE = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 private int startupMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // This indicates whether we are really starting a server or not
a61af66fc99e Initial load
duke
parents:
diff changeset
78 private boolean isServer;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // All possible required information for connecting
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private int pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 private String javaExecutableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 private String coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 private String debugServerID;
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // All needed information for server side
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private String serverID;
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 private String[] jvmLibNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // FIXME: make these configurable, i.e., via a dotfile; also
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // consider searching within the JDK from which this Java executable
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // comes to find them
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private static final String defaultDbxPathPrefix = "/net/jano.sfbay/export/disk05/hotspot/sa";
a61af66fc99e Initial load
duke
parents:
diff changeset
95 private static final String defaultDbxSvcAgentDSOPathPrefix = "/net/jano.sfbay/export/disk05/hotspot/sa";
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static void showUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 System.out.println(" You can also pass these -D options to java to specify where to find dbx and the \n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
99 " Serviceability Agent plugin for dbx:");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 System.out.println(" -DdbxPathName=<path-to-dbx-executable>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
101 " Default is derived from dbxPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 System.out.println(" or");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 System.out.println(" -DdbxPathPrefix=<xxx>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
104 " where xxx is the path name of a dir structure that contains:\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
105 " <os>/<arch>/bin/dbx\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
106 " The default is " + defaultDbxPathPrefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 System.out.println(" and");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 System.out.println(" -DdbxSvcAgentDSOPathName=<path-to-dbx-serviceability-agent-module>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
109 " Default is determined from dbxSvcAgentDSOPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 System.out.println(" or");
a61af66fc99e Initial load
duke
parents:
diff changeset
111 System.out.println(" -DdbxSvcAgentDSOPathPrefix=<xxx>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
112 " where xxx is the pathname of a dir structure that contains:\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
113 " <os>/<arch>/bin/lib/libsvc_agent_dbx.so\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
114 " The default is " + defaultDbxSvcAgentDSOPathPrefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public HotSpotAgent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // for non-server add shutdown hook to clean-up debugger in case
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // of forced exit. For remote server, shutdown hook is added by
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // DebugServer.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 Runtime.getRuntime().addShutdownHook(new java.lang.Thread(
a61af66fc99e Initial load
duke
parents:
diff changeset
122 new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 synchronized (HotSpotAgent.this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Accessors (once the system is set up)
a61af66fc99e Initial load
duke
parents:
diff changeset
135 //
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public synchronized Debugger getDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public synchronized TypeDataBase getTypeDataBase() {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return db;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Client-side operations
a61af66fc99e Initial load
duke
parents:
diff changeset
147 //
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 /** This attaches to a process running on the local machine. */
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public synchronized void attach(int processID)
a61af66fc99e Initial load
duke
parents:
diff changeset
151 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 startupMode = PROCESS_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 /** This opens a core file on the local machine */
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public synchronized void attach(String javaExecutableName, String coreFileName)
a61af66fc99e Initial load
duke
parents:
diff changeset
163 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if ((javaExecutableName == null) || (coreFileName == null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 throw new DebuggerException("Both the core file name and Java executable name must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 this.javaExecutableName = javaExecutableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 this.coreFileName = coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 startupMode = CORE_FILE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 /** This attaches to a "debug server" on a remote machine; this
a61af66fc99e Initial load
duke
parents:
diff changeset
178 remote server has already attached to a process or opened a
a61af66fc99e Initial load
duke
parents:
diff changeset
179 core file and is waiting for RMI calls on the Debugger object to
a61af66fc99e Initial load
duke
parents:
diff changeset
180 come in. */
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public synchronized void attach(String remoteServerID)
a61af66fc99e Initial load
duke
parents:
diff changeset
182 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 throw new DebuggerException("Already attached to a process");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (remoteServerID == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 throw new DebuggerException("Debug server id must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 debugServerID = remoteServerID;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 startupMode = REMOTE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
192 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 /** This should only be called by the user on the client machine,
a61af66fc99e Initial load
duke
parents:
diff changeset
197 not the server machine */
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public synchronized boolean detach() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 throw new DebuggerException("Should not call detach() for server configuration");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return detachInternal();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // Server-side operations
a61af66fc99e Initial load
duke
parents:
diff changeset
207 //
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 /** This attaches to a process running on the local machine and
a61af66fc99e Initial load
duke
parents:
diff changeset
210 starts a debug server, allowing remote machines to connect and
a61af66fc99e Initial load
duke
parents:
diff changeset
211 examine this process. Uses specified name to uniquely identify a
a61af66fc99e Initial load
duke
parents:
diff changeset
212 specific debuggee on the server */
a61af66fc99e Initial load
duke
parents:
diff changeset
213 public synchronized void startServer(int processID, String uniqueID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 startupMode = PROCESS_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 isServer = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 serverID = uniqueID;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 /** This attaches to a process running on the local machine and
a61af66fc99e Initial load
duke
parents:
diff changeset
225 starts a debug server, allowing remote machines to connect and
a61af66fc99e Initial load
duke
parents:
diff changeset
226 examine this process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
227 public synchronized void startServer(int processID)
a61af66fc99e Initial load
duke
parents:
diff changeset
228 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 startServer(processID, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 /** This opens a core file on the local machine and starts a debug
a61af66fc99e Initial load
duke
parents:
diff changeset
233 server, allowing remote machines to connect and examine this
a61af66fc99e Initial load
duke
parents:
diff changeset
234 core file. Uses supplied uniqueID to uniquely identify a specific
a61af66fc99e Initial load
duke
parents:
diff changeset
235 debugee */
a61af66fc99e Initial load
duke
parents:
diff changeset
236 public synchronized void startServer(String javaExecutableName,
a61af66fc99e Initial load
duke
parents:
diff changeset
237 String coreFileName,
a61af66fc99e Initial load
duke
parents:
diff changeset
238 String uniqueID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if ((javaExecutableName == null) || (coreFileName == null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 throw new DebuggerException("Both the core file name and Java executable name must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 this.javaExecutableName = javaExecutableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 this.coreFileName = coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 startupMode = CORE_FILE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 isServer = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 serverID = uniqueID;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 /** This opens a core file on the local machine and starts a debug
a61af66fc99e Initial load
duke
parents:
diff changeset
254 server, allowing remote machines to connect and examine this
a61af66fc99e Initial load
duke
parents:
diff changeset
255 core file. */
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public synchronized void startServer(String javaExecutableName, String coreFileName)
a61af66fc99e Initial load
duke
parents:
diff changeset
257 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 startServer(javaExecutableName, coreFileName, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 /** This may only be called on the server side after startServer()
a61af66fc99e Initial load
duke
parents:
diff changeset
262 has been called */
a61af66fc99e Initial load
duke
parents:
diff changeset
263 public synchronized boolean shutdownServer() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 throw new DebuggerException("Should not call shutdownServer() for client configuration");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return detachInternal();
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
273 //
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 private boolean detachInternal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if (debugger == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 boolean retval = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 VM.shutdown();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // We must not call detach() if we are a client and are connected
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // to a remote debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
285 Debugger dbg = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 DebuggerException ex = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 RMIHelper.unbind(serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 catch (DebuggerException de) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 ex = de;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 dbg = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 dbg = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (dbg != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 retval = dbg.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 debugger = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
305 machDesc = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 db = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (ex != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 throw(ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return retval;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 private void go() {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 setupDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 setupVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 private void setupDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 //
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // Local mode (client attaching to local process or setting up
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // server, but not client attaching to server)
a61af66fc99e Initial load
duke
parents:
diff changeset
323 //
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 os = PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
327 cpu = PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 catch (UnsupportedPlatformException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 fileSep = System.getProperty("file.separator");
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 setupDebuggerSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
336 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 setupDebuggerWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 setupDebuggerLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Add support for more operating systems here
a61af66fc99e Initial load
duke
parents:
diff changeset
342 throw new DebuggerException("Operating system " + os + " not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 RemoteDebuggerServer remote = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 remote = new RemoteDebuggerServer(debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350 catch (RemoteException rem) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 throw new DebuggerException(rem);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 RMIHelper.rebind(serverID, remote);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 //
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // Remote mode (client attaching to server)
a61af66fc99e Initial load
duke
parents:
diff changeset
358 //
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // Create and install a security manager
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 // FIXME: currently commented out because we were having
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // security problems since we're "in the sun.* hierarchy" here.
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // Perhaps a permissive policy file would work around this. In
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // the long run, will probably have to move into com.sun.*.
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // if (System.getSecurityManager() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // System.setSecurityManager(new RMISecurityManager());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 connectRemoteDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375 private void setupVM() {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // We need to instantiate a HotSpotTypeDataBase on both the client
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // and server machine. On the server it is only currently used to
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // configure the Java primitive type sizes (which we should
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // consider making constant). On the client it is used to
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // configure the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 db = new HotSpotTypeDataBase(machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
385 new HotSpotSolarisVtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
386 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
387 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 db = new HotSpotTypeDataBase(machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
389 new Win32VtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
390 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 db = new HotSpotTypeDataBase(machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
393 new LinuxVtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
394 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess yet)");
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399 catch (NoSuchSymbolException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 throw new DebuggerException("Doesn't appear to be a HotSpot VM (could not find symbol \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
401 e.getSymbol() + "\" in remote process)");
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 // Configure the debugger with the primitive type sizes just obtained from the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
406 debugger.configureJavaPrimitiveTypeSizes(db.getJBooleanType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
407 db.getJByteType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
408 db.getJCharType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
409 db.getJDoubleType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
410 db.getJFloatType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
411 db.getJIntType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
412 db.getJLongType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
413 db.getJShortType().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Do not initialize the VM on the server (unnecessary, since it's
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // instantiated on the client)
a61af66fc99e Initial load
duke
parents:
diff changeset
419 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 VM.initialize(db, debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 } catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 throw (e);
a61af66fc99e Initial load
duke
parents:
diff changeset
423 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
430 // OS-specific debugger setup/connect routines
a61af66fc99e Initial load
duke
parents:
diff changeset
431 //
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 //
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
435 //
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 private void setupDebuggerSolaris() {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 setupJVMLibNamesSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if(System.getProperty("sun.jvm.hotspot.debugger.useProcDebugger") != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 debugger = dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // Set up CPU-dependent stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
445 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
446 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
447 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
448 int addressSize = dbg.getRemoteProcessAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (addressSize == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 throw new DebuggerException("Error occurred while trying to determine the remote process's " +
a61af66fc99e Initial load
duke
parents:
diff changeset
451 "address size");
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (addressSize == 32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 } else if (addressSize == 64) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
458 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
463 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 dbg.setMachineDescription(machDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 String dbxPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 String dbxPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
473 String dbxSvcAgentDSOPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 String dbxSvcAgentDSOPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
475 String[] dbxSvcAgentDSOPathNames = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // use path names/prefixes specified on command
a61af66fc99e Initial load
duke
parents:
diff changeset
478 dbxPathName = System.getProperty("dbxPathName");
a61af66fc99e Initial load
duke
parents:
diff changeset
479 if (dbxPathName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 dbxPathPrefix = System.getProperty("dbxPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
481 if (dbxPathPrefix == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 dbxPathPrefix = defaultDbxPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 dbxPathName = dbxPathPrefix + fileSep + os + fileSep + cpu + fileSep + "bin" + fileSep + "dbx";
a61af66fc99e Initial load
duke
parents:
diff changeset
485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 dbxSvcAgentDSOPathName = System.getProperty("dbxSvcAgentDSOPathName");
a61af66fc99e Initial load
duke
parents:
diff changeset
488 if (dbxSvcAgentDSOPathName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 dbxSvcAgentDSOPathNames = new String[] { dbxSvcAgentDSOPathName } ;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 dbxSvcAgentDSOPathPrefix = System.getProperty("dbxSvcAgentDSOPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (dbxSvcAgentDSOPathPrefix == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 dbxSvcAgentDSOPathPrefix = defaultDbxSvcAgentDSOPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 dbxSvcAgentDSOPathNames = new String[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // FIXME: bad hack for SPARC v9. This is necessary because
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // there are two dbx executables on SPARC, one for v8 and one
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // for v9, and it isn't obvious how to tell the two apart
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // using the dbx command line. See
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // DbxDebuggerLocal.importDbxModule().
a61af66fc99e Initial load
duke
parents:
diff changeset
502 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + "v9" + fileSep + "lib" +
a61af66fc99e Initial load
duke
parents:
diff changeset
503 fileSep + "libsvc_agent_dbx.so",
a61af66fc99e Initial load
duke
parents:
diff changeset
504 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" +
a61af66fc99e Initial load
duke
parents:
diff changeset
505 fileSep + "libsvc_agent_dbx.so",
a61af66fc99e Initial load
duke
parents:
diff changeset
506 };
a61af66fc99e Initial load
duke
parents:
diff changeset
507 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 dbxSvcAgentDSOPathNames = new String[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" +
a61af66fc99e Initial load
duke
parents:
diff changeset
510 fileSep + "libsvc_agent_dbx.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
511 };
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 // Note we do not use a cache for the local debugger in server
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // mode; it's taken care of on the client side
a61af66fc99e Initial load
duke
parents:
diff changeset
517 DbxDebuggerLocal dbg = new DbxDebuggerLocal(null, dbxPathName, dbxSvcAgentDSOPathNames, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 debugger = dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // Set up CPU-dependent stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
525 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 int addressSize = dbg.getRemoteProcessAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (addressSize == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 throw new DebuggerException("Error occurred while trying to determine the remote process's " +
a61af66fc99e Initial load
duke
parents:
diff changeset
529 "address size. It's possible that the Serviceability Agent's dbx module failed to " +
a61af66fc99e Initial load
duke
parents:
diff changeset
530 "initialize. Examine the standard output and standard error streams from the dbx " +
a61af66fc99e Initial load
duke
parents:
diff changeset
531 "process for more information.");
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 if (addressSize == 32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
536 } else if (addressSize == 64) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
538 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542
a61af66fc99e Initial load
duke
parents:
diff changeset
543 dbg.setMachineDescription(machDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546 }
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 private void connectRemoteDebugger() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 RemoteDebugger remote =
a61af66fc99e Initial load
duke
parents:
diff changeset
550 (RemoteDebugger) RMIHelper.lookup(debugServerID);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 debugger = new RemoteDebuggerClient(remote);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
a61af66fc99e Initial load
duke
parents:
diff changeset
553 os = debugger.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
554 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
555 setupJVMLibNamesSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
556 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 setupJVMLibNamesWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
558 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
559 setupJVMLibNamesLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
560 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 throw new RuntimeException("Unknown OS type");
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 cpu = debugger.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 private void setupJVMLibNamesSolaris() {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so", "gamma_g" };
a61af66fc99e Initial load
duke
parents:
diff changeset
569 }
a61af66fc99e Initial load
duke
parents:
diff changeset
570
a61af66fc99e Initial load
duke
parents:
diff changeset
571 //
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // Win32
a61af66fc99e Initial load
duke
parents:
diff changeset
573 //
a61af66fc99e Initial load
duke
parents:
diff changeset
574
a61af66fc99e Initial load
duke
parents:
diff changeset
575 private void setupDebuggerWin32() {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 setupJVMLibNamesWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
580 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
582 } else if (cpu.equals("ia64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 machDesc = new MachineDescriptionIA64();
a61af66fc99e Initial load
duke
parents:
diff changeset
584 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587
a61af66fc99e Initial load
duke
parents:
diff changeset
588 // Note we do not use a cache for the local debugger in server
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // mode; it will be taken care of on the client side (once remote
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // debugging is implemented).
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 if (System.getProperty("sun.jvm.hotspot.debugger.useWindbgDebugger") != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 debugger = new Win32DebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
596 }
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // FIXME: add support for server mode
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 private void setupJVMLibNamesWin32() {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 //
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // Linux
a61af66fc99e Initial load
duke
parents:
diff changeset
609 //
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 private void setupDebuggerLinux() {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 setupJVMLibNamesLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
616 } else if (cpu.equals("ia64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 machDesc = new MachineDescriptionIA64();
a61af66fc99e Initial load
duke
parents:
diff changeset
618 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 if (LinuxDebuggerLocal.getAddressSize()==8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
622 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
623 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
627 throw new DebuggerException("Linux only supported on x86/ia64/amd64/sparc/sparc64");
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 LinuxDebuggerLocal dbg =
a61af66fc99e Initial load
duke
parents:
diff changeset
631 new LinuxDebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
632 debugger = dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 private void setupJVMLibNamesLinux() {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 /** Convenience routine which should be called by per-platform
a61af66fc99e Initial load
duke
parents:
diff changeset
642 debugger setup. Should not be called when startupMode is
a61af66fc99e Initial load
duke
parents:
diff changeset
643 REMOTE_MODE. */
a61af66fc99e Initial load
duke
parents:
diff changeset
644 private void attachDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 if (startupMode == PROCESS_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 debugger.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 } else if (startupMode == CORE_FILE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 debugger.attach(javaExecutableName, coreFileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
649 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 throw new DebuggerException("Should not call attach() for startupMode == " + startupMode);
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }