Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/debugger/win32/Win32Thread.java @ 1552:c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
author | trims |
---|---|
date | Thu, 27 May 2010 19:08:38 -0700 |
parents | a61af66fc99e |
children |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.debugger.win32; | |
26 | |
27 import sun.jvm.hotspot.debugger.*; | |
28 import sun.jvm.hotspot.debugger.x86.*; | |
29 | |
30 class Win32Thread implements ThreadProxy { | |
31 private Win32Debugger debugger; | |
32 private int handle; | |
33 private boolean mustDuplicate; | |
34 private boolean gotID; | |
35 private int id; | |
36 | |
37 /** The address argument must be the address of the HANDLE of the | |
38 desired thread in the target process. */ | |
39 Win32Thread(Win32Debugger debugger, Address addr) { | |
40 this.debugger = debugger; | |
41 // FIXME: size of data fetched here should be configurable. | |
42 // However, making it so would produce a dependency on the "types" | |
43 // package from the debugger package, which is not desired. | |
44 this.handle = (int) addr.getCIntegerAt(0, 4, true); | |
45 // Thread handles in the target process must be duplicated before | |
46 // fetching their contexts | |
47 mustDuplicate = true; | |
48 gotID = false; | |
49 } | |
50 | |
51 /** The integer argument must be the value of a HANDLE received from | |
52 the "threadlist" operation. */ | |
53 Win32Thread(Win32Debugger debugger, long handle) { | |
54 this.debugger = debugger; | |
55 this.handle = (int) handle; | |
56 mustDuplicate = false; | |
57 gotID = false; | |
58 } | |
59 | |
60 public ThreadContext getContext() throws IllegalThreadStateException { | |
61 if (!debugger.isSuspended()) { | |
62 throw new IllegalThreadStateException("Target process must be suspended"); | |
63 } | |
64 long[] data = debugger.getThreadIntegerRegisterSet(handle, mustDuplicate); | |
65 Win32ThreadContext context = new Win32ThreadContext(debugger); | |
66 for (int i = 0; i < data.length; i++) { | |
67 context.setRegister(i, data[i]); | |
68 } | |
69 return context; | |
70 } | |
71 | |
72 public boolean canSetContext() throws DebuggerException { | |
73 return true; | |
74 } | |
75 | |
76 public void setContext(ThreadContext thrCtx) | |
77 throws IllegalThreadStateException, DebuggerException { | |
78 if (!debugger.isSuspended()) { | |
79 throw new IllegalThreadStateException("Target process must be suspended"); | |
80 } | |
81 X86ThreadContext context = (X86ThreadContext) thrCtx; | |
82 long[] data = new long[X86ThreadContext.NPRGREG]; | |
83 for (int i = 0; i < data.length; i++) { | |
84 data[i] = context.getRegister(i); | |
85 } | |
86 debugger.setThreadIntegerRegisterSet(handle, mustDuplicate, data); | |
87 } | |
88 | |
89 public boolean equals(Object obj) { | |
90 if ((obj == null) || !(obj instanceof Win32Thread)) { | |
91 return false; | |
92 } | |
93 | |
94 return (((Win32Thread) obj).getThreadID() == getThreadID()); | |
95 } | |
96 | |
97 public int hashCode() { | |
98 return getThreadID(); | |
99 } | |
100 | |
101 public String toString() { | |
102 return Integer.toString(getThreadID()); | |
103 } | |
104 | |
105 /** Retrieves the thread ID of this thread by examining the Thread | |
106 Information Block. */ | |
107 private int getThreadID() { | |
108 if (!gotID) { | |
109 try { | |
110 // Get thread context | |
111 X86ThreadContext context = (X86ThreadContext) getContext(); | |
112 // Get LDT entry for FS register | |
113 Win32LDTEntry ldt = | |
114 debugger.getThreadSelectorEntry(handle, | |
115 mustDuplicate, | |
116 (int) context.getRegister(X86ThreadContext.FS)); | |
117 // Get base address of segment = Thread Environment Block (TEB) | |
118 Address teb = debugger.newAddress(ldt.getBase()); | |
119 // Thread ID is at offset 0x24 | |
120 id = (int) teb.getCIntegerAt(0x24, 4, true); | |
121 gotID = true; | |
122 } catch (AddressException e) { | |
123 throw new DebuggerException(e); | |
124 } | |
125 } | |
126 | |
127 return id; | |
128 } | |
129 } |