annotate agent/src/share/classes/sun/jvm/hotspot/debugger/proc/ProcDebuggerLocal.java @ 196:d1605aabd0a1 jdk7-b30

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