annotate agent/src/share/classes/sun/jvm/hotspot/debugger/proc/ProcDebuggerLocal.java @ 17736:58fc1b1523dc

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