annotate agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java @ 6848:8e47bac5643a

7054512: Compress class pointers after perm gen removal Summary: support of compress class pointers in the compilers. Reviewed-by: kvn, twisti
author roland
date Tue, 09 Oct 2012 10:11:38 +0200
parents c18cbe5936b8
children f6a055fcf47d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
2 * Copyright (c) 2002, 2008, 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.linux;
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.x86.*;
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.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import java.lang.reflect.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** <P> An implementation of the JVMDebugger interface. The basic debug
a61af66fc99e Initial load
duke
parents:
diff changeset
37 facilities are implemented through ptrace interface in the JNI code
a61af66fc99e Initial load
duke
parents:
diff changeset
38 (libsaproc.so). Library maps and symbol table management are done in
a61af66fc99e Initial load
duke
parents:
diff changeset
39 JNI. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 <P> <B>NOTE</B> that since we have the notion of fetching "Java
a61af66fc99e Initial load
duke
parents:
diff changeset
42 primitive types" from the remote process (which might have
a61af66fc99e Initial load
duke
parents:
diff changeset
43 different sizes than we expect) we have a bootstrapping
a61af66fc99e Initial load
duke
parents:
diff changeset
44 problem. We need to know the sizes of these types before we can
a61af66fc99e Initial load
duke
parents:
diff changeset
45 fetch them. The current implementation solves this problem by
a61af66fc99e Initial load
duke
parents:
diff changeset
46 requiring that it be configured with these type sizes before they
a61af66fc99e Initial load
duke
parents:
diff changeset
47 can be fetched. The readJ(Type) routines here will throw a
a61af66fc99e Initial load
duke
parents:
diff changeset
48 RuntimeException if they are called before the debugger is
a61af66fc99e Initial load
duke
parents:
diff changeset
49 configured with the Java primitive type sizes. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public class LinuxDebuggerLocal extends DebuggerBase implements LinuxDebugger {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private boolean useGCC32ABI;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private boolean attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private long p_ps_prochandle; // native debugger handle
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private boolean isCore;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private LinuxCDebugger cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // threadList and loadObjectList are filled by attach0 method
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private List threadList;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private List loadObjectList;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // called by native method lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private ClosestSymbol createClosestSymbol(String name, long offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return new ClosestSymbol(name, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // called by native method attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private LoadObject createLoadObject(String fileName, long textsize,
a61af66fc99e Initial load
duke
parents:
diff changeset
71 long base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 File f = new File(fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Address baseAddr = newAddress(base);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return new SharedObject(this, fileName, f.length(), baseAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // native methods
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 private native static void init0()
a61af66fc99e Initial load
duke
parents:
diff changeset
80 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private native void attach0(int pid)
a61af66fc99e Initial load
duke
parents:
diff changeset
82 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 private native void attach0(String execName, String coreName)
a61af66fc99e Initial load
duke
parents:
diff changeset
84 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 private native void detach0()
a61af66fc99e Initial load
duke
parents:
diff changeset
86 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private native long lookupByName0(String objectName, String symbol)
a61af66fc99e Initial load
duke
parents:
diff changeset
88 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 private native ClosestSymbol lookupByAddress0(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
90 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private native long[] getThreadIntegerRegisterSet0(int lwp_id)
a61af66fc99e Initial load
duke
parents:
diff changeset
92 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private native byte[] readBytesFromProcess0(long address, long numBytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
94 throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public native static int getAddressSize() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Note on Linux threads are really processes. When target process is
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // attached by a serviceability agent thread, only that thread can do
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // ptrace operations on the target. This is because from kernel's point
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // view, other threads are just separate processes and they are not
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // attached to the target. When they attempt to make ptrace calls,
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // an ESRCH error will be returned as kernel believes target is not
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // being traced by the caller.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // To work around the problem, we use a worker thread here to handle
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // all JNI functions that are making ptrace calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 interface WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public void doit(LinuxDebuggerLocal debugger) throws DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 class LinuxDebuggerLocalWorkerThread extends Thread {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 LinuxDebuggerLocal debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 WorkerThreadTask task;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 DebuggerException lastException;
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public LinuxDebuggerLocalWorkerThread(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 this.debugger = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 setDaemon(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 synchronized (workerThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 for (;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (task != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 lastException = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 task.doit(debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 } catch (DebuggerException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 lastException = exp;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 task = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 workerThread.notifyAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 workerThread.wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 } catch (InterruptedException x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public WorkerThreadTask execute(WorkerThreadTask task) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 synchronized (workerThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 this.task = task;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 workerThread.notifyAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 while (this.task != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 workerThread.wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } catch (InterruptedException x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (lastException != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 throw new DebuggerException(lastException);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return task;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private LinuxDebuggerLocalWorkerThread workerThread = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Implementation of Debugger interface
a61af66fc99e Initial load
duke
parents:
diff changeset
164 //
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 /** <P> machDesc may not be null. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 <P> useCache should be set to true if debugging is being done
a61af66fc99e Initial load
duke
parents:
diff changeset
169 locally, and to false if the debugger is being created for the
a61af66fc99e Initial load
duke
parents:
diff changeset
170 purpose of supporting remote debugging. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
171 public LinuxDebuggerLocal(MachineDescription machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
172 boolean useCache) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 utils = new DebuggerUtilities(machDesc.getAddressSize(),
a61af66fc99e Initial load
duke
parents:
diff changeset
175 machDesc.isBigEndian()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 public void checkAlignment(long address, long alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Need to override default checkAlignment because we need to
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // relax alignment constraints on Linux/x86
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if ( (address % alignment != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
180 &&(alignment != 8 || address % 4 != 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 throw new UnalignedAddressException(
a61af66fc99e Initial load
duke
parents:
diff changeset
182 "Trying to read at address: "
a61af66fc99e Initial load
duke
parents:
diff changeset
183 + addressValueToString(address)
a61af66fc99e Initial load
duke
parents:
diff changeset
184 + " with alignment: " + alignment,
a61af66fc99e Initial load
duke
parents:
diff changeset
185 address);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 };
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // FIXME: re-test necessity of cache on Linux, where data
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // fetching is faster
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Cache portion of the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // Fetching data over the socket connection to dbx is slow.
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Might be faster if we were using a binary protocol to talk to
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // dbx, but would have to test. For now, this cache works best
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // if it covers the entire heap of the remote process. FIXME: at
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // least should make this tunable from the outside, i.e., via
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // the UI. This is a cache of 4096 4K pages, or 16 MB. The page
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // size must be adjusted to be the hardware's page size.
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // (FIXME: should pick this up from the debugger.)
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (getCPU().equals("ia64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 initCache(16384, parseCacheNumPagesProperty(1024));
a61af66fc99e Initial load
duke
parents:
diff changeset
204 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 initCache(4096, parseCacheNumPagesProperty(4096));
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 workerThread = new LinuxDebuggerLocalWorkerThread(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 workerThread.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public boolean hasProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
219 public List getProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 throw new DebuggerException("getProcessList not implemented yet");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 private void checkAttached() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 if (attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 throw new DebuggerException("attached to a core dump already");
a61af66fc99e Initial load
duke
parents:
diff changeset
227 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 throw new DebuggerException("attached to a process already");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 private void requireAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (! attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 throw new RuntimeException("not attached to a process or a core!");
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 /* called from attach methods */
a61af66fc99e Initial load
duke
parents:
diff changeset
240 private void findABIVersion() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (lookupByName0("libjvm.so", "__vt_10JavaThread") != 0 ||
a61af66fc99e Initial load
duke
parents:
diff changeset
242 lookupByName0("libjvm_g.so", "__vt_10JavaThread") != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // old C++ ABI
a61af66fc99e Initial load
duke
parents:
diff changeset
244 useGCC32ABI = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // new C++ ABI
a61af66fc99e Initial load
duke
parents:
diff changeset
247 useGCC32ABI = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
252 public synchronized void attach(int processID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 checkAttached();
a61af66fc99e Initial load
duke
parents:
diff changeset
254 threadList = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 loadObjectList = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
256 class AttachTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 debugger.attach0(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 debugger.attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 debugger.isCore = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 findABIVersion();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 AttachTask task = new AttachTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 task.pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
272 public synchronized void attach(String execName, String coreName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 checkAttached();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 threadList = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 loadObjectList = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 attach0(execName, coreName);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 isCore = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 findABIVersion();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
283 public synchronized boolean detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 threadList = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 loadObjectList = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 detach0();
a61af66fc99e Initial load
duke
parents:
diff changeset
293 attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 class DetachTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 boolean result = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 debugger.detach0();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 debugger.attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 result = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 DetachTask task = new DetachTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return task.result;
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 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
313 public Address parseAddress(String addressString)
a61af66fc99e Initial load
duke
parents:
diff changeset
314 throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 long addr = utils.scanAddress(addressString);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (addr == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return new LinuxAddress(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
323 public String getOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
328 public String getCPU() {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 public boolean hasConsole() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 public String consoleExecuteCommand(String cmd) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 throw new DebuggerException("No debugger console available on Linux");
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 public String getConsolePrompt() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 /* called from lookup */
a61af66fc99e Initial load
duke
parents:
diff changeset
345 private long handleGCC32ABI(long addr, String symbol) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 if (useGCC32ABI && symbol.startsWith("_ZTV")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 return addr + (2 * machDesc.getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
348 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
354 public synchronized Address lookup(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 long addr = lookupByName0(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return (addr == 0)? null : new LinuxAddress(this, handleGCC32ABI(addr, symbol));
a61af66fc99e Initial load
duke
parents:
diff changeset
363 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 class LookupByNameTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 String objectName, symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 Address result;
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 long addr = debugger.lookupByName0(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 result = (addr == 0 ? null : new LinuxAddress(debugger, handleGCC32ABI(addr, symbol)));
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 LookupByNameTask task = new LookupByNameTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
375 task.objectName = objectName;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 task.symbol = symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 return task.result;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
383 public synchronized OopHandle lookupOop(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 Address addr = lookup(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 return addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 /** From the Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
392 public MachineDescription getMachineDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 return machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // Implementation of ThreadAccess interface
a61af66fc99e Initial load
duke
parents:
diff changeset
398 //
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 /** From the ThreadAccess interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
401 public ThreadProxy getThreadForIdentifierAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 return new LinuxThread(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 /** From the ThreadAccess interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
406 public ThreadProxy getThreadForThreadId(long id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 return new LinuxThread(this, id);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // Internal routines (for implementation of LinuxAddress).
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // These must not be called until the MachineDescription has been set up.
a61af66fc99e Initial load
duke
parents:
diff changeset
413 //
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 /** From the LinuxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
416 public String addressValueToString(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 return utils.addressValueToString(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 /** From the LinuxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
421 public LinuxAddress readAddress(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
422 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return (value == 0 ? null : new LinuxAddress(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
426 public LinuxAddress readCompOopAddress(long address)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
427 throws UnmappedAddressException, UnalignedAddressException {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
428 long value = readCompOopAddressValue(address);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
429 return (value == 0 ? null : new LinuxAddress(this, value));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
430 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
431
6848
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
432 public LinuxAddress readCompKlassAddress(long address)
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
433 throws UnmappedAddressException, UnalignedAddressException {
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
434 long value = readCompKlassAddressValue(address);
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
435 return (value == 0 ? null : new LinuxAddress(this, value));
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
436 }
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 1552
diff changeset
437
0
a61af66fc99e Initial load
duke
parents:
diff changeset
438 /** From the LinuxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
439 public LinuxOopHandle readOopHandle(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
440 throws UnmappedAddressException, UnalignedAddressException,
a61af66fc99e Initial load
duke
parents:
diff changeset
441 NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 return (value == 0 ? null : new LinuxOopHandle(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
445 public LinuxOopHandle readCompOopHandle(long address)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
446 throws UnmappedAddressException, UnalignedAddressException,
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
447 NotInHeapException {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
448 long value = readCompOopAddressValue(address);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
449 return (value == 0 ? null : new LinuxOopHandle(this, value));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
450 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // Thread context access
a61af66fc99e Initial load
duke
parents:
diff changeset
454 //
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 public synchronized long[] getThreadIntegerRegisterSet(int lwp_id)
a61af66fc99e Initial load
duke
parents:
diff changeset
457 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
458 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 return getThreadIntegerRegisterSet0(lwp_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 class GetThreadIntegerRegisterSetTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 int lwp_id;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 long[] result;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 result = debugger.getThreadIntegerRegisterSet0(lwp_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 GetThreadIntegerRegisterSetTask task = new GetThreadIntegerRegisterSetTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
471 task.lwp_id = lwp_id;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 return task.result;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 /** Need to override this to relax alignment checks on x86. */
a61af66fc99e Initial load
duke
parents:
diff changeset
478 public long readCInteger(long address, long numBytes, boolean isUnsigned)
a61af66fc99e Initial load
duke
parents:
diff changeset
479 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // Only slightly relaxed semantics -- this is a hack, but is
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // necessary on x86 where it seems the compiler is
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // putting some global 64-bit data on 32-bit boundaries
a61af66fc99e Initial load
duke
parents:
diff changeset
483 if (numBytes == 8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 utils.checkAlignment(address, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
485 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 utils.checkAlignment(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488 byte[] data = readBytes(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 return utils.dataToCInteger(data, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // Overridden from DebuggerBase because we need to relax alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // constraints on x86
a61af66fc99e Initial load
duke
parents:
diff changeset
494 public long readJLong(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
495 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 utils.checkAlignment(address, jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
497 byte[] data = readBytes(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return utils.dataToJLong(data, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // Address access. Can not be package private, but should only be
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // accessed by the architecture-specific subpackages.
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 /** From the LinuxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
506 public long getAddressValue(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (addr == null) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 return ((LinuxAddress) addr).getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 /** From the LinuxDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
512 public Address newAddress(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 if (value == 0) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
514 return new LinuxAddress(this, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 /** From the LinuxCDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
518 public List/*<ThreadProxy>*/ getThreadList() {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
520 return threadList;
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 /** From the LinuxCDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
524 public List/*<LoadObject>*/ getLoadObjectList() {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
526 return loadObjectList;
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 /** From the LinuxCDebugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
530 public synchronized ClosestSymbol lookup(long addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
531 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 return lookupByAddress0(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 class LookupByAddressTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 long addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
537 ClosestSymbol result;
a61af66fc99e Initial load
duke
parents:
diff changeset
538
a61af66fc99e Initial load
duke
parents:
diff changeset
539 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 result = debugger.lookupByAddress0(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 LookupByAddressTask task = new LookupByAddressTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
545 task.addr = addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
546 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 return task.result;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 public CDebugger getCDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 if (cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 String cpu = getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
554 if (cpu.equals("ia64") ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // IA-64 is not supported because of stack-walking issues
a61af66fc99e Initial load
duke
parents:
diff changeset
556 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
557 }
a61af66fc99e Initial load
duke
parents:
diff changeset
558 cdbg = new LinuxCDebugger(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 }
a61af66fc99e Initial load
duke
parents:
diff changeset
560 return cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 /** This reads bytes from the remote process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
564 public synchronized ReadResult readBytesFromProcess(long address,
a61af66fc99e Initial load
duke
parents:
diff changeset
565 long numBytes) throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 requireAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
567 if (isCore) {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 byte[] res = readBytesFromProcess0(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return (res != null)? new ReadResult(res) : new ReadResult(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 class ReadBytesFromProcessTask implements WorkerThreadTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 long address, numBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
573 ReadResult result;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 public void doit(LinuxDebuggerLocal debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 byte[] res = debugger.readBytesFromProcess0(address, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
576 if (res != null)
a61af66fc99e Initial load
duke
parents:
diff changeset
577 result = new ReadResult(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
578 else
a61af66fc99e Initial load
duke
parents:
diff changeset
579 result = new ReadResult(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
581 }
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 ReadBytesFromProcessTask task = new ReadBytesFromProcessTask();
a61af66fc99e Initial load
duke
parents:
diff changeset
584 task.address = address;
a61af66fc99e Initial load
duke
parents:
diff changeset
585 task.numBytes = numBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 workerThread.execute(task);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 return task.result;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 public void writeBytesToProcess(long address, long numBytes, byte[] data)
a61af66fc99e Initial load
duke
parents:
diff changeset
592 throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
594 throw new DebuggerException("Unimplemented");
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 System.loadLibrary("saproc");
a61af66fc99e Initial load
duke
parents:
diff changeset
599 init0();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }