annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java @ 6782:5a98bf7d847b

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