annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.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) 2002, 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.bugspot;
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.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.dbx.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.proc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.debugger.win32.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.debugger.windbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.debugger.linux.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.debugger.sparc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.debugger.remote.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.livejvm.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 /** <P> This class wraps the basic functionality for connecting to the
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * target process or debug server. It makes it simple to start up the
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * debugging system. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
50 *
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * <P> This agent (as compared to the HotSpotAgent) can connect to
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * and interact with arbitrary processes. If the target process
a61af66fc99e Initial load
duke
parents:
diff changeset
53 * happens to be a HotSpot JVM, the Java debugging features of the
a61af66fc99e Initial load
duke
parents:
diff changeset
54 * Serviceability Agent are enabled. Further, if the Serviceability
a61af66fc99e Initial load
duke
parents:
diff changeset
55 * Agent's JVMDI module is loaded into the target VM, interaction
a61af66fc99e Initial load
duke
parents:
diff changeset
56 * with the live Java program is possible, specifically the catching
a61af66fc99e Initial load
duke
parents:
diff changeset
57 * of exceptions and setting of breakpoints. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
58 *
a61af66fc99e Initial load
duke
parents:
diff changeset
59 * <P> The BugSpot debugger requires that the underlying Debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
60 * support C/C++ debugging via the CDebugger interface. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
61 *
a61af66fc99e Initial load
duke
parents:
diff changeset
62 * <P> FIXME: need to add a way to configure the paths to dbx and the
a61af66fc99e Initial load
duke
parents:
diff changeset
63 * DSO from the outside. However, this should work for now for
a61af66fc99e Initial load
duke
parents:
diff changeset
64 * internal use. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
65 *
a61af66fc99e Initial load
duke
parents:
diff changeset
66 * <P> FIXME: especially with the addition of remote debugging, this
a61af66fc99e Initial load
duke
parents:
diff changeset
67 * has turned into a mess; needs rethinking. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public class BugSpotAgent {
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private JVMDebugger debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private MachineDescription machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private TypeDataBase db;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 private String os;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private String cpu;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 private String fileSep;
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // The system can work in several ways:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // - Attaching to local process
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // - Attaching to local core file
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // - Connecting to remote debug server
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // - Starting debug server for process
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // - Starting debug server for core file
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // These are options for the "client" side of things
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private static final int PROCESS_MODE = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 private static final int CORE_FILE_MODE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 private static final int REMOTE_MODE = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 private int startupMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // This indicates whether we are really starting a server or not
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private boolean isServer;
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // All possible required information for connecting
a61af66fc99e Initial load
duke
parents:
diff changeset
96 private int pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 private String executableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 private String coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 private String debugServerID;
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // All needed information for server side
a61af66fc99e Initial load
duke
parents:
diff changeset
102 private String serverID;
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Indicates whether we are attached to a HotSpot JVM or not
a61af66fc99e Initial load
duke
parents:
diff changeset
105 private boolean javaMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Indicates whether we have process control over a live HotSpot JVM
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // or not; non-null if so.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 private ServiceabilityAgentJVMDIModule jvmdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // While handling C breakpoints interactivity with the Java program
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // is forbidden. Too many invariants are broken while the target is
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // stopped at a C breakpoint to risk making JVMDI calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private boolean javaInteractionDisabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 private String[] jvmLibNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 private String[] saLibNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // FIXME: make these configurable, i.e., via a dotfile; also
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // consider searching within the JDK from which this Java executable
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // comes to find them
a61af66fc99e Initial load
duke
parents:
diff changeset
121 private static final String defaultDbxPathPrefix = "/net/jano.eng/export/disk05/hotspot/sa";
a61af66fc99e Initial load
duke
parents:
diff changeset
122 private static final String defaultDbxSvcAgentDSOPathPrefix = "/net/jano.eng/export/disk05/hotspot/sa";
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private static final boolean DEBUG;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 DEBUG = System.getProperty("sun.jvm.hotspot.bugspot.BugSpotAgent.DEBUG")
a61af66fc99e Initial load
duke
parents:
diff changeset
127 != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 static void debugPrintln(String str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 System.err.println(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 static void showUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 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
138 " Serviceability Agent plugin for dbx:");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 System.out.println(" -DdbxPathName=<path-to-dbx-executable>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
140 " Default is derived from dbxPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 System.out.println(" or");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 System.out.println(" -DdbxPathPrefix=<xxx>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
143 " where xxx is the path name of a dir structure that contains:\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
144 " <os>/<arch>/bin/dbx\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
145 " The default is " + defaultDbxPathPrefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 System.out.println(" and");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 System.out.println(" -DdbxSvcAgentDSOPathName=<path-to-dbx-serviceability-agent-module>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
148 " Default is determined from dbxSvcAgentDSOPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 System.out.println(" or");
a61af66fc99e Initial load
duke
parents:
diff changeset
150 System.out.println(" -DdbxSvcAgentDSOPathPrefix=<xxx>\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
151 " where xxx is the pathname of a dir structure that contains:\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
152 " <os>/<arch>/bin/lib/libsvc_agent_dbx.so\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
153 " The default is " + defaultDbxSvcAgentDSOPathPrefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public BugSpotAgent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // for non-server add shutdown hook to clean-up debugger in case
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // of forced exit. For remote server, shutdown hook is added by
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // DebugServer.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 Runtime.getRuntime().addShutdownHook(new java.lang.Thread(
a61af66fc99e Initial load
duke
parents:
diff changeset
161 new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 synchronized (BugSpotAgent.this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Accessors (once the system is set up)
a61af66fc99e Initial load
duke
parents:
diff changeset
174 //
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 public synchronized Debugger getDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 public synchronized CDebugger getCDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return getDebugger().getCDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 public synchronized ProcessControl getProcessControl() {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return getCDebugger().getProcessControl();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 public synchronized TypeDataBase getTypeDataBase() {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return db;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 /** Indicates whether the target process is suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
193 completely. Equivalent to getProcessControl().isSuspended(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public synchronized boolean isSuspended() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return getProcessControl().isSuspended();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 /** Suspends the target process completely. Equivalent to
a61af66fc99e Initial load
duke
parents:
diff changeset
199 getProcessControl().suspend(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
200 public synchronized void suspend() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 getProcessControl().suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 /** Resumes the target process completely. Equivalent to
a61af66fc99e Initial load
duke
parents:
diff changeset
205 getProcessControl().suspend(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
206 public synchronized void resume() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 getProcessControl().resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 /** Indicates whether we are attached to a Java HotSpot virtual
a61af66fc99e Initial load
duke
parents:
diff changeset
211 machine */
a61af66fc99e Initial load
duke
parents:
diff changeset
212 public synchronized boolean isJavaMode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return javaMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 /** Temporarily disables interaction with the target process via
a61af66fc99e Initial load
duke
parents:
diff changeset
217 JVMDI. This is done while the target process is stopped at a C
a61af66fc99e Initial load
duke
parents:
diff changeset
218 breakpoint. Can be called even if the JVMDI agent has not been
a61af66fc99e Initial load
duke
parents:
diff changeset
219 initialized. */
a61af66fc99e Initial load
duke
parents:
diff changeset
220 public synchronized void disableJavaInteraction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 javaInteractionDisabled = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 /** Re-enables interaction with the target process via JVMDI. This
a61af66fc99e Initial load
duke
parents:
diff changeset
225 is done while the target process is continued past a C
a61af66fc99e Initial load
duke
parents:
diff changeset
226 braekpoint. Can be called even if the JVMDI agent has not been
a61af66fc99e Initial load
duke
parents:
diff changeset
227 initialized. */
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public synchronized void enableJavaInteraction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 javaInteractionDisabled = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 /** Indicates whether Java interaction has been disabled */
a61af66fc99e Initial load
duke
parents:
diff changeset
233 public synchronized boolean isJavaInteractionDisabled() {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return javaInteractionDisabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 /** Indicates whether we can talk to the Serviceability Agent's
a61af66fc99e Initial load
duke
parents:
diff changeset
238 JVMDI module to be able to set breakpoints */
a61af66fc99e Initial load
duke
parents:
diff changeset
239 public synchronized boolean canInteractWithJava() {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 return (jvmdi != null) && !javaInteractionDisabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 /** Suspends all Java threads in the target process. Can only be
a61af66fc99e Initial load
duke
parents:
diff changeset
244 called if we are attached to a HotSpot JVM and can connect to
a61af66fc99e Initial load
duke
parents:
diff changeset
245 the SA's JVMDI module. Must not be called when the target
a61af66fc99e Initial load
duke
parents:
diff changeset
246 process has been suspended with suspend(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
247 public synchronized void suspendJava() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 throw new DebuggerException("Could not connect to SA's JVMDI module");
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 if (jvmdi.isSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 throw new DebuggerException("Target process already suspended via JVMDI");
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 jvmdi.suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 /** Resumes all Java threads in the target process. Can only be
a61af66fc99e Initial load
duke
parents:
diff changeset
258 called if we are attached to a HotSpot JVM and can connect to
a61af66fc99e Initial load
duke
parents:
diff changeset
259 the SA's JVMDI module. Must not be called when the target
a61af66fc99e Initial load
duke
parents:
diff changeset
260 process has been suspended with suspend(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
261 public synchronized void resumeJava() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 throw new DebuggerException("Could not connect to SA's JVMDI module");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!jvmdi.isSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 throw new DebuggerException("Target process already resumed via JVMDI");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 jvmdi.resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 /** Indicates whether the target process has been suspended at the
a61af66fc99e Initial load
duke
parents:
diff changeset
272 Java language level via the SA's JVMDI module */
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public synchronized boolean isJavaSuspended() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return jvmdi.isSuspended();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 /** Toggle a Java breakpoint at the given location. */
a61af66fc99e Initial load
duke
parents:
diff changeset
278 public synchronized ServiceabilityAgentJVMDIModule.BreakpointToggleResult
a61af66fc99e Initial load
duke
parents:
diff changeset
279 toggleJavaBreakpoint(String srcFileName,
a61af66fc99e Initial load
duke
parents:
diff changeset
280 String pkgName,
a61af66fc99e Initial load
duke
parents:
diff changeset
281 int lineNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 throw new DebuggerException("Could not connect to SA's JVMDI module; can not toggle Java breakpoints");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 return jvmdi.toggleBreakpoint(srcFileName, pkgName, lineNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 /** Access to JVMDI module's eventPending */
a61af66fc99e Initial load
duke
parents:
diff changeset
289 public synchronized boolean javaEventPending() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 throw new DebuggerException("Could not connect to SA's JVMDI module; can not poll for Java debug events");
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 return jvmdi.eventPending();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 /** Access to JVMDI module's eventPoll */
a61af66fc99e Initial load
duke
parents:
diff changeset
297 public synchronized Event javaEventPoll() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 throw new DebuggerException("Could not connect to SA's JVMDI module; can not poll for Java debug events");
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return jvmdi.eventPoll();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 /** Access to JVMDI module's eventContinue */
a61af66fc99e Initial load
duke
parents:
diff changeset
305 public synchronized void javaEventContinue() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if (!canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 throw new DebuggerException("Could not connect to SA's JVMDI module; can not continue past Java debug events");
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309 jvmdi.eventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // FIXME: add other accessors. For example, suspension and
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // resumption should be done through this interface, as well as
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // interaction with the live Java process such as breakpoint setting.
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // Probably should not expose the ServiceabilityAgentJVMDIModule
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // from this interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // Client-side operations
a61af66fc99e Initial load
duke
parents:
diff changeset
321 //
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 /** This attaches to a process running on the local machine. */
a61af66fc99e Initial load
duke
parents:
diff changeset
324 public synchronized void attach(int processID)
a61af66fc99e Initial load
duke
parents:
diff changeset
325 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 startupMode = PROCESS_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 /** This opens a core file on the local machine */
a61af66fc99e Initial load
duke
parents:
diff changeset
336 public synchronized void attach(String executableName, String coreFileName)
a61af66fc99e Initial load
duke
parents:
diff changeset
337 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 if ((executableName == null) || (coreFileName == null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 throw new DebuggerException("Both the core file name and executable name must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344 this.executableName = executableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 this.coreFileName = coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 startupMode = CORE_FILE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 /** This attaches to a "debug server" on a remote machine; this
a61af66fc99e Initial load
duke
parents:
diff changeset
352 remote server has already attached to a process or opened a
a61af66fc99e Initial load
duke
parents:
diff changeset
353 core file and is waiting for RMI calls on the Debugger object to
a61af66fc99e Initial load
duke
parents:
diff changeset
354 come in. */
a61af66fc99e Initial load
duke
parents:
diff changeset
355 public synchronized void attach(String remoteServerID)
a61af66fc99e Initial load
duke
parents:
diff changeset
356 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 throw new DebuggerException("Already attached to a process");
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 if (remoteServerID == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 throw new DebuggerException("Debug server id must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 debugServerID = remoteServerID;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 startupMode = REMOTE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 isServer = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 /** This should only be called by the user on the client machine,
a61af66fc99e Initial load
duke
parents:
diff changeset
371 not the server machine */
a61af66fc99e Initial load
duke
parents:
diff changeset
372 public synchronized boolean detach() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 throw new DebuggerException("Should not call detach() for server configuration");
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return detachInternal();
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
a61af66fc99e Initial load
duke
parents:
diff changeset
379 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // Server-side operations
a61af66fc99e Initial load
duke
parents:
diff changeset
381 //
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 /** This attaches to a process running on the local machine and
a61af66fc99e Initial load
duke
parents:
diff changeset
384 starts a debug server, allowing remote machines to connect and
a61af66fc99e Initial load
duke
parents:
diff changeset
385 examine this process. uniqueID is used to uniquely identify the
a61af66fc99e Initial load
duke
parents:
diff changeset
386 debuggee */
a61af66fc99e Initial load
duke
parents:
diff changeset
387 public synchronized void startServer(int processID, String uniqueID)
a61af66fc99e Initial load
duke
parents:
diff changeset
388 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 startupMode = PROCESS_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 isServer = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 serverID = uniqueID;
a61af66fc99e Initial load
duke
parents:
diff changeset
396 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 /** This attaches to a process running on the local machine and
a61af66fc99e Initial load
duke
parents:
diff changeset
400 starts a debug server, allowing remote machines to connect and
a61af66fc99e Initial load
duke
parents:
diff changeset
401 examine this process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
402 public synchronized void startServer(int processID)
a61af66fc99e Initial load
duke
parents:
diff changeset
403 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 startServer(processID, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 /** This opens a core file on the local machine and starts a debug
a61af66fc99e Initial load
duke
parents:
diff changeset
408 server, allowing remote machines to connect and examine this
a61af66fc99e Initial load
duke
parents:
diff changeset
409 core file. uniqueID is used to uniquely identify the
a61af66fc99e Initial load
duke
parents:
diff changeset
410 debuggee */
a61af66fc99e Initial load
duke
parents:
diff changeset
411 public synchronized void startServer(String executableName, String coreFileName,
a61af66fc99e Initial load
duke
parents:
diff changeset
412 String uniqueID)
a61af66fc99e Initial load
duke
parents:
diff changeset
413 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (debugger != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 throw new DebuggerException("Already attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417 if ((executableName == null) || (coreFileName == null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 throw new DebuggerException("Both the core file name and Java executable name must be specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420 this.executableName = executableName;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 this.coreFileName = coreFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 startupMode = CORE_FILE_MODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 isServer = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 serverID = uniqueID;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 go();
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 /** This opens a core file on the local machine and starts a debug
a61af66fc99e Initial load
duke
parents:
diff changeset
429 server, allowing remote machines to connect and examine this
a61af66fc99e Initial load
duke
parents:
diff changeset
430 core file.*/
a61af66fc99e Initial load
duke
parents:
diff changeset
431 public synchronized void startServer(String executableName, String coreFileName)
a61af66fc99e Initial load
duke
parents:
diff changeset
432 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 startServer(executableName, coreFileName, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 /** This may only be called on the server side after startServer()
a61af66fc99e Initial load
duke
parents:
diff changeset
437 has been called */
a61af66fc99e Initial load
duke
parents:
diff changeset
438 public synchronized boolean shutdownServer() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 throw new DebuggerException("Should not call shutdownServer() for client configuration");
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 return detachInternal();
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
448 //
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450 private boolean detachInternal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (debugger == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 jvmdi.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 jvmdi = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 boolean retval = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 VM.shutdown();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // We must not call detach() if we are a client and are connected
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // to a remote debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
464 Debugger dbg = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 DebuggerException ex = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 RMIHelper.unbind(serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470 catch (DebuggerException de) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 ex = de;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 dbg = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 dbg = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 if (dbg != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 retval = dbg.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 debugger = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 machDesc = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
485 db = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (ex != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 throw(ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489 return retval;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 private void go() {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 setupDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
494 javaMode = setupVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 private void setupDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
499 //
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // Local mode (client attaching to local process or setting up
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // server, but not client attaching to server)
a61af66fc99e Initial load
duke
parents:
diff changeset
502 //
a61af66fc99e Initial load
duke
parents:
diff changeset
503
a61af66fc99e Initial load
duke
parents:
diff changeset
504 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 os = PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
506 cpu = PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508 catch (UnsupportedPlatformException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
510 }
a61af66fc99e Initial load
duke
parents:
diff changeset
511 fileSep = System.getProperty("file.separator");
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 setupDebuggerSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
515 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 setupDebuggerWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
517 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 setupDebuggerLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
519 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // Add support for more operating systems here
a61af66fc99e Initial load
duke
parents:
diff changeset
521 throw new DebuggerException("Operating system " + os + " not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
522 }
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 RemoteDebuggerServer remote = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
525 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 remote = new RemoteDebuggerServer(debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528 catch (RemoteException rem) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 throw new DebuggerException(rem);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 RMIHelper.rebind(serverID, remote);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 //
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // Remote mode (client attaching to server)
a61af66fc99e Initial load
duke
parents:
diff changeset
536 //
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // Create and install a security manager
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // FIXME: currently commented out because we were having
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // security problems since we're "in the sun.* hierarchy" here.
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // Perhaps a permissive policy file would work around this. In
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // the long run, will probably have to move into com.sun.*.
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // if (System.getSecurityManager() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // System.setSecurityManager(new RMISecurityManager());
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
548
a61af66fc99e Initial load
duke
parents:
diff changeset
549 connectRemoteDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551 }
a61af66fc99e Initial load
duke
parents:
diff changeset
552
a61af66fc99e Initial load
duke
parents:
diff changeset
553 private boolean setupVM() {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // We need to instantiate a HotSpotTypeDataBase on both the client
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // and server machine. On the server it is only currently used to
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // configure the Java primitive type sizes (which we should
a61af66fc99e Initial load
duke
parents:
diff changeset
557 // consider making constant). On the client it is used to
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // configure the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 db = new HotSpotTypeDataBase(machDesc, new HotSpotSolarisVtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
563 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 db = new HotSpotTypeDataBase(machDesc, new Win32VtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
566 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 db = new HotSpotTypeDataBase(machDesc, new LinuxVtblAccess(debugger, jvmLibNames),
a61af66fc99e Initial load
duke
parents:
diff changeset
569 debugger, jvmLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess implemented yet)");
a61af66fc99e Initial load
duke
parents:
diff changeset
572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
573 }
a61af66fc99e Initial load
duke
parents:
diff changeset
574 catch (NoSuchSymbolException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
576 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if (startupMode != REMOTE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 // Configure the debugger with the primitive type sizes just obtained from the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
581 debugger.configureJavaPrimitiveTypeSizes(db.getJBooleanType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
582 db.getJByteType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
583 db.getJCharType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
584 db.getJDoubleType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
585 db.getJFloatType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
586 db.getJIntType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
587 db.getJLongType().getSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
588 db.getJShortType().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 if (!isServer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // Do not initialize the VM on the server (unnecessary, since it's
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // instantiated on the client)
a61af66fc99e Initial load
duke
parents:
diff changeset
594 VM.initialize(db, debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 jvmdi = new ServiceabilityAgentJVMDIModule(debugger, saLibNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 if (jvmdi.canAttach()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 jvmdi.attach();
a61af66fc99e Initial load
duke
parents:
diff changeset
601 jvmdi.setCommandTimeout(6000);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 debugPrintln("Attached to Serviceability Agent's JVMDI module.");
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // Jog VM to suspended point with JVMDI module
a61af66fc99e Initial load
duke
parents:
diff changeset
604 resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
605 suspendJava();
a61af66fc99e Initial load
duke
parents:
diff changeset
606 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
607 debugPrintln("Suspended all Java threads.");
a61af66fc99e Initial load
duke
parents:
diff changeset
608 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 debugPrintln("Could not locate SA's JVMDI module; skipping attachment");
a61af66fc99e Initial load
duke
parents:
diff changeset
610 jvmdi = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
614 jvmdi = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
615 }
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // OS-specific debugger setup/connect routines
a61af66fc99e Initial load
duke
parents:
diff changeset
622 //
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 //
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
626 //
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 private void setupDebuggerSolaris() {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 setupJVMLibNamesSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
630 String prop = System.getProperty("sun.jvm.hotspot.debugger.useProcDebugger");
a61af66fc99e Initial load
duke
parents:
diff changeset
631 if (prop != null && !prop.equals("false")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
633 debugger = dbg;
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 // Set up CPU-dependent stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
637 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
639 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 int addressSize = dbg.getRemoteProcessAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (addressSize == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 throw new DebuggerException("Error occurred while trying to determine the remote process's address size");
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 if (addressSize == 32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
647 } else if (addressSize == 64) {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
649 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
654 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
655 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 dbg.setMachineDescription(machDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
659 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
660 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
661 String dbxPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
662 String dbxPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
663 String dbxSvcAgentDSOPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
664 String dbxSvcAgentDSOPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
665 String[] dbxSvcAgentDSOPathNames = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // use path names/prefixes specified on command
a61af66fc99e Initial load
duke
parents:
diff changeset
668 dbxPathName = System.getProperty("dbxPathName");
a61af66fc99e Initial load
duke
parents:
diff changeset
669 if (dbxPathName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
670 dbxPathPrefix = System.getProperty("dbxPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
671 if (dbxPathPrefix == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 dbxPathPrefix = defaultDbxPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674 dbxPathName = dbxPathPrefix + fileSep + os + fileSep + cpu + fileSep + "bin" + fileSep + "dbx";
a61af66fc99e Initial load
duke
parents:
diff changeset
675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 dbxSvcAgentDSOPathName = System.getProperty("dbxSvcAgentDSOPathName");
a61af66fc99e Initial load
duke
parents:
diff changeset
678 if (dbxSvcAgentDSOPathName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 dbxSvcAgentDSOPathNames = new String[] { dbxSvcAgentDSOPathName } ;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 dbxSvcAgentDSOPathPrefix = System.getProperty("dbxSvcAgentDSOPathPrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 if (dbxSvcAgentDSOPathPrefix == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
683 dbxSvcAgentDSOPathPrefix = defaultDbxSvcAgentDSOPathPrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685 if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 dbxSvcAgentDSOPathNames = new String[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // FIXME: bad hack for SPARC v9. This is necessary because
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // there are two dbx executables on SPARC, one for v8 and one
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // for v9, and it isn't obvious how to tell the two apart
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // using the dbx command line. See
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // DbxDebuggerLocal.importDbxModule().
a61af66fc99e Initial load
duke
parents:
diff changeset
692 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + "v9" + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so",
a61af66fc99e Initial load
duke
parents:
diff changeset
693 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so",
a61af66fc99e Initial load
duke
parents:
diff changeset
694 };
a61af66fc99e Initial load
duke
parents:
diff changeset
695 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 dbxSvcAgentDSOPathNames = new String[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
698 };
a61af66fc99e Initial load
duke
parents:
diff changeset
699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
701 // Note we do not use a cache for the local debugger in server
a61af66fc99e Initial load
duke
parents:
diff changeset
702 // mode; it's taken care of on the client side
a61af66fc99e Initial load
duke
parents:
diff changeset
703 DbxDebuggerLocal dbg = new DbxDebuggerLocal(null, dbxPathName, dbxSvcAgentDSOPathNames, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
704 debugger = dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
707
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // Set up CPU-dependent stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
709 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
711 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
712 int addressSize = dbg.getRemoteProcessAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
713 if (addressSize == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 throw new DebuggerException("Error occurred while trying to determine the remote process's address size. It's possible that the Serviceability Agent's dbx module failed to initialize. Examine the standard output and standard error streams from the dbx process for more information.");
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 if (addressSize == 32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
718 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
719 } else if (addressSize == 64) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
721 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
a61af66fc99e Initial load
duke
parents:
diff changeset
723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
724 }
a61af66fc99e Initial load
duke
parents:
diff changeset
725
a61af66fc99e Initial load
duke
parents:
diff changeset
726 dbg.setMachineDescription(machDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 private void connectRemoteDebugger() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 RemoteDebugger remote =
a61af66fc99e Initial load
duke
parents:
diff changeset
732 (RemoteDebugger) RMIHelper.lookup(debugServerID);
a61af66fc99e Initial load
duke
parents:
diff changeset
733 debugger = new RemoteDebuggerClient(remote);
a61af66fc99e Initial load
duke
parents:
diff changeset
734 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
a61af66fc99e Initial load
duke
parents:
diff changeset
735 os = debugger.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
736 if (os.equals("solaris")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 setupJVMLibNamesSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
738 } else if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
739 setupJVMLibNamesWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
740 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
741 setupJVMLibNamesLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
742 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 throw new RuntimeException("Unknown OS type");
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 cpu = debugger.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748
a61af66fc99e Initial load
duke
parents:
diff changeset
749 private void setupJVMLibNamesSolaris() {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so", "gamma_g" };
a61af66fc99e Initial load
duke
parents:
diff changeset
751 saLibNames = new String[] { "libsa.so", "libsa_g.so" };
a61af66fc99e Initial load
duke
parents:
diff changeset
752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
753
a61af66fc99e Initial load
duke
parents:
diff changeset
754 //
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // Win32
a61af66fc99e Initial load
duke
parents:
diff changeset
756 //
a61af66fc99e Initial load
duke
parents:
diff changeset
757
a61af66fc99e Initial load
duke
parents:
diff changeset
758 private void setupDebuggerWin32() {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 setupJVMLibNamesWin32();
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
762 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
763 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
765 } else if (cpu.equals("ia64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
766 machDesc = new MachineDescriptionIA64();
a61af66fc99e Initial load
duke
parents:
diff changeset
767 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770
a61af66fc99e Initial load
duke
parents:
diff changeset
771 // Note we do not use a cache for the local debugger in server
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // mode; it will be taken care of on the client side (once remote
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // debugging is implemented).
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (System.getProperty("sun.jvm.hotspot.debugger.useWindbgDebugger") != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
777 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
778 debugger = new Win32DebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
780
a61af66fc99e Initial load
duke
parents:
diff changeset
781 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
782 }
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 private void setupJVMLibNamesWin32() {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
a61af66fc99e Initial load
duke
parents:
diff changeset
786 saLibNames = new String[] { "sa.dll", "sa_g.dll" };
a61af66fc99e Initial load
duke
parents:
diff changeset
787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 //
a61af66fc99e Initial load
duke
parents:
diff changeset
790 // Linux
a61af66fc99e Initial load
duke
parents:
diff changeset
791 //
a61af66fc99e Initial load
duke
parents:
diff changeset
792
a61af66fc99e Initial load
duke
parents:
diff changeset
793 private void setupDebuggerLinux() {
a61af66fc99e Initial load
duke
parents:
diff changeset
794 setupJVMLibNamesLinux();
a61af66fc99e Initial load
duke
parents:
diff changeset
795
a61af66fc99e Initial load
duke
parents:
diff changeset
796 if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 machDesc = new MachineDescriptionIntelX86();
a61af66fc99e Initial load
duke
parents:
diff changeset
798 } else if (cpu.equals("ia64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
799 machDesc = new MachineDescriptionIA64();
a61af66fc99e Initial load
duke
parents:
diff changeset
800 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 machDesc = new MachineDescriptionAMD64();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 } else if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 if (LinuxDebuggerLocal.getAddressSize()==8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
804 machDesc = new MachineDescriptionSPARC64Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
805 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
806 machDesc = new MachineDescriptionSPARC32Bit();
a61af66fc99e Initial load
duke
parents:
diff changeset
807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
808 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 throw new DebuggerException("Linux only supported on x86/ia64/amd64/sparc/sparc64");
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811
a61af66fc99e Initial load
duke
parents:
diff changeset
812 // Note we do not use a cache for the local debugger in server
a61af66fc99e Initial load
duke
parents:
diff changeset
813 // mode; it will be taken care of on the client side (once remote
a61af66fc99e Initial load
duke
parents:
diff changeset
814 // debugging is implemented).
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 debugger = new LinuxDebuggerLocal(machDesc, !isServer);
a61af66fc99e Initial load
duke
parents:
diff changeset
817 attachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
819
a61af66fc99e Initial load
duke
parents:
diff changeset
820 private void setupJVMLibNamesLinux() {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // same as solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
822 setupJVMLibNamesSolaris();
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824
a61af66fc99e Initial load
duke
parents:
diff changeset
825 /** Convenience routine which should be called by per-platform
a61af66fc99e Initial load
duke
parents:
diff changeset
826 debugger setup. Should not be called when startupMode is
a61af66fc99e Initial load
duke
parents:
diff changeset
827 REMOTE_MODE. */
a61af66fc99e Initial load
duke
parents:
diff changeset
828 private void attachDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 if (startupMode == PROCESS_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
830 debugger.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 } else if (startupMode == CORE_FILE_MODE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
832 debugger.attach(executableName, coreFileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
833 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
834 throw new DebuggerException("Should not call attach() for startupMode == " + startupMode);
a61af66fc99e Initial load
duke
parents:
diff changeset
835 }
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }