annotate agent/src/share/classes/sun/jvm/hotspot/debugger/dbx/DbxDebuggerLocal.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.debugger.dbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.dbx.sparc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.dbx.x86.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.cdbg.CDebugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** <P> An implementation of the JVMDebugger interface which sits on
a61af66fc99e Initial load
duke
parents:
diff changeset
37 top of dbx and relies on the SA's dbx import module for
a61af66fc99e Initial load
duke
parents:
diff changeset
38 communication with the debugger. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 <P> <B>NOTE</B> that since we have the notion of fetching "Java
a61af66fc99e Initial load
duke
parents:
diff changeset
41 primitive types" from the remote process (which might have
a61af66fc99e Initial load
duke
parents:
diff changeset
42 different sizes than we expect) we have a bootstrapping
a61af66fc99e Initial load
duke
parents:
diff changeset
43 problem. We need to know the sizes of these types before we can
a61af66fc99e Initial load
duke
parents:
diff changeset
44 fetch them. The current implementation solves this problem by
a61af66fc99e Initial load
duke
parents:
diff changeset
45 requiring that it be configured with these type sizes before they
a61af66fc99e Initial load
duke
parents:
diff changeset
46 can be fetched. The readJ(Type) routines here will throw a
a61af66fc99e Initial load
duke
parents:
diff changeset
47 RuntimeException if they are called before the debugger is
a61af66fc99e Initial load
duke
parents:
diff changeset
48 configured with the Java primitive type sizes. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
49 */
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public class DbxDebuggerLocal extends DebuggerBase implements DbxDebugger {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // These may be set by DbxDebuggerRemote
a61af66fc99e Initial load
duke
parents:
diff changeset
53 protected boolean unalignedAccessesOkay;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 protected DbxThreadFactory threadFactory;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private String dbxPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private String[] dbxSvcAgentDSOPathNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private Process dbxProcess;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private StreamMonitor dbxOutStreamMonitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private StreamMonitor dbxErrStreamMonitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private PrintWriter dbxOstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private PrintWriter out;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private InputLexer in;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private Socket importModuleSocket;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private static final int PORT = 21928;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private static final int LONG_TIMEOUT = 60000;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private static final int DBX_MODULE_NOT_FOUND = 101;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private static final int DBX_MODULE_LOADED = 102;
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Implementation of Debugger interface
a61af66fc99e Initial load
duke
parents:
diff changeset
72 //
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 /** <P> machDesc may be null if it couldn't be determined yet; i.e.,
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if we're on SPARC, we need to ask the remote process whether
a61af66fc99e Initial load
duke
parents:
diff changeset
76 we're in 32- or 64-bit mode. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 <P> useCache should be set to true if debugging is being done
a61af66fc99e Initial load
duke
parents:
diff changeset
79 locally, and to false if the debugger is being created for the
a61af66fc99e Initial load
duke
parents:
diff changeset
80 purpose of supporting remote debugging. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public DbxDebuggerLocal(MachineDescription machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
82 String dbxPathName,
a61af66fc99e Initial load
duke
parents:
diff changeset
83 String[] dbxSvcAgentDSOPathNames,
a61af66fc99e Initial load
duke
parents:
diff changeset
84 boolean useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 this.dbxPathName = dbxPathName;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 this.dbxSvcAgentDSOPathNames = dbxSvcAgentDSOPathNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int cacheNumPages;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int cachePageSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if (PlatformInfo.getCPU().equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 cacheNumPages = parseCacheNumPagesProperty(2048);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 cachePageSize = 8192;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 threadFactory = new DbxSPARCThreadFactory(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 } else if (PlatformInfo.getCPU().equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 cacheNumPages = 4096;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 cachePageSize = 4096;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 threadFactory = new DbxX86ThreadFactory(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 unalignedAccessesOkay = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 throw new RuntimeException("Thread access for CPU architecture " + PlatformInfo.getCPU() + " not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Cache portion of the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Fetching data over the socket connection to dbx is relatively
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // slow. For now, this cache works best if it covers the entire
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // heap of the remote process. FIXME: at least should make this
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // tunable from the outside, i.e., via the UI. This is a 16 MB
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // cache divided on SPARC into 2048 8K pages and on x86 into
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // 4096 4K pages; the page size must be adjusted to be the OS's
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // page size. (FIXME: should pick this up from the debugger.)
a61af66fc99e Initial load
duke
parents:
diff changeset
111 initCache(cachePageSize, cacheNumPages);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 /** Only called by DbxDebuggerRemote */
a61af66fc99e Initial load
duke
parents:
diff changeset
116 protected DbxDebuggerLocal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 /** FIXME: implement this with a Runtime.exec() of ps followed by
a61af66fc99e Initial load
duke
parents:
diff changeset
120 parsing of its output */
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public boolean hasProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public List getProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 throw new DebuggerException("Not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public synchronized void attach(int processID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 launchProcess();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 dbxErrStreamMonitor.addTrigger("dbx: no process", 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 dbxErrStreamMonitor.addTrigger("dbx: Cannot open", 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 dbxErrStreamMonitor.addTrigger("dbx: Cannot find", DBX_MODULE_NOT_FOUND);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 dbxOstr = new PrintWriter(dbxProcess.getOutputStream(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 dbxOstr.println("debug - " + processID);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 dbxOstr.println("kprint -u2 \\(ready\\)");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 boolean seen = dbxErrStreamMonitor.waitFor("(ready)", LONG_TIMEOUT);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (!seen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 throw new DebuggerException("Timed out while connecting to process " + processID);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 List retVals = dbxErrStreamMonitor.getTriggersSeen();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (retVals.contains(new Integer(1))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 throw new DebuggerException("No such process " + processID);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Throws DebuggerException upon failure
a61af66fc99e Initial load
duke
parents:
diff changeset
151 importDbxModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 dbxOstr.println("svc_agent_run");
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 connectToImportModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Set "fail fast" mode on process memory reads
a61af66fc99e Initial load
duke
parents:
diff changeset
158 printlnToOutput("peek_fail_fast 1");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 throw new DebuggerException("Error while connecting to dbx process", e);
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 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public synchronized void attach(String executableName, String coreFileName) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 launchProcess();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Missing executable
a61af66fc99e Initial load
duke
parents:
diff changeset
171 dbxErrStreamMonitor.addTrigger("dbx: Cannot open", 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // Missing core file
a61af66fc99e Initial load
duke
parents:
diff changeset
173 dbxErrStreamMonitor.addTrigger("dbx: can't read", 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Corrupt executable
a61af66fc99e Initial load
duke
parents:
diff changeset
175 dbxErrStreamMonitor.addTrigger("dbx: File", 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Corrupt core file
a61af66fc99e Initial load
duke
parents:
diff changeset
177 dbxErrStreamMonitor.addTrigger("dbx: Unable to read", 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Mismatched core and executable
a61af66fc99e Initial load
duke
parents:
diff changeset
179 dbxErrStreamMonitor.addTrigger("dbx: core object name", 5);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Missing loadobject
a61af66fc99e Initial load
duke
parents:
diff changeset
181 dbxErrStreamMonitor.addTrigger("dbx: can't stat", 6);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Successful load of svc module
a61af66fc99e Initial load
duke
parents:
diff changeset
183 dbxOstr = new PrintWriter(dbxProcess.getOutputStream(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 dbxOstr.println("debug " + executableName + " " + coreFileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 dbxOstr.println("kprint -u2 \\(ready\\)");
a61af66fc99e Initial load
duke
parents:
diff changeset
186 boolean seen = dbxErrStreamMonitor.waitFor("(ready)", LONG_TIMEOUT);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (!seen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 throw new DebuggerException("Timed out while attaching to core file");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 List retVals = dbxErrStreamMonitor.getTriggersSeen();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (retVals.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (retVals.contains(new Integer(1))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 throw new DebuggerException("Can not find executable \"" + executableName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 } else if (retVals.contains(new Integer(2))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 throw new DebuggerException("Can not find core file \"" + coreFileName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } else if (retVals.contains(new Integer(3))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 throw new DebuggerException("Corrupt executable \"" + executableName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 } else if (retVals.contains(new Integer(4))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 throw new DebuggerException("Corrupt core file \"" + coreFileName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } else if (retVals.contains(new Integer(5))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 throw new DebuggerException("Mismatched core file/executable \"" + coreFileName + "\"/\"" + executableName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 throw new DebuggerException("Couldn't find all loaded libraries for executable \"" + executableName + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Throws DebuggerException upon failure
a61af66fc99e Initial load
duke
parents:
diff changeset
211 importDbxModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 dbxOstr.println("svc_agent_run");
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 connectToImportModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Set "fail fast" mode on process memory reads
a61af66fc99e Initial load
duke
parents:
diff changeset
218 printlnToOutput("peek_fail_fast 1");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 throw new DebuggerException("Error while connecting to dbx process", e);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
227 public synchronized boolean detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (dbxProcess == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if (out != null && dbxOstr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 printlnToOutput("exit");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 dbxOstr.println("exit");
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Wait briefly for the process to exit (FIXME: should make this
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // nicer)
a61af66fc99e Initial load
duke
parents:
diff changeset
239 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 Thread.sleep(500);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 catch (InterruptedException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 shutdown();
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public Address parseAddress(String addressString) throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 long addr = utils.scanAddress(addressString);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return new DbxAddress(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public String getOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
270 public String getCPU() {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 return PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 public boolean hasConsole() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 public synchronized String consoleExecuteCommand(String cmd) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // A little tricky. We need to cause the dbx import module to
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // exit, then print our command on dbx's stdin along with a
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // command which will allow our StreamMonitors to
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // resynchronize. We need save the output from the StreamMonitors
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // along the way.
a61af66fc99e Initial load
duke
parents:
diff changeset
285 printlnToOutput("exit");
a61af66fc99e Initial load
duke
parents:
diff changeset
286 importModuleSocket.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 importModuleSocket = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 out = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 in = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 dbxOstr.println("kprint \\(ready\\)");
a61af66fc99e Initial load
duke
parents:
diff changeset
291 dbxOstr.flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
292 dbxOutStreamMonitor.waitFor("(ready)", LONG_TIMEOUT);
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 dbxOutStreamMonitor.startCapture();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 dbxErrStreamMonitor.startCapture();
a61af66fc99e Initial load
duke
parents:
diff changeset
296 dbxOstr.println(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 dbxOstr.println("kprint \\(ready\\)");
a61af66fc99e Initial load
duke
parents:
diff changeset
298 dbxOutStreamMonitor.waitFor("(ready)", LONG_TIMEOUT);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 String result = dbxOutStreamMonitor.stopCapture();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 String result2 = dbxErrStreamMonitor.stopCapture();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 result = result + result2;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // Cut out the "(ready)" string
a61af66fc99e Initial load
duke
parents:
diff changeset
303 StringBuffer outBuf = new StringBuffer(result.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
304 BufferedReader reader = new BufferedReader(new StringReader(result));
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // FIXME: bug in BufferedReader? readLine returns null when
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // ready() returns true.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 String line = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 line = reader.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if ((line != null) && (!line.equals("(ready)"))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 outBuf.append(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 outBuf.append("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 } while (line != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
315 dbxOstr.println("svc_agent_run");
a61af66fc99e Initial load
duke
parents:
diff changeset
316 dbxOstr.flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 connectToImportModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return outBuf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 throw new DebuggerException("Error while executing command on dbx console", e);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 public String getConsolePrompt() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return "(dbx) ";
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 public CDebugger getCDebugger() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
337 public synchronized Address lookup(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 long addr = lookupInProcess(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 return new DbxAddress(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
346 public synchronized OopHandle lookupOop(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 long addr = lookupInProcess(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 return new DbxOopHandle(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 /** From the Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
355 public MachineDescription getMachineDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 /** Internal routine supporting lazy setting of MachineDescription,
a61af66fc99e Initial load
duke
parents:
diff changeset
360 since on SPARC we will need to query the remote process to ask
a61af66fc99e Initial load
duke
parents:
diff changeset
361 it what its data model is (32- or 64-bit). NOTE that this is NOT
a61af66fc99e Initial load
duke
parents:
diff changeset
362 present in the DbxDebugger interface because it should not be
a61af66fc99e Initial load
duke
parents:
diff changeset
363 called across the wire (until we support attaching to multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
364 remote processes via RMI -- see the documentation for
a61af66fc99e Initial load
duke
parents:
diff changeset
365 DbxDebuggerRemoteIntf.) */
a61af66fc99e Initial load
duke
parents:
diff changeset
366 public void setMachineDescription(MachineDescription machDesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 setBigEndian(machDesc.isBigEndian());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian());
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 /** Internal routine which queries the remote process about its data
a61af66fc99e Initial load
duke
parents:
diff changeset
373 model -- i.e., size of addresses. Returns -1 upon error.
a61af66fc99e Initial load
duke
parents:
diff changeset
374 Currently supported return values are 32 and 64. NOTE that this
a61af66fc99e Initial load
duke
parents:
diff changeset
375 is NOT present in the DbxDebugger interface because it should
a61af66fc99e Initial load
duke
parents:
diff changeset
376 not be called across the wire (until we support attaching to
a61af66fc99e Initial load
duke
parents:
diff changeset
377 multiple remote processes via RMI -- see the documentation for
a61af66fc99e Initial load
duke
parents:
diff changeset
378 DbxDebuggerRemoteIntf.) */
a61af66fc99e Initial load
duke
parents:
diff changeset
379 public int getRemoteProcessAddressSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (dbxProcess == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 throw new RuntimeException("Not attached to remote process");
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 printlnToOutput("address_size");
a61af66fc99e Initial load
duke
parents:
diff changeset
386 int i = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // Implementation of ThreadAccess interface
a61af66fc99e Initial load
duke
parents:
diff changeset
396 //
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 /** From the ThreadAccess interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
399 public ThreadProxy getThreadForIdentifierAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 return threadFactory.createThreadWrapper(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 public ThreadProxy getThreadForThreadId(long id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 return threadFactory.createThreadWrapper(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
408 // Overridden from DebuggerBase because we need to relax alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // constraints on x86
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 public long readJLong(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
412 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 checkJavaConfigured();
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // FIXME: allow this to be configurable. Undesirable to add a
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // dependency on the runtime package here, though, since this
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // package should be strictly underneath it.
a61af66fc99e Initial load
duke
parents:
diff changeset
417 if (unalignedAccessesOkay) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 utils.checkAlignment(address, jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 utils.checkAlignment(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422 byte[] data = readBytes(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
423 return utils.dataToJLong(data, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // Internal routines (for implementation of DbxAddress).
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // These must not be called until the MachineDescription has been set up.
a61af66fc99e Initial load
duke
parents:
diff changeset
429 //
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 /** From the DbxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
432 public String addressValueToString(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return utils.addressValueToString(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 /** Need to override this to relax alignment checks on Solaris/x86. */
a61af66fc99e Initial load
duke
parents:
diff changeset
437 public long readCInteger(long address, long numBytes, boolean isUnsigned)
a61af66fc99e Initial load
duke
parents:
diff changeset
438 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 checkConfigured();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (!unalignedAccessesOkay) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 utils.checkAlignment(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 // Only slightly relaxed semantics -- this is a hack, but is
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // necessary on Solaris/x86 where it seems the compiler is
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // putting some global 64-bit data on 32-bit boundaries
a61af66fc99e Initial load
duke
parents:
diff changeset
446 if (numBytes == 8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 utils.checkAlignment(address, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 utils.checkAlignment(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452 byte[] data = readBytes(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 return utils.dataToCInteger(data, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 /** From the DbxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
457 public DbxAddress readAddress(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
458 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 return (value == 0 ? null : new DbxAddress(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 /** From the DbxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
464 public DbxOopHandle readOopHandle(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
465 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 return (value == 0 ? null : new DbxOopHandle(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // Thread context access. Can not be package private, but should
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // only be accessed by the architecture-specific subpackages.
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 /** From the DbxDebugger interface. May have to redefine this later. */
a61af66fc99e Initial load
duke
parents:
diff changeset
475 public synchronized long[] getThreadIntegerRegisterSet(int tid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 printlnToOutput("thr_gregs " + tid);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 int num = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
479 long[] res = new long[num];
a61af66fc99e Initial load
duke
parents:
diff changeset
480 for (int i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 res[i] = in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
487 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // Address access. Can not be package private, but should only be
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // accessed by the architecture-specific subpackages.
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495 /** From the Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
496 public long getAddressValue(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (addr == null) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return ((DbxAddress) addr).getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 /** From the DbxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
502 public Address newAddress(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 if (value == 0) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 return new DbxAddress(this, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
509 //
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 private void launchProcess() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 dbxProcess = Runtime.getRuntime().exec(dbxPathName);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 // dbxOutStreamMonitor = new StreamMonitor(dbxProcess.getInputStream());
a61af66fc99e Initial load
duke
parents:
diff changeset
514 // dbxErrStreamMonitor = new StreamMonitor(dbxProcess.getErrorStream());
a61af66fc99e Initial load
duke
parents:
diff changeset
515 dbxOutStreamMonitor = new StreamMonitor(dbxProcess.getInputStream(), "dbx stdout", true);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 dbxErrStreamMonitor = new StreamMonitor(dbxProcess.getErrorStream(), "dbx stderr", true);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 /** Requires that dbxErrStreamMonitor has a trigger on "dbx: Cannot
a61af66fc99e Initial load
duke
parents:
diff changeset
520 find" with number DBX_MODULE_NOT_FOUND as well as one on "dbx:
a61af66fc99e Initial load
duke
parents:
diff changeset
521 warning:" (plus the serviceability agent's dbx module path name,
a61af66fc99e Initial load
duke
parents:
diff changeset
522 to avoid conflation with inability to load individual object
a61af66fc99e Initial load
duke
parents:
diff changeset
523 files) with number DBX_MODULE_FAILED_TO_LOAD. The former
a61af66fc99e Initial load
duke
parents:
diff changeset
524 indicates an absence of libsvc_agent_dbx.so, while the latter
a61af66fc99e Initial load
duke
parents:
diff changeset
525 indicates that the module failed to load, specifically because
a61af66fc99e Initial load
duke
parents:
diff changeset
526 the architecture was mismatched. (I don't see a way to detect
a61af66fc99e Initial load
duke
parents:
diff changeset
527 from the dbx command prompt whether it's running the v8 or v9
a61af66fc99e Initial load
duke
parents:
diff changeset
528 executbale, so we try to import both flavors of the import
a61af66fc99e Initial load
duke
parents:
diff changeset
529 module; the "v8" file name convention doesn't actually include
a61af66fc99e Initial load
duke
parents:
diff changeset
530 the v8 prefix, so this code should work for Intel as well.) */
a61af66fc99e Initial load
duke
parents:
diff changeset
531 private void importDbxModule() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // Trigger for a successful load
a61af66fc99e Initial load
duke
parents:
diff changeset
533 dbxOutStreamMonitor.addTrigger("Defining svc_agent_run", DBX_MODULE_LOADED);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 for (int i = 0; i < dbxSvcAgentDSOPathNames.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 dbxOstr.println("import " + dbxSvcAgentDSOPathNames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 dbxOstr.println("kprint -u2 \\(Ready\\)");
a61af66fc99e Initial load
duke
parents:
diff changeset
537 boolean seen = dbxErrStreamMonitor.waitFor("(Ready)", LONG_TIMEOUT);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 if (!seen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
540 throw new DebuggerException("Timed out while importing dbx module from file\n" + dbxSvcAgentDSOPathNames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542 List retVals = dbxErrStreamMonitor.getTriggersSeen();
a61af66fc99e Initial load
duke
parents:
diff changeset
543 if (retVals.contains(new Integer(DBX_MODULE_NOT_FOUND))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
544 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
545 throw new DebuggerException("Unable to find the Serviceability Agent's dbx import module at pathname \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
546 dbxSvcAgentDSOPathNames[i] + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
547 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 retVals = dbxOutStreamMonitor.getTriggersSeen();
a61af66fc99e Initial load
duke
parents:
diff changeset
549 if (retVals.contains(new Integer(DBX_MODULE_LOADED))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
550 System.out.println("importDbxModule: imported " + dbxSvcAgentDSOPathNames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Failed to load all flavors
a61af66fc99e Initial load
duke
parents:
diff changeset
557 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
558 String errMsg = ("Unable to find a version of the Serviceability Agent's dbx import module\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
559 "matching the architecture of dbx at any of the following locations:");
a61af66fc99e Initial load
duke
parents:
diff changeset
560 for (int i = 0; i < dbxSvcAgentDSOPathNames.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 errMsg = errMsg + "\n" + dbxSvcAgentDSOPathNames[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563 throw new DebuggerException(errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 /** Terminate the debugger forcibly */
a61af66fc99e Initial load
duke
parents:
diff changeset
567 private void shutdown() {
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569 if (dbxProcess != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // See whether the process has exited and, if not, terminate it
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // forcibly
a61af66fc99e Initial load
duke
parents:
diff changeset
572 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 dbxProcess.exitValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575 catch (IllegalThreadStateException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 dbxProcess.destroy();
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578 }
a61af66fc99e Initial load
duke
parents:
diff changeset
579
a61af66fc99e Initial load
duke
parents:
diff changeset
580 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 if (importModuleSocket != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 importModuleSocket.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587
a61af66fc99e Initial load
duke
parents:
diff changeset
588 // Release references to all objects
a61af66fc99e Initial load
duke
parents:
diff changeset
589 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
590 clearCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 /** Looks up an address in the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
594 Returns 0 if symbol not found or upon error. Package private to
a61af66fc99e Initial load
duke
parents:
diff changeset
595 allow DbxDebuggerRemoteIntfImpl access. */
a61af66fc99e Initial load
duke
parents:
diff changeset
596 synchronized long lookupInProcess(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 printlnToOutput("lookup " + objectName + " " + symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 return in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
603 }
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 /** This reads bytes from the remote process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
607 public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
608 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 if (numBytes < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
610 throw new DebuggerException("Can not read negative number (" + numBytes + ") of bytes from process");
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 String cmd = "peek " + utils.addressValueToString(address) + " " + numBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 printlnToOutput(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
615 while (in.readByte() != 'B') {
a61af66fc99e Initial load
duke
parents:
diff changeset
616 }
a61af66fc99e Initial load
duke
parents:
diff changeset
617 byte res = in.readByte();
a61af66fc99e Initial load
duke
parents:
diff changeset
618 if (res == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 System.err.println("Failing command: " + cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 throw new DebuggerException("Read of remote process address space failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
621 }
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // NOTE: must read ALL of the data regardless of whether we need
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // to throw an UnmappedAddressException. Otherwise will corrupt
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // the input stream each time we have a failure. Not good. Do
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // not want to risk "flushing" the input stream in case a huge
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // read has a hangup in the middle and we leave data on the
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // stream.
a61af66fc99e Initial load
duke
parents:
diff changeset
628 byte[] buf = new byte[(int) numBytes];
a61af66fc99e Initial load
duke
parents:
diff changeset
629 boolean bailOut = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 long failureAddress = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
631 int numReads = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 while (numBytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 long len = in.readUnsignedInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
634 boolean isMapped = ((in.readByte() == 0) ? false : true);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 if (!isMapped) {
a61af66fc99e Initial load
duke
parents:
diff changeset
636 if (!bailOut) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 bailOut = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 failureAddress = address;
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // This won't work if we have unmapped regions, but if we do
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // then we're going to throw an exception anyway
a61af66fc99e Initial load
duke
parents:
diff changeset
643
a61af66fc99e Initial load
duke
parents:
diff changeset
644 // NOTE: there is a factor of 20 speed difference between
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // these two ways of doing this read.
a61af66fc99e Initial load
duke
parents:
diff changeset
646 in.readBytes(buf, 0, (int) len);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Do NOT do this:
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // for (int i = 0; i < (int) len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // buf[i] = in.readByte();
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
653
a61af66fc99e Initial load
duke
parents:
diff changeset
654 numBytes -= len;
a61af66fc99e Initial load
duke
parents:
diff changeset
655 address += len;
a61af66fc99e Initial load
duke
parents:
diff changeset
656 ++numReads;
a61af66fc99e Initial load
duke
parents:
diff changeset
657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 Assert.that(numBytes == 0, "Bug in debug server's implementation of peek: numBytesLeft == " +
a61af66fc99e Initial load
duke
parents:
diff changeset
660 numBytes + ", should be 0 (did " + numReads + " reads)");
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if (bailOut) {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 return new ReadResult(failureAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
664 }
a61af66fc99e Initial load
duke
parents:
diff changeset
665 return new ReadResult(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
668 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 public void writeBytesToProcess(long address, long numBytes, byte[] data)
a61af66fc99e Initial load
duke
parents:
diff changeset
673 throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
675 throw new DebuggerException("Unimplemented");
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 /** This provides DbxDebuggerRemoteIntfImpl access to readBytesFromProcess */
a61af66fc99e Initial load
duke
parents:
diff changeset
679 ReadResult readBytesFromProcessInternal(long address, long numBytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
680 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return readBytesFromProcess(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 /** Convenience routine */
a61af66fc99e Initial load
duke
parents:
diff changeset
685 private void printlnToOutput(String s) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 out.println(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 if (out.checkError()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 throw new IOException("Error occurred while writing to debug server");
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691
a61af66fc99e Initial load
duke
parents:
diff changeset
692 private void clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 dbxProcess = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 dbxOstr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
695 out = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 in = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
697 importModuleSocket = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699
a61af66fc99e Initial load
duke
parents:
diff changeset
700 /** Connects to the dbx import module, setting up out and in
a61af66fc99e Initial load
duke
parents:
diff changeset
701 streams. Factored out to allow access to the dbx console. */
a61af66fc99e Initial load
duke
parents:
diff changeset
702 private void connectToImportModule() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // Try for 20 seconds to connect to dbx import module; time out
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // with failure if didn't succeed
a61af66fc99e Initial load
duke
parents:
diff changeset
705 importModuleSocket = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
706 long endTime = System.currentTimeMillis() + LONG_TIMEOUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
707
a61af66fc99e Initial load
duke
parents:
diff changeset
708 while ((importModuleSocket == null) && (System.currentTimeMillis() < endTime)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 importModuleSocket = new Socket(InetAddress.getLocalHost(), PORT);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 importModuleSocket.setTcpNoDelay(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 // Swallow IO exceptions while attempting connection
a61af66fc99e Initial load
duke
parents:
diff changeset
715 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
716 // Don't swamp the CPU
a61af66fc99e Initial load
duke
parents:
diff changeset
717 Thread.sleep(1000);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 }
a61af66fc99e Initial load
duke
parents:
diff changeset
719 catch (InterruptedException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 if (importModuleSocket == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // Failed to connect because of timeout
a61af66fc99e Initial load
duke
parents:
diff changeset
726 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
727 throw new DebuggerException("Timed out while attempting to connect to remote dbx process");
a61af66fc99e Initial load
duke
parents:
diff changeset
728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(importModuleSocket.getOutputStream(), "US-ASCII")), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
731 in = new InputLexer(new BufferedInputStream(importModuleSocket.getInputStream()));
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }