annotate agent/src/share/classes/sun/jvm/hotspot/debugger/proc/ProcDebuggerLocal.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 2002-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.proc;
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.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.proc.amd64.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.proc.sparc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.proc.x86.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.debugger.amd64.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.debugger.sparc.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.debugger.x86.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 /** <P> An implementation of the JVMDebugger interface which sits on
a61af66fc99e Initial load
duke
parents:
diff changeset
41 * top of proc and relies on the SA's proc import module for
a61af66fc99e Initial load
duke
parents:
diff changeset
42 * communication with the debugger. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
43 *
a61af66fc99e Initial load
duke
parents:
diff changeset
44 * <P> <B>NOTE</B> that since we have the notion of fetching "Java
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * primitive types" from the remote process (which might have
a61af66fc99e Initial load
duke
parents:
diff changeset
46 * different sizes than we expect) we have a bootstrapping
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * problem. We need to know the sizes of these types before we can
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * fetch them. The current implementation solves this problem by
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * requiring that it be configured with these type sizes before they
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * can be fetched. The readJ(Type) routines here will throw a
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * RuntimeException if they are called before the debugger is
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * configured with the Java primitive type sizes. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
53 */
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public class ProcDebuggerLocal extends DebuggerBase implements ProcDebugger {
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 protected static final int cacheSize = 16 * 1024 * 1024; // 16 MB
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 //------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Implementation of Debugger interface
a61af66fc99e Initial load
duke
parents:
diff changeset
62 //
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 /** <P> machDesc may be null if it couldn't be determined yet; i.e.,
a61af66fc99e Initial load
duke
parents:
diff changeset
65 * if we're on SPARC, we need to ask the remote process whether
a61af66fc99e Initial load
duke
parents:
diff changeset
66 * we're in 32- or 64-bit mode. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
67 *
a61af66fc99e Initial load
duke
parents:
diff changeset
68 * <P> useCache should be set to true if debugging is being done
a61af66fc99e Initial load
duke
parents:
diff changeset
69 * locally, and to false if the debugger is being created for the
a61af66fc99e Initial load
duke
parents:
diff changeset
70 * purpose of supporting remote debugging. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public ProcDebuggerLocal(MachineDescription machDesc, boolean useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 int cacheNumPages;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int cachePageSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 final String cpu = PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (cpu.equals("sparc")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 threadFactory = new ProcSPARCThreadFactory(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 pcRegIndex = SPARCThreadContext.R_PC;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 fpRegIndex = SPARCThreadContext.R_I6;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 } else if (cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 threadFactory = new ProcX86ThreadFactory(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 pcRegIndex = X86ThreadContext.EIP;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 fpRegIndex = X86ThreadContext.EBP;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 unalignedAccessesOkay = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } else if (cpu.equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 threadFactory = new ProcAMD64ThreadFactory(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 pcRegIndex = AMD64ThreadContext.RIP;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 fpRegIndex = AMD64ThreadContext.RBP;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 throw new RuntimeException("Thread access for CPU architecture " + PlatformInfo.getCPU() + " not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Cache portion of the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // For now, this cache works best if it covers the entire
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // heap of the remote process. FIXME: at least should make this
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // tunable from the outside, i.e., via the UI. This is a 16 MB
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // cache divided on SPARC into 2048 8K pages and on x86 into
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // 4096 4K pages; the page size must be adjusted to be the OS's
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // page size.
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 cachePageSize = getPageSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 cacheNumPages = parseCacheNumPagesProperty(cacheSize / cachePageSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 initCache(cachePageSize, cacheNumPages);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 resetNativePointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 clearCacheFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 /** FIXME: implement this with a Runtime.exec() of ps followed by
a61af66fc99e Initial load
duke
parents:
diff changeset
112 * parsing of its output */
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public boolean hasProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public List getProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 throw new DebuggerException("Not yet supported");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public synchronized void attach(int processID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 checkAttached();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 isCore = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 attach0(new Integer(processID).toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
127 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public synchronized void attach
a61af66fc99e Initial load
duke
parents:
diff changeset
133 (String executableName, String coreFileName) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 checkAttached();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 isCore = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 topFrameCache = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 attach0(executableName, coreFileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public synchronized boolean detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (! attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (p_ps_prochandle == 0L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 detach0();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 clearCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 resetNativePointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 clearCacheFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 suspended = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 attached = false;
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 public synchronized void suspend() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 throw new DebuggerException("Process already suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 suspend0();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 enableCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 reresolveLoadObjects();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public synchronized void resume() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 resume0();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 disableCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 suspended = false;
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 boolean isSuspended() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public Address parseAddress(String addressString) throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 long addr = utils.scanAddress(addressString);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return new ProcAddress(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
202 public String getOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
207 public String getCPU() {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public boolean hasConsole() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 public String consoleExecuteCommand(String cmd) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 throw new DebuggerException("Can't execute console commands");
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 public String getConsolePrompt() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return "";
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public CDebugger getCDebugger() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 if (cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 cdbg = new ProcCDebugger(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
231 public synchronized Address lookup(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 long addr = lookupByName0(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return new ProcAddress(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public synchronized OopHandle lookupOop(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 Address addr = lookup(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 return addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
250 public MachineDescription getMachineDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 /** Internal routine supporting lazy setting of MachineDescription,
a61af66fc99e Initial load
duke
parents:
diff changeset
255 * since on SPARC we will need to query the remote process to ask
a61af66fc99e Initial load
duke
parents:
diff changeset
256 * it what its data model is (32- or 64-bit).
a61af66fc99e Initial load
duke
parents:
diff changeset
257 */
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 public void setMachineDescription(MachineDescription machDesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 setBigEndian(machDesc.isBigEndian());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian());
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public synchronized int getRemoteProcessAddressSize()
a61af66fc99e Initial load
duke
parents:
diff changeset
266 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return getRemoteProcessAddressSize0();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // Implementation of ThreadAccess interface
a61af66fc99e Initial load
duke
parents:
diff changeset
273 //
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 /** From the ThreadAccess interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public ThreadProxy getThreadForIdentifierAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return threadFactory.createThreadWrapper(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 public ThreadProxy getThreadForThreadId(long id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return threadFactory.createThreadWrapper(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Overridden from DebuggerBase because we need to relax alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // constraints on x86
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 public long readJLong(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
289 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 checkJavaConfigured();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // FIXME: allow this to be configurable. Undesirable to add a
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // dependency on the runtime package here, though, since this
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // package should be strictly underneath it.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (unalignedAccessesOkay) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 utils.checkAlignment(address, jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 utils.checkAlignment(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 byte[] data = readBytes(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return utils.dataToJLong(data, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Internal routines (for implementation of ProcAddress).
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // These must not be called until the MachineDescription has been set up.
a61af66fc99e Initial load
duke
parents:
diff changeset
306 //
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
309 public String addressValueToString(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return utils.addressValueToString(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 /** Need to override this to relax alignment checks on Solaris/x86. */
a61af66fc99e Initial load
duke
parents:
diff changeset
314 public long readCInteger(long address, long numBytes, boolean isUnsigned)
a61af66fc99e Initial load
duke
parents:
diff changeset
315 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 checkConfigured();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (!unalignedAccessesOkay) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 utils.checkAlignment(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // Only slightly relaxed semantics -- this is a hack, but is
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // necessary on Solaris/x86 where it seems the compiler is
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // putting some global 64-bit data on 32-bit boundaries
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (numBytes == 8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 utils.checkAlignment(address, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 utils.checkAlignment(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 byte[] data = readBytes(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return utils.dataToCInteger(data, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
334 public ProcAddress readAddress(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
335 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return (value == 0 ? null : new ProcAddress(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
341 public ProcOopHandle readOopHandle(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
342 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return (value == 0 ? null : new ProcOopHandle(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 public void writeBytesToProcess(long address, long numBytes, byte[] data)
a61af66fc99e Initial load
duke
parents:
diff changeset
348 throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 throw new DebuggerException("Attached to a core file!");
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 writeBytesToProcess0(address, numBytes, data);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
356 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
358 byte[] res = readBytesFromProcess0(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 if(res != null)
a61af66fc99e Initial load
duke
parents:
diff changeset
360 return new ReadResult(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 else
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return new ReadResult(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 protected int getPageSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 int pagesize = getPageSize0();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (pagesize == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // return the hard coded default value.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 pagesize = (PlatformInfo.getCPU().equals("x86"))? 4096 : 8192;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return pagesize;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // Thread context access. Can not be package private, but should
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // only be accessed by the architecture-specific subpackages.
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 /** From the ProcDebugger interface. May have to redefine this later. */
a61af66fc99e Initial load
duke
parents:
diff changeset
379 public synchronized long[] getThreadIntegerRegisterSet(int tid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return getThreadIntegerRegisterSet0(tid);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // Address access. Can not be package private, but should only be
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // accessed by the architecture-specific subpackages.
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
389 public long getAddressValue(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (addr == null) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 return ((ProcAddress) addr).getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
395 public Address newAddress(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (value == 0) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
397 return new ProcAddress(this, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
401 public synchronized List getThreadList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 List res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 if (isCore && (threadListCache != null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 res = threadListCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 res = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
408 fillThreadList0(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 threadListCache = res;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
417 public synchronized List getLoadObjectList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 if (loadObjectCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 updateLoadObjectCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return loadObjectCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
430 public synchronized CFrame topFrameForThread(ThreadProxy thread)
a61af66fc99e Initial load
duke
parents:
diff changeset
431 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
433 CFrame res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 if (isCore && ((res = (CFrame) topFrameCache.get(thread)) != null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 ThreadContext context = thread.getContext();
a61af66fc99e Initial load
duke
parents:
diff changeset
438 int numRegs = context.getNumRegisters();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 long[] regs = new long[numRegs];
a61af66fc99e Initial load
duke
parents:
diff changeset
440 for (int i = 0; i < numRegs; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 regs[i] = context.getRegister(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443 res = fillCFrameList0(regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 topFrameCache.put(thread, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
452 public synchronized ClosestSymbol lookup(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 return lookupByAddress0(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456
a61af66fc99e Initial load
duke
parents:
diff changeset
457 /** From the ProcDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
458 public String demangle(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return demangle0(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 //------------- Internals only below this point --------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
463 //
a61af66fc99e Initial load
duke
parents:
diff changeset
464 //
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 private void updateLoadObjectCache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 List res = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 nameToDsoMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 fillLoadObjectList0(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 loadObjectCache = sortLoadObjects(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // sort load objects by base address
a61af66fc99e Initial load
duke
parents:
diff changeset
474 private static List sortLoadObjects(List in) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // sort the list by base address
a61af66fc99e Initial load
duke
parents:
diff changeset
476 Object[] arr = in.toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
477 Arrays.sort(arr, loadObjectComparator);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 return Arrays.asList(arr);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 private long lookupByName(String objectName, String symbolName)
a61af66fc99e Initial load
duke
parents:
diff changeset
482 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // NOTE: this assumes that process is suspended (which is probably
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // necessary assumption given that DSOs can be loaded/unloaded as
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // process runs). Should update documentation.
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (nameToDsoMap == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 getLoadObjectList();
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489 SharedObject dso = (SharedObject) nameToDsoMap.get(objectName);
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // The DSO can be null because we use this to search through known
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // DSOs in HotSpotTypeDataBase (for example)
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (dso != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 ProcAddress addr = (ProcAddress) dso.lookupSymbol(symbolName);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 if (addr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 return addr.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 private SharedObject findDSOByName(String fullPathName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (loadObjectCache == null)
a61af66fc99e Initial load
duke
parents:
diff changeset
503 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 for (Iterator iter = loadObjectCache.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 SharedObject dso = (SharedObject) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
506 if (dso.getName().equals(fullPathName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 return dso;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 private void reresolveLoadObjects() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 if (loadObjectCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517 updateLoadObjectCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 private void checkAttached() {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 if (attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 throw new DebuggerException("already attached to a core file!");
a61af66fc99e Initial load
duke
parents:
diff changeset
525 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 throw new DebuggerException("already attached to a process!");
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 private void requireAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (! attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 throw new RuntimeException("not attached to a process or core file!");
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536
a61af66fc99e Initial load
duke
parents:
diff changeset
537 private void clearCacheFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
538 loadObjectCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 nameToDsoMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 threadListCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 topFrameCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 private void resetNativePointers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 p_ps_prochandle = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // reset thread_db pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
548 libthread_db_handle = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 p_td_thragent_t = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 p_td_init = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
551 p_td_ta_new = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 p_td_ta_delete = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
553 p_td_ta_thr_iter = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 p_td_thr_get_info = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
555 p_td_ta_map_id2thr = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
556 p_td_thr_getgregs = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // part of class sharing workaround
a61af66fc99e Initial load
duke
parents:
diff changeset
559 classes_jsa_fd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
560 p_file_map_header = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 // native methods and native helpers
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // attach, detach
a61af66fc99e Initial load
duke
parents:
diff changeset
566 private native void attach0(String pid) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 private native void attach0(String executableFile, String coreFileName) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
568 private native void detach0() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // address size, page size
a61af66fc99e Initial load
duke
parents:
diff changeset
571 private native int getRemoteProcessAddressSize0() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 private native int getPageSize0() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // threads, stacks
a61af66fc99e Initial load
duke
parents:
diff changeset
575 private native long[] getThreadIntegerRegisterSet0(long tid) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
576 private native void fillThreadList0(List l) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // fills stack frame list given reg set of the top frame and top frame
a61af66fc99e Initial load
duke
parents:
diff changeset
579 private native ProcCFrame fillCFrameList0(long[] regs) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // helper called by fillCFrameList0
a61af66fc99e Initial load
duke
parents:
diff changeset
582 private ProcCFrame createSenderFrame(ProcCFrame f, long pc, long fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 ProcCFrame sender = new ProcCFrame(this, newAddress(pc), newAddress(fp));
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (f != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 f.setSender(sender);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 return sender;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // shared objects
a61af66fc99e Initial load
duke
parents:
diff changeset
591 private native void fillLoadObjectList0(List l) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // helper called by fillLoadObjectList0
a61af66fc99e Initial load
duke
parents:
diff changeset
594 private LoadObject createLoadObject(String fileName, long textsize, long base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 File f = new File(fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
596 Address baseAddr = newAddress(base);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 SharedObject res = findDSOByName(fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (res != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 // already in cache. just change the base, if needed
a61af66fc99e Initial load
duke
parents:
diff changeset
600 Address oldBase = res.getBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
601 if (! baseAddr.equals(oldBase)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 res.setBase(baseAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 }
a61af66fc99e Initial load
duke
parents:
diff changeset
604 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // new shared object.
a61af66fc99e Initial load
duke
parents:
diff changeset
606 res = new SharedObject(this, fileName, f.length(), baseAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608 nameToDsoMap.put(f.getName(), res);
a61af66fc99e Initial load
duke
parents:
diff changeset
609 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // symbol-to-pc
a61af66fc99e Initial load
duke
parents:
diff changeset
613 private native long lookupByName0(String objectName, String symbolName) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 private native ClosestSymbol lookupByAddress0(long address) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // helper called by lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
617 private ClosestSymbol createClosestSymbol(String name, long offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
618 return new ClosestSymbol(name, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // process read/write
a61af66fc99e Initial load
duke
parents:
diff changeset
622 private native byte[] readBytesFromProcess0(long address, long numBytes) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
623 private native void writeBytesToProcess0(long address, long numBytes, byte[] data) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // process control
a61af66fc99e Initial load
duke
parents:
diff changeset
626 private native void suspend0() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
627 private native void resume0() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // demangle a C++ name
a61af66fc99e Initial load
duke
parents:
diff changeset
630 private native String demangle0(String name);
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 // init JNI ids to fields, methods
a61af66fc99e Initial load
duke
parents:
diff changeset
633 private native static void initIDs() throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 private static LoadObjectComparator loadObjectComparator;
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 System.loadLibrary("saproc");
a61af66fc99e Initial load
duke
parents:
diff changeset
638 initIDs();
a61af66fc99e Initial load
duke
parents:
diff changeset
639 loadObjectComparator = new LoadObjectComparator();
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 private boolean unalignedAccessesOkay;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 private ProcThreadFactory threadFactory;
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // indices of PC and FP registers in gregset
a61af66fc99e Initial load
duke
parents:
diff changeset
646 private int pcRegIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 private int fpRegIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Symbol lookup support
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // This is a map of library names to DSOs
a61af66fc99e Initial load
duke
parents:
diff changeset
651 private Map nameToDsoMap; // Map<String, SharedObject>
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // C/C++ debugging support
a61af66fc99e Initial load
duke
parents:
diff changeset
654 private List/*<LoadObject>*/ loadObjects;
a61af66fc99e Initial load
duke
parents:
diff changeset
655 private CDebugger cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
656
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // ProcessControl support
a61af66fc99e Initial load
duke
parents:
diff changeset
658 private boolean suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
659
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // libproc handle
a61af66fc99e Initial load
duke
parents:
diff changeset
661 private long p_ps_prochandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // libthread.so's dlopen handle, thread agent
a61af66fc99e Initial load
duke
parents:
diff changeset
664 // and function pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
665 private long libthread_db_handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 private long p_td_thragent_t;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 private long p_td_init;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 private long p_td_ta_new;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 private long p_td_ta_delete;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 private long p_td_ta_thr_iter;
a61af66fc99e Initial load
duke
parents:
diff changeset
671 private long p_td_thr_get_info;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 private long p_td_ta_map_id2thr;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 private long p_td_thr_getgregs;
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // part of class sharing workaround
a61af66fc99e Initial load
duke
parents:
diff changeset
676 private int classes_jsa_fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
677 private long p_file_map_header;
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 private boolean attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 private boolean isCore;
a61af66fc99e Initial load
duke
parents:
diff changeset
681
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // for core files, we cache load object list, thread list, top frames etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
683 // for processes we cache load object list and sync. it during suspend.
a61af66fc99e Initial load
duke
parents:
diff changeset
684 private List threadListCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
685 private List loadObjectCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 private Map topFrameCache; // Map<ThreadProxy, CFrame>
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }