annotate agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java @ 17524:89152779163c

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