annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java @ 6073:78d2ae5ab35b

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