annotate agent/src/share/classes/sun/jvm/hotspot/debugger/win32/Win32DebuggerLocal.java @ 1385:bc32f286fae0

6945219: minor SA fixes Reviewed-by: twisti
author never
date Tue, 20 Apr 2010 13:26:33 -0700
parents d1605aabd0a1
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 113
diff changeset
2 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.debugger.win32;
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.win32.coff.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.cdbg.basic.BasicDebugEvent;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.utilities.memo.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 /** <P> An implementation of the JVMDebugger interface which talks to
a61af66fc99e Initial load
duke
parents:
diff changeset
39 the Free Windows Debug Server (FwDbgSrv) over a socket to
a61af66fc99e Initial load
duke
parents:
diff changeset
40 implement attach/detach and read from process memory. All DLL and
a61af66fc99e Initial load
duke
parents:
diff changeset
41 symbol table management is done in Java. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 <P> <B>NOTE</B> that since we have the notion of fetching "Java
a61af66fc99e Initial load
duke
parents:
diff changeset
44 primitive types" from the remote process (which might have
a61af66fc99e Initial load
duke
parents:
diff changeset
45 different sizes than we expect) we have a bootstrapping
a61af66fc99e Initial load
duke
parents:
diff changeset
46 problem. We need to know the sizes of these types before we can
a61af66fc99e Initial load
duke
parents:
diff changeset
47 fetch them. The current implementation solves this problem by
a61af66fc99e Initial load
duke
parents:
diff changeset
48 requiring that it be configured with these type sizes before they
a61af66fc99e Initial load
duke
parents:
diff changeset
49 can be fetched. The readJ(Type) routines here will throw a
a61af66fc99e Initial load
duke
parents:
diff changeset
50 RuntimeException if they are called before the debugger is
a61af66fc99e Initial load
duke
parents:
diff changeset
51 configured with the Java primitive type sizes. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public class Win32DebuggerLocal extends DebuggerBase implements Win32Debugger {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private Socket debuggerSocket;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private boolean attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // FIXME: update when core files supported
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private long pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // Communication with debug server
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private PrintWriter out;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private DataOutputStream rawOut;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private InputLexer in;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private static final int PORT = 27000;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private PageCache cache;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private static final long SHORT_TIMEOUT = 2000;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private static final long LONG_TIMEOUT = 20000;
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Symbol lookup support
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // This is a map of library names to DLLs
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private Map nameToDllMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // C/C++ debugging support
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private List/*<LoadObject>*/ loadObjects;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private CDebugger cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // ProcessControl support
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private boolean suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Maps Long objects (addresses) to Byte objects (original instructions)
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // (Longs used instead of Addresses to properly represent breakpoints at 0x0 if needed)
a61af66fc99e Initial load
duke
parents:
diff changeset
79 private Map breakpoints;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Current debug event, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private DebugEvent curDebugEvent;
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Implementation of Debugger interface
a61af66fc99e Initial load
duke
parents:
diff changeset
85 //
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 /** <P> machDesc may not be null. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 <P> useCache should be set to true if debugging is being done
a61af66fc99e Initial load
duke
parents:
diff changeset
90 locally, and to false if the debugger is being created for the
a61af66fc99e Initial load
duke
parents:
diff changeset
91 purpose of supporting remote debugging. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
92 public Win32DebuggerLocal(MachineDescription machDesc,
a61af66fc99e Initial load
duke
parents:
diff changeset
93 boolean useCache) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian());
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (useCache) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Cache portion of the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Fetching data over the socket connection to dbx is slow.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Might be faster if we were using a binary protocol to talk to
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // dbx, but would have to test. For now, this cache works best
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // if it covers the entire heap of the remote process. FIXME: at
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // least should make this tunable from the outside, i.e., via
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // the UI. This is a cache of 4096 4K pages, or 16 MB. The page
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // size must be adjusted to be the hardware's page size.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // (FIXME: should pick this up from the debugger.)
a61af66fc99e Initial load
duke
parents:
diff changeset
106 initCache(4096, parseCacheNumPagesProperty(4096));
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // FIXME: add instantiation of thread factory
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 connectToDebugServer();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean hasProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public List getProcessList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 List processes = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 printlnToOutput("proclist");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int num = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 for (int i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int pid = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 String name = parseString();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // NOTE: Win32 hack
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (name.equals("")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 name = "System Idle Process";
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 processes.add(new ProcessInfo(name, pid));
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return processes;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public synchronized void attach(int processID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // FIXME: update when core files supported
a61af66fc99e Initial load
duke
parents:
diff changeset
149 throw new DebuggerException("Already attached to process " + pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 printlnToOutput("attach " + processID);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 throw new DebuggerException("Error attaching to process, or no such process");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 pid = processID;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 breakpoints = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 curDebugEvent = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 nameToDllMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 loadObjects = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 throw new DebuggerException(e);
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 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public synchronized void attach(String executableName, String coreFileName) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 throw new DebuggerException("Core files not yet supported on Win32");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public synchronized boolean detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 suspended = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 breakpoints = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // Close all open DLLs
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (nameToDllMap != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 for (Iterator iter = nameToDllMap.values().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 DLL dll = (DLL) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 dll.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 nameToDllMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 loadObjects = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 cdbg = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 clearCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 printlnToOutput("detach");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return in.parseBoolean();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 /** From the Debugger interface via JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
209 public Address parseAddress(String addressString) throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return newAddress(utils.scanAddress(addressString));
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 String getOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return PlatformInfo.getOS();
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 String getCPU() {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public boolean hasConsole() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 public String consoleExecuteCommand(String cmd) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 throw new DebuggerException("No debugger console available on Win32");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 public String getConsolePrompt() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 public CDebugger getCDebugger() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 cdbg = new Win32CDebugger(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return cdbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
243 public synchronized Address lookup(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return newAddress(lookupInProcess(objectName, symbol));
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 /** From the SymbolLookup interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
251 public synchronized OopHandle lookupOop(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 Address addr = lookup(objectName, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 /** From the Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
260 public MachineDescription getMachineDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Implementation of ThreadAccess interface
a61af66fc99e Initial load
duke
parents:
diff changeset
266 //
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 /** From the ThreadAccess interface via Debugger and JVMDebugger */
a61af66fc99e Initial load
duke
parents:
diff changeset
269 public ThreadProxy getThreadForIdentifierAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return new Win32Thread(this, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public ThreadProxy getThreadForThreadId(long handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return new Win32Thread(this, handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Overridden from DebuggerBase because we need to relax alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // constraints on x86
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 public long readJLong(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
282 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 checkJavaConfigured();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // FIXME: allow this to be configurable. Undesirable to add a
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // dependency on the runtime package here, though, since this
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // package should be strictly underneath it.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // utils.checkAlignment(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
288 utils.checkAlignment(address, jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 byte[] data = readBytes(address, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 return utils.dataToJLong(data, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Internal routines (for implementation of Win32Address).
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // These must not be called until the MachineDescription has been set up.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 //
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
299 public String addressValueToString(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return utils.addressValueToString(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
304 public Win32Address readAddress(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
305 throws UnmappedAddressException, UnalignedAddressException {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return (Win32Address) newAddress(readAddressValue(address));
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
309 public Win32Address readCompOopAddress(long address)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
310 throws UnmappedAddressException, UnalignedAddressException {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
311 return (Win32Address) newAddress(readCompOopAddressValue(address));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
312 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
313
0
a61af66fc99e Initial load
duke
parents:
diff changeset
314 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
315 public Win32OopHandle readOopHandle(long address)
a61af66fc99e Initial load
duke
parents:
diff changeset
316 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 long value = readAddressValue(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 return (value == 0 ? null : new Win32OopHandle(this, value));
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
320 public Win32OopHandle readCompOopHandle(long address)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
321 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
322 long value = readCompOopAddressValue(address);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
323 return (value == 0 ? null : new Win32OopHandle(this, value));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
324 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
327 public void writeAddress(long address, Win32Address value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 writeAddressValue(address, getAddressValue(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
332 public void writeOopHandle(long address, Win32OopHandle value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 writeAddressValue(address, getAddressValue(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // Thread context access
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 synchronized long[] getThreadIntegerRegisterSet(int threadHandleValue,
a61af66fc99e Initial load
duke
parents:
diff changeset
341 boolean mustDuplicateHandle)
a61af66fc99e Initial load
duke
parents:
diff changeset
342 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 int handle = threadHandleValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 handle = (int) in.parseAddress(); // Must close to avoid leaks
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356 printlnToOutput("getcontext 0x" + Integer.toHexString(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 String failMessage = "GetThreadContext failed for thread handle 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
362 Integer.toHexString(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 failMessage = failMessage + ", duplicated from thread handle " +
a61af66fc99e Initial load
duke
parents:
diff changeset
365 Integer.toHexString(threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367 throw new DebuggerException(failMessage);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // Otherwise, parse all registers. See
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // src/os/win32/agent/README-commands.txt for the format.
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // Note the array we have to return has to match that specified by
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // X86ThreadContext.java.
a61af66fc99e Initial load
duke
parents:
diff changeset
373 int numRegs = 22;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 long[] winRegs = new long[numRegs];
a61af66fc99e Initial load
duke
parents:
diff changeset
375 for (int i = 0; i < numRegs; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 winRegs[i] = in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // Clean up after ourselves
a61af66fc99e Initial load
duke
parents:
diff changeset
380 printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // Now create the real return value
a61af66fc99e Initial load
duke
parents:
diff changeset
383 long[] retval = new long[X86ThreadContext.NPRGREG];
a61af66fc99e Initial load
duke
parents:
diff changeset
384 retval[X86ThreadContext.EAX] = winRegs[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
385 retval[X86ThreadContext.EBX] = winRegs[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
386 retval[X86ThreadContext.ECX] = winRegs[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
387 retval[X86ThreadContext.EDX] = winRegs[3];
a61af66fc99e Initial load
duke
parents:
diff changeset
388 retval[X86ThreadContext.ESI] = winRegs[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
389 retval[X86ThreadContext.EDI] = winRegs[5];
a61af66fc99e Initial load
duke
parents:
diff changeset
390 retval[X86ThreadContext.EBP] = winRegs[6];
a61af66fc99e Initial load
duke
parents:
diff changeset
391 retval[X86ThreadContext.ESP] = winRegs[7];
a61af66fc99e Initial load
duke
parents:
diff changeset
392 retval[X86ThreadContext.EIP] = winRegs[8];
a61af66fc99e Initial load
duke
parents:
diff changeset
393 retval[X86ThreadContext.DS] = winRegs[9];
a61af66fc99e Initial load
duke
parents:
diff changeset
394 retval[X86ThreadContext.ES] = winRegs[10];
a61af66fc99e Initial load
duke
parents:
diff changeset
395 retval[X86ThreadContext.FS] = winRegs[11];
a61af66fc99e Initial load
duke
parents:
diff changeset
396 retval[X86ThreadContext.GS] = winRegs[12];
a61af66fc99e Initial load
duke
parents:
diff changeset
397 retval[X86ThreadContext.CS] = winRegs[13];
a61af66fc99e Initial load
duke
parents:
diff changeset
398 retval[X86ThreadContext.SS] = winRegs[14];
a61af66fc99e Initial load
duke
parents:
diff changeset
399 retval[X86ThreadContext.EFL] = winRegs[15];
a61af66fc99e Initial load
duke
parents:
diff changeset
400 retval[X86ThreadContext.DR0] = winRegs[16];
a61af66fc99e Initial load
duke
parents:
diff changeset
401 retval[X86ThreadContext.DR1] = winRegs[17];
a61af66fc99e Initial load
duke
parents:
diff changeset
402 retval[X86ThreadContext.DR2] = winRegs[18];
a61af66fc99e Initial load
duke
parents:
diff changeset
403 retval[X86ThreadContext.DR3] = winRegs[19];
a61af66fc99e Initial load
duke
parents:
diff changeset
404 retval[X86ThreadContext.DR6] = winRegs[20];
a61af66fc99e Initial load
duke
parents:
diff changeset
405 retval[X86ThreadContext.DR7] = winRegs[21];
a61af66fc99e Initial load
duke
parents:
diff changeset
406 return retval;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 public synchronized void setThreadIntegerRegisterSet(int threadHandleValue,
a61af66fc99e Initial load
duke
parents:
diff changeset
413 boolean mustDuplicateHandle,
a61af66fc99e Initial load
duke
parents:
diff changeset
414 long[] context)
a61af66fc99e Initial load
duke
parents:
diff changeset
415 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 int handle = threadHandleValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 handle = (int) in.parseAddress(); // Must close to avoid leaks
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // Change order of registers to match that of debug server
a61af66fc99e Initial load
duke
parents:
diff changeset
430 long[] winRegs = new long[context.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
431 winRegs[0] = context[X86ThreadContext.EAX];
a61af66fc99e Initial load
duke
parents:
diff changeset
432 winRegs[1] = context[X86ThreadContext.EBX];
a61af66fc99e Initial load
duke
parents:
diff changeset
433 winRegs[2] = context[X86ThreadContext.ECX];
a61af66fc99e Initial load
duke
parents:
diff changeset
434 winRegs[3] = context[X86ThreadContext.EDX];
a61af66fc99e Initial load
duke
parents:
diff changeset
435 winRegs[4] = context[X86ThreadContext.ESI];
a61af66fc99e Initial load
duke
parents:
diff changeset
436 winRegs[5] = context[X86ThreadContext.EDI];
a61af66fc99e Initial load
duke
parents:
diff changeset
437 winRegs[6] = context[X86ThreadContext.EBP];
a61af66fc99e Initial load
duke
parents:
diff changeset
438 winRegs[7] = context[X86ThreadContext.ESP];
a61af66fc99e Initial load
duke
parents:
diff changeset
439 winRegs[8] = context[X86ThreadContext.EIP];
a61af66fc99e Initial load
duke
parents:
diff changeset
440 winRegs[9] = context[X86ThreadContext.DS];
a61af66fc99e Initial load
duke
parents:
diff changeset
441 winRegs[10] = context[X86ThreadContext.ES];
a61af66fc99e Initial load
duke
parents:
diff changeset
442 winRegs[11] = context[X86ThreadContext.FS];
a61af66fc99e Initial load
duke
parents:
diff changeset
443 winRegs[12] = context[X86ThreadContext.GS];
a61af66fc99e Initial load
duke
parents:
diff changeset
444 winRegs[13] = context[X86ThreadContext.CS];
a61af66fc99e Initial load
duke
parents:
diff changeset
445 winRegs[14] = context[X86ThreadContext.SS];
a61af66fc99e Initial load
duke
parents:
diff changeset
446 winRegs[15] = context[X86ThreadContext.EFL];
a61af66fc99e Initial load
duke
parents:
diff changeset
447 winRegs[16] = context[X86ThreadContext.DR0];
a61af66fc99e Initial load
duke
parents:
diff changeset
448 winRegs[17] = context[X86ThreadContext.DR1];
a61af66fc99e Initial load
duke
parents:
diff changeset
449 winRegs[18] = context[X86ThreadContext.DR2];
a61af66fc99e Initial load
duke
parents:
diff changeset
450 winRegs[19] = context[X86ThreadContext.DR3];
a61af66fc99e Initial load
duke
parents:
diff changeset
451 winRegs[20] = context[X86ThreadContext.DR6];
a61af66fc99e Initial load
duke
parents:
diff changeset
452 winRegs[21] = context[X86ThreadContext.DR7];
a61af66fc99e Initial load
duke
parents:
diff changeset
453 StringBuffer cmd = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 cmd.append("setcontext 0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
455 cmd.append(Integer.toHexString(threadHandleValue));
a61af66fc99e Initial load
duke
parents:
diff changeset
456 for (int i = 0; i < context.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 cmd.append(" 0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
458 cmd.append(Long.toHexString(winRegs[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 printlnToOutput(cmd.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
461 boolean res = in.parseBoolean();
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 if (!res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 String failMessage = "SetThreadContext failed for thread handle 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
467 Integer.toHexString(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 failMessage = failMessage + ", duplicated from thread handle " +
a61af66fc99e Initial load
duke
parents:
diff changeset
470 Integer.toHexString(threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472 throw new DebuggerException(failMessage);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 /** Fetches the Win32 LDT_ENTRY for the given thread and selector.
a61af66fc99e Initial load
duke
parents:
diff changeset
480 This data structure allows the conversion of a segment-relative
a61af66fc99e Initial load
duke
parents:
diff changeset
481 address to a linear virtual address. For example, it allows the
a61af66fc99e Initial load
duke
parents:
diff changeset
482 expression of operations like "mov eax, fs:[18h]", which fetches
a61af66fc99e Initial load
duke
parents:
diff changeset
483 the thread information block, allowing access to the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
484 ID. */
a61af66fc99e Initial load
duke
parents:
diff changeset
485 public synchronized Win32LDTEntry getThreadSelectorEntry(int threadHandleValue,
a61af66fc99e Initial load
duke
parents:
diff changeset
486 boolean mustDuplicateHandle,
a61af66fc99e Initial load
duke
parents:
diff changeset
487 int selector)
a61af66fc99e Initial load
duke
parents:
diff changeset
488 throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 int handle = threadHandleValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 handle = (int) in.parseAddress(); // Must close to avoid leaks
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 printlnToOutput("selectorentry 0x" + Integer.toHexString(handle) + " " + selector);
a61af66fc99e Initial load
duke
parents:
diff changeset
499 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (mustDuplicateHandle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
503 throw new DebuggerException("GetThreadContext failed for thread handle 0x" + handle +
a61af66fc99e Initial load
duke
parents:
diff changeset
504 ", duplicated from thread handle " + threadHandleValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 // Parse result. See
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // src/os/win32/agent/README-commands.txt for the format.
a61af66fc99e Initial load
duke
parents:
diff changeset
508 short limitLow = (short) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 short baseLow = (short) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
510 byte baseMid = (byte) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
511 byte flags1 = (byte) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
512 byte flags2 = (byte) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
513 byte baseHi = (byte) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
514 return new Win32LDTEntry(limitLow, baseLow, baseMid, flags1, flags2, baseHi);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 public synchronized List getThreadList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 printlnToOutput("threadlist");
a61af66fc99e Initial load
duke
parents:
diff changeset
527 List ret = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
528 int numThreads = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
529 for (int i = 0; i < numThreads; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 int handle = (int) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
531 ret.add(new Win32Thread(this, handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
538
a61af66fc99e Initial load
duke
parents:
diff changeset
539 public synchronized List getLoadObjectList() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
541 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 if (loadObjects == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 loadObjects = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
547 nameToDllMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // Get list of library names and base addresses
a61af66fc99e Initial load
duke
parents:
diff changeset
549 printlnToOutput("libinfo");
a61af66fc99e Initial load
duke
parents:
diff changeset
550 int numInfo = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 for (int i = 0; i < numInfo; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // NOTE: because Win32 is case insensitive, we standardize on
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // lowercase file names.
a61af66fc99e Initial load
duke
parents:
diff changeset
555 String fullPathName = parseString().toLowerCase();
a61af66fc99e Initial load
duke
parents:
diff changeset
556 Address base = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 File file = new File(fullPathName);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 long size = file.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
560 DLL dll = new DLL(this, fullPathName, size, base);
a61af66fc99e Initial load
duke
parents:
diff changeset
561 String name = file.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
562 nameToDllMap.put(name, dll);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 loadObjects.add(dll);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 return loadObjects;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 }
a61af66fc99e Initial load
duke
parents:
diff changeset
572
a61af66fc99e Initial load
duke
parents:
diff changeset
573 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // Process control access
a61af66fc99e Initial load
duke
parents:
diff changeset
575 //
a61af66fc99e Initial load
duke
parents:
diff changeset
576
a61af66fc99e Initial load
duke
parents:
diff changeset
577 public synchronized void writeBytesToProcess(long startAddress, long numBytes, byte[] data)
a61af66fc99e Initial load
duke
parents:
diff changeset
578 throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 printToOutput("poke 0x" + Long.toHexString(startAddress) +
a61af66fc99e Initial load
duke
parents:
diff changeset
581 " |");
a61af66fc99e Initial load
duke
parents:
diff changeset
582 writeIntToOutput((int) numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 writeToOutput(data, 0, (int) numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
584 printlnToOutput("");
a61af66fc99e Initial load
duke
parents:
diff changeset
585 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 throw new UnmappedAddressException(startAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
589 throw new DebuggerException(e);
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 public synchronized void suspend() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
594 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if (suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 throw new DebuggerException("Process already suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
598 printlnToOutput("suspend");
a61af66fc99e Initial load
duke
parents:
diff changeset
599 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
600 enableCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
601 reresolveLoadObjects();
a61af66fc99e Initial load
duke
parents:
diff changeset
602 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 public synchronized void resume() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
610 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612 disableCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
613 printlnToOutput("resume");
a61af66fc99e Initial load
duke
parents:
diff changeset
614 suspended = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
615 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
616 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
617 }
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 public synchronized boolean isSuspended() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 return suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 public synchronized void setBreakpoint(Address addr) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 long addrVal = getAddressValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
630 Long where = new Long(addrVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
631 if (breakpoints.get(where) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 throw new DebuggerException("Breakpoint already set at " + addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634 Byte what = new Byte(readBytes(addrVal, 1)[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // Now put 0xCC (int 3) at the target address, fail if can not
a61af66fc99e Initial load
duke
parents:
diff changeset
636 writeBytesToProcess(addrVal, 1, new byte[] { (byte) 0xCC });
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // OK, the breakpoint is set.
a61af66fc99e Initial load
duke
parents:
diff changeset
638 breakpoints.put(where, what);
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 public synchronized void clearBreakpoint(Address addr) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 if (!suspended) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 throw new DebuggerException("Process not suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 long addrVal = getAddressValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 Long where = new Long(addrVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
648 Byte what = (Byte) breakpoints.get(where);
a61af66fc99e Initial load
duke
parents:
diff changeset
649 if (what == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 throw new DebuggerException("Breakpoint not set at " + addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // Put original data back at address
a61af66fc99e Initial load
duke
parents:
diff changeset
653 writeBytesToProcess(addrVal, 1, new byte[] { what.byteValue() });
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // OK, breakpoint is cleared
a61af66fc99e Initial load
duke
parents:
diff changeset
655 breakpoints.remove(where);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 public synchronized boolean isBreakpointSet(Address addr) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 return (breakpoints.get(new Long(getAddressValue(addr))) != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
661
a61af66fc99e Initial load
duke
parents:
diff changeset
662 // Following constants taken from winnt.h
a61af66fc99e Initial load
duke
parents:
diff changeset
663 private static final int EXCEPTION_DEBUG_EVENT = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
664 private static final int LOAD_DLL_DEBUG_EVENT = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
665 private static final int UNLOAD_DLL_DEBUG_EVENT = 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 private static final int EXCEPTION_ACCESS_VIOLATION = 0xC0000005;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 private static final int EXCEPTION_BREAKPOINT = 0x80000003;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 private static final int EXCEPTION_SINGLE_STEP = 0x80000004;
a61af66fc99e Initial load
duke
parents:
diff changeset
669
a61af66fc99e Initial load
duke
parents:
diff changeset
670 public synchronized DebugEvent debugEventPoll() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 if (curDebugEvent != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 return curDebugEvent;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 printlnToOutput("pollevent");
a61af66fc99e Initial load
duke
parents:
diff changeset
677 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
679 }
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // Otherwise, got a debug event. Need to figure out what kind it is.
a61af66fc99e Initial load
duke
parents:
diff changeset
681 int handle = (int) in.parseAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
682 ThreadProxy thread = new Win32Thread(this, handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
683 int code = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
684 DebugEvent ev = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
685 switch (code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 case LOAD_DLL_DEBUG_EVENT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 Address addr = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
688 ev = BasicDebugEvent.newLoadObjectLoadEvent(thread, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691
a61af66fc99e Initial load
duke
parents:
diff changeset
692 case UNLOAD_DLL_DEBUG_EVENT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 Address addr = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
694 ev = BasicDebugEvent.newLoadObjectUnloadEvent(thread, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
695 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697
a61af66fc99e Initial load
duke
parents:
diff changeset
698 case EXCEPTION_DEBUG_EVENT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 int exceptionCode = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
700 Address pc = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
701 switch (exceptionCode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 case EXCEPTION_ACCESS_VIOLATION:
a61af66fc99e Initial load
duke
parents:
diff changeset
703 boolean wasWrite = in.parseBoolean();
a61af66fc99e Initial load
duke
parents:
diff changeset
704 Address addr = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
705 ev = BasicDebugEvent.newAccessViolationEvent(thread, pc, wasWrite, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
706 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
707
a61af66fc99e Initial load
duke
parents:
diff changeset
708 case EXCEPTION_BREAKPOINT:
a61af66fc99e Initial load
duke
parents:
diff changeset
709 ev = BasicDebugEvent.newBreakpointEvent(thread, pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
711
a61af66fc99e Initial load
duke
parents:
diff changeset
712 case EXCEPTION_SINGLE_STEP:
a61af66fc99e Initial load
duke
parents:
diff changeset
713 ev = BasicDebugEvent.newSingleStepEvent(thread, pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
715
a61af66fc99e Initial load
duke
parents:
diff changeset
716 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
717 ev = BasicDebugEvent.newUnknownEvent(thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
718 "Exception 0x" + Integer.toHexString(exceptionCode) +
a61af66fc99e Initial load
duke
parents:
diff changeset
719 " at PC " + pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
724
a61af66fc99e Initial load
duke
parents:
diff changeset
725 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
726 ev = BasicDebugEvent.newUnknownEvent(thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
727 "Debug event " + code + " occurred");
a61af66fc99e Initial load
duke
parents:
diff changeset
728 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 Assert.that(ev != null, "Must have created event");
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 curDebugEvent = ev;
a61af66fc99e Initial load
duke
parents:
diff changeset
734 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 return curDebugEvent;
a61af66fc99e Initial load
duke
parents:
diff changeset
739 }
a61af66fc99e Initial load
duke
parents:
diff changeset
740
a61af66fc99e Initial load
duke
parents:
diff changeset
741 public synchronized void debugEventContinue() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if (curDebugEvent == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 throw new DebuggerException("No debug event pending");
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 ///////////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
748 // //
a61af66fc99e Initial load
duke
parents:
diff changeset
749 // FIXME: this **must** be modified to handle breakpoint events
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // properly. Must temporarily remove the breakpoint and enable
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // single-stepping mode (hiding those single-step events from
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // the user unless they have been requested; currently there is
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // no way to request single-step events; and it isn't clear how
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // to enable them or how the hardware and/or OS typically
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // supports them, i.e., are they on a per-process or per-thread
a61af66fc99e Initial load
duke
parents:
diff changeset
756 // level?) until the process steps past the breakpoint, then put
a61af66fc99e Initial load
duke
parents:
diff changeset
757 // the breakpoint back.
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // //
a61af66fc99e Initial load
duke
parents:
diff changeset
759 ///////////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 DebugEvent.Type t = curDebugEvent.getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
762 boolean shouldPassOn = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
763 if (t == DebugEvent.Type.BREAKPOINT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 // FIXME: correct algorithm appears to be as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
765 //
a61af66fc99e Initial load
duke
parents:
diff changeset
766 // 1. Check to see whether we know about this breakpoint. If
a61af66fc99e Initial load
duke
parents:
diff changeset
767 // not, it's requested by the user's program and we should
a61af66fc99e Initial load
duke
parents:
diff changeset
768 // ignore it (not pass it on to the program).
a61af66fc99e Initial load
duke
parents:
diff changeset
769 //
a61af66fc99e Initial load
duke
parents:
diff changeset
770 // 2. Replace the original opcode.
a61af66fc99e Initial load
duke
parents:
diff changeset
771 //
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // 3. Set single-stepping mode in the debug registers.
a61af66fc99e Initial load
duke
parents:
diff changeset
773 //
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // 4. Back up the PC.
a61af66fc99e Initial load
duke
parents:
diff changeset
775 //
a61af66fc99e Initial load
duke
parents:
diff changeset
776 // 5. In debugEventPoll(), watch for a single-step event on
a61af66fc99e Initial load
duke
parents:
diff changeset
777 // this thread. When we get it, put the breakpoint back. Only
a61af66fc99e Initial load
duke
parents:
diff changeset
778 // deliver that single-step event if the user has requested
a61af66fc99e Initial load
duke
parents:
diff changeset
779 // single-step events (FIXME: must figure out whether they are
a61af66fc99e Initial load
duke
parents:
diff changeset
780 // per-thread or per-process, and also expose a way to turn
a61af66fc99e Initial load
duke
parents:
diff changeset
781 // them on.)
a61af66fc99e Initial load
duke
parents:
diff changeset
782
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // To make breakpoints work for now, we will just back up the
a61af66fc99e Initial load
duke
parents:
diff changeset
784 // PC, which we have to do in order to not disrupt the program
a61af66fc99e Initial load
duke
parents:
diff changeset
785 // execution in case the user decides to disable the breakpoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787 if (breakpoints.get(new Long(getAddressValue(curDebugEvent.getPC()))) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
788 System.err.println("Backing up PC due to breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
789 X86ThreadContext ctx = (X86ThreadContext) curDebugEvent.getThread().getContext();
a61af66fc99e Initial load
duke
parents:
diff changeset
790 ctx.setRegister(X86ThreadContext.EIP, ctx.getRegister(X86ThreadContext.EIP) - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
791 curDebugEvent.getThread().setContext(ctx);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 System.err.println("Skipping back up of PC since I didn't know about this breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
794 System.err.println("Known breakpoints:");
a61af66fc99e Initial load
duke
parents:
diff changeset
795 for (Iterator iter = breakpoints.keySet().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
796 System.err.println(" 0x" + Long.toHexString(((Long) iter.next()).longValue()));
a61af66fc99e Initial load
duke
parents:
diff changeset
797 }
a61af66fc99e Initial load
duke
parents:
diff changeset
798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
799 shouldPassOn = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 } else if (t == DebugEvent.Type.SINGLE_STEP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 shouldPassOn = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // Other kinds of debug events are either ignored if passed on
a61af66fc99e Initial load
duke
parents:
diff changeset
804 // or probably should be passed on so the program exits
a61af66fc99e Initial load
duke
parents:
diff changeset
805 // FIXME: generate process exiting events (should be easy)
a61af66fc99e Initial load
duke
parents:
diff changeset
806
a61af66fc99e Initial load
duke
parents:
diff changeset
807 int val = (shouldPassOn ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
808 printlnToOutput("continueevent " + val);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if (!in.parseBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 throw new DebuggerException("Unknown error while attempting to continue past debug event");
a61af66fc99e Initial load
duke
parents:
diff changeset
811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
812 curDebugEvent = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
813 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
819 // Address access
a61af66fc99e Initial load
duke
parents:
diff changeset
820 //
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 /** From the Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
823 public long getAddressValue(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 if (addr == null) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
825 return ((Win32Address) addr).getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
826 }
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 /** From the Win32Debugger interface */
a61af66fc99e Initial load
duke
parents:
diff changeset
829 public Address newAddress(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
830 if (value == 0) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 return new Win32Address(this, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
835 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
836 //
a61af66fc99e Initial load
duke
parents:
diff changeset
837
a61af66fc99e Initial load
duke
parents:
diff changeset
838 private String parseString() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 int charSize = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
840 int numChars = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
841 in.skipByte();
a61af66fc99e Initial load
duke
parents:
diff changeset
842 String str;
a61af66fc99e Initial load
duke
parents:
diff changeset
843 if (charSize == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 str = in.readByteString(numChars);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 str = in.readCharString(numChars);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848 return str;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 }
a61af66fc99e Initial load
duke
parents:
diff changeset
850
a61af66fc99e Initial load
duke
parents:
diff changeset
851 /** Looks up an address in the remote process's address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
852 Returns 0 if symbol not found or upon error. Package private to
a61af66fc99e Initial load
duke
parents:
diff changeset
853 allow Win32DebuggerRemoteIntfImpl access. NOTE that this returns
a61af66fc99e Initial load
duke
parents:
diff changeset
854 a long instead of an Address because we do not want to serialize
a61af66fc99e Initial load
duke
parents:
diff changeset
855 Addresses. */
a61af66fc99e Initial load
duke
parents:
diff changeset
856 synchronized long lookupInProcess(String objectName, String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 // NOTE: this assumes that process is suspended (which is probably
a61af66fc99e Initial load
duke
parents:
diff changeset
858 // necessary assumption given that DLLs can be loaded/unloaded as
a61af66fc99e Initial load
duke
parents:
diff changeset
859 // process runs). Should update documentation.
a61af66fc99e Initial load
duke
parents:
diff changeset
860 if (nameToDllMap == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 getLoadObjectList();
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863 DLL dll = (DLL) nameToDllMap.get(objectName);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 // The DLL can be null because we use this to search through known
a61af66fc99e Initial load
duke
parents:
diff changeset
865 // DLLs in HotSpotTypeDataBase (for example)
a61af66fc99e Initial load
duke
parents:
diff changeset
866 if (dll != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
867 Win32Address addr = (Win32Address) dll.lookupSymbol(symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (addr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 return addr.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
873 }
a61af66fc99e Initial load
duke
parents:
diff changeset
874
a61af66fc99e Initial load
duke
parents:
diff changeset
875 /** This reads bytes from the remote process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
876 public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
877 throws UnmappedAddressException, DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
879 String cmd = "peek " + utils.addressValueToString(address) + " " + numBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
880 printlnToOutput(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 while (in.readByte() != 'B') {
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 byte res = in.readByte();
a61af66fc99e Initial load
duke
parents:
diff changeset
884 if (res == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
885 System.err.println("Failing command: " + cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
886 throw new DebuggerException("Read of remote process address space failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
888 // NOTE: must read ALL of the data regardless of whether we need
a61af66fc99e Initial load
duke
parents:
diff changeset
889 // to throw an UnmappedAddressException. Otherwise will corrupt
a61af66fc99e Initial load
duke
parents:
diff changeset
890 // the input stream each time we have a failure. Not good. Do
a61af66fc99e Initial load
duke
parents:
diff changeset
891 // not want to risk "flushing" the input stream in case a huge
a61af66fc99e Initial load
duke
parents:
diff changeset
892 // read has a hangup in the middle and we leave data on the
a61af66fc99e Initial load
duke
parents:
diff changeset
893 // stream.
a61af66fc99e Initial load
duke
parents:
diff changeset
894 byte[] buf = new byte[(int) numBytes];
a61af66fc99e Initial load
duke
parents:
diff changeset
895 boolean bailOut = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
896 long failureAddress = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
897 while (numBytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 long len = in.readUnsignedInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
899 boolean isMapped = ((in.readByte() == 0) ? false : true);
a61af66fc99e Initial load
duke
parents:
diff changeset
900 if (!isMapped) {
a61af66fc99e Initial load
duke
parents:
diff changeset
901 if (!bailOut) {
a61af66fc99e Initial load
duke
parents:
diff changeset
902 bailOut = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
903 failureAddress = address;
a61af66fc99e Initial load
duke
parents:
diff changeset
904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
905 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 // This won't work if we have unmapped regions, but if we do
a61af66fc99e Initial load
duke
parents:
diff changeset
907 // then we're going to throw an exception anyway
a61af66fc99e Initial load
duke
parents:
diff changeset
908
a61af66fc99e Initial load
duke
parents:
diff changeset
909 // NOTE: there is a factor of 20 speed difference between
a61af66fc99e Initial load
duke
parents:
diff changeset
910 // these two ways of doing this read.
a61af66fc99e Initial load
duke
parents:
diff changeset
911 in.readBytes(buf, 0, (int) len);
a61af66fc99e Initial load
duke
parents:
diff changeset
912 }
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // Do NOT do this:
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // for (int i = 0; i < (int) len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 // buf[i] = in.readByte();
a61af66fc99e Initial load
duke
parents:
diff changeset
917 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
918
a61af66fc99e Initial load
duke
parents:
diff changeset
919 numBytes -= len;
a61af66fc99e Initial load
duke
parents:
diff changeset
920 address += len;
a61af66fc99e Initial load
duke
parents:
diff changeset
921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
922 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
923 Assert.that(numBytes == 0, "Bug in debug server's implementation of peek");
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925 if (bailOut) {
a61af66fc99e Initial load
duke
parents:
diff changeset
926 return new ReadResult(failureAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
927 }
a61af66fc99e Initial load
duke
parents:
diff changeset
928 return new ReadResult(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
931 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
932 }
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934
a61af66fc99e Initial load
duke
parents:
diff changeset
935 /** Convenience routines */
a61af66fc99e Initial load
duke
parents:
diff changeset
936 private void printlnToOutput(String s) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
937 out.println(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
938 if (out.checkError()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 throw new IOException("Error occurred while writing to debug server");
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942
a61af66fc99e Initial load
duke
parents:
diff changeset
943 private void printToOutput(String s) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
944 out.print(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
945 if (out.checkError()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 throw new IOException("Error occurred while writing to debug server");
a61af66fc99e Initial load
duke
parents:
diff changeset
947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
948 }
a61af66fc99e Initial load
duke
parents:
diff changeset
949
a61af66fc99e Initial load
duke
parents:
diff changeset
950 private void writeIntToOutput(int val) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
951 rawOut.writeInt(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
952 rawOut.flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
953 }
a61af66fc99e Initial load
duke
parents:
diff changeset
954
a61af66fc99e Initial load
duke
parents:
diff changeset
955 private void writeToOutput(byte[] buf, int off, int len) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 rawOut.write(buf, off, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
957 rawOut.flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
958 }
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 /** Connects to the debug server, setting up out and in streams. */
a61af66fc99e Initial load
duke
parents:
diff changeset
961 private void connectToDebugServer() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
962 // Try for a short period of time to connect to debug server; time out
a61af66fc99e Initial load
duke
parents:
diff changeset
963 // with failure if didn't succeed
a61af66fc99e Initial load
duke
parents:
diff changeset
964 debuggerSocket = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
965 long endTime = System.currentTimeMillis() + SHORT_TIMEOUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
966
a61af66fc99e Initial load
duke
parents:
diff changeset
967 while ((debuggerSocket == null) && (System.currentTimeMillis() < endTime)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
969 // FIXME: this does not work if we are on a DHCP machine which
a61af66fc99e Initial load
duke
parents:
diff changeset
970 // did not get an IP address this session. It appears to use
a61af66fc99e Initial load
duke
parents:
diff changeset
971 // an old cached address and the connection does not actually
a61af66fc99e Initial load
duke
parents:
diff changeset
972 // succeed. Must file a bug.
a61af66fc99e Initial load
duke
parents:
diff changeset
973 // debuggerSocket = new Socket(InetAddress.getLocalHost(), PORT);
a61af66fc99e Initial load
duke
parents:
diff changeset
974 debuggerSocket = new Socket(InetAddress.getByName("127.0.0.1"), PORT);
a61af66fc99e Initial load
duke
parents:
diff changeset
975 debuggerSocket.setTcpNoDelay(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
976 }
a61af66fc99e Initial load
duke
parents:
diff changeset
977 catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 // Swallow IO exceptions while attempting connection
a61af66fc99e Initial load
duke
parents:
diff changeset
979 debuggerSocket = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
980 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 // Don't swamp the CPU
a61af66fc99e Initial load
duke
parents:
diff changeset
982 Thread.sleep(750);
a61af66fc99e Initial load
duke
parents:
diff changeset
983 }
a61af66fc99e Initial load
duke
parents:
diff changeset
984 catch (InterruptedException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
986 }
a61af66fc99e Initial load
duke
parents:
diff changeset
987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 if (debuggerSocket == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 // Failed to connect because of timeout
a61af66fc99e Initial load
duke
parents:
diff changeset
991 throw new DebuggerException("Timed out while attempting to connect to debug server (please start SwDbgSrv.exe)");
a61af66fc99e Initial load
duke
parents:
diff changeset
992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
993
a61af66fc99e Initial load
duke
parents:
diff changeset
994 out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(debuggerSocket.getOutputStream(), "US-ASCII")), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
995 rawOut = new DataOutputStream(new BufferedOutputStream(debuggerSocket.getOutputStream()));
a61af66fc99e Initial load
duke
parents:
diff changeset
996 in = new InputLexer(new BufferedInputStream(debuggerSocket.getInputStream()));
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 private DLL findDLLByName(String fullPathName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 for (Iterator iter = loadObjects.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 DLL dll = (DLL) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 if (dll.getName().equals(fullPathName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 return dll;
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1008
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 private void reresolveLoadObjects() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 // It is too expensive to throw away the loadobject list every
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 // time the process is suspended, largely because of debug
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 // information re-parsing. When we suspend the target process we
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 // instead fetch the list of loaded libraries in the target and
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 // see whether any loadobject needs to be thrown away (because it
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 // was unloaded) or invalidated (because it was unloaded and
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 // reloaded at a different target address). Note that we don't
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 // properly handle the case of a loaded DLL being unloaded,
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 // recompiled, and reloaded. We could handle this by keeping a
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 // time stamp.
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (loadObjects == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 // Need to create new list since have to figure out which ones
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 // were unloaded
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 List newLoadObjects = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1029
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 // Get list of library names and base addresses
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 printlnToOutput("libinfo");
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 int numInfo = in.parseInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
1033
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 for (int i = 0; i < numInfo; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 // NOTE: because Win32 is case insensitive, we standardize on
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 // lowercase file names.
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 String fullPathName = parseString().toLowerCase();
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 Address base = newAddress(in.parseAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
1039
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 // Look for full path name in DLL list
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 DLL dll = findDLLByName(fullPathName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 boolean mustLoad = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 if (dll != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 loadObjects.remove(dll);
a61af66fc99e Initial load
duke
parents:
diff changeset
1045
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 // See whether base addresses match; otherwise, need to reload
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 if (AddressOps.equal(base, dll.getBase())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 mustLoad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1051
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 if (mustLoad) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 // Create new DLL
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 File file = new File(fullPathName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 long size = file.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 String name = file.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 dll = new DLL(this, fullPathName, size, base);
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 nameToDllMap.put(name, dll);
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 newLoadObjects.add(dll);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 // All remaining entries in loadObjects have to be removed from
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 // the nameToDllMap
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 for (Iterator dllIter = loadObjects.iterator(); dllIter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 DLL dll = (DLL) dllIter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 for (Iterator iter = nameToDllMap.keySet().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 String name = (String) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 if (nameToDllMap.get(name) == dll) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 nameToDllMap.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1075
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 loadObjects = newLoadObjects;
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 loadObjects = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 nameToDllMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 throw new DebuggerException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 }