annotate agent/src/os/linux/LinuxDebuggerLocal.c @ 12329:f2512d89ad0c

8025613: clang: remove -Wno-unused-value Reviewed-by: iveresov
author twisti
date Sat, 28 Sep 2013 12:42:22 -0700
parents 96bd4772ec62
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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
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 #include <jni.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "libproc.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
28 #include <elf.h>
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
29 #include <sys/types.h>
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
30 #include <sys/stat.h>
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
31 #include <fcntl.h>
12329
f2512d89ad0c 8025613: clang: remove -Wno-unused-value
twisti
parents: 8670
diff changeset
32 #include <stdlib.h>
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
33 #include <string.h>
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
34 #include <limits.h>
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #if defined(x86_64) && !defined(amd64)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #define amd64 1
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #ifdef i386
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
42 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #ifdef amd64
a61af66fc99e Initial load
duke
parents:
diff changeset
45 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 #if defined(sparc) || defined(sparcv9)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
50 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 static jfieldID p_ps_prochandle_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 static jfieldID threadList_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 static jfieldID loadObjectList_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 static jmethodID createClosestSymbol_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static jmethodID createLoadObject_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static jmethodID getThreadForThreadId_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static jmethodID listAdd_ID = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
63 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
a61af66fc99e Initial load
duke
parents:
diff changeset
65
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
66 void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67 (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
70 struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
71 jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return (struct ps_prochandle*)(intptr_t)ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
76 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
77 * Method: init0
a61af66fc99e Initial load
duke
parents:
diff changeset
78 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
79 */
a61af66fc99e Initial load
duke
parents:
diff changeset
80 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0
a61af66fc99e Initial load
duke
parents:
diff changeset
81 (JNIEnv *env, jclass cls) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 jclass listClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
83
12329
f2512d89ad0c 8025613: clang: remove -Wno-unused-value
twisti
parents: 8670
diff changeset
84 if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
85 THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // fields we use
a61af66fc99e Initial load
duke
parents:
diff changeset
89 p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
90 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // methods we use
a61af66fc99e Initial load
duke
parents:
diff changeset
97 createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
a61af66fc99e Initial load
duke
parents:
diff changeset
98 "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
a61af66fc99e Initial load
duke
parents:
diff changeset
99 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
a61af66fc99e Initial load
duke
parents:
diff changeset
101 "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId",
a61af66fc99e Initial load
duke
parents:
diff changeset
104 "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
a61af66fc99e Initial load
duke
parents:
diff changeset
105 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // java.util.List method we call
a61af66fc99e Initial load
duke
parents:
diff changeset
107 listClass = (*env)->FindClass(env, "java/util/List");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize
a61af66fc99e Initial load
duke
parents:
diff changeset
114 (JNIEnv *env, jclass cls)
a61af66fc99e Initial load
duke
parents:
diff changeset
115 {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int n = 0, i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // add threads
a61af66fc99e Initial load
duke
parents:
diff changeset
129 n = get_num_threads(ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 for (i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 jobject thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 jobject threadList;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 lwpid_t lwpid;
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 lwpid = get_lwp_id(ph, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID,
a61af66fc99e Initial load
duke
parents:
diff changeset
137 (jlong)lwpid);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 threadList = (*env)->GetObjectField(env, this_obj, threadList_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // add load objects
a61af66fc99e Initial load
duke
parents:
diff changeset
146 n = get_num_libs(ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 for (i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 uintptr_t base;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 const char* name;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 jobject loadObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 jobject loadObjectList;
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 base = get_lib_base(ph, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 name = get_lib_name(ph, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
a61af66fc99e Initial load
duke
parents:
diff changeset
156 (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
165
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
166 /*
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
167 * Verify that a named ELF binary file (core or executable) has the same
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
168 * bitness as ourselves.
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
169 * Throw an exception if there is a mismatch or other problem.
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
170 *
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
171 * If we proceed using a mismatched debugger/debuggee, the best to hope
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
172 * for is a missing symbol, the worst is a crash searching for debug symbols.
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
173 */
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
174 void verifyBitness(JNIEnv *env, const char *binaryName) {
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
175 int fd = open(binaryName, O_RDONLY);
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
176 if (fd < 0) {
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
177 THROW_NEW_DEBUGGER_EXCEPTION("cannot open binary file");
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
178 }
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
179 unsigned char elf_ident[EI_NIDENT];
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
180 int i = read(fd, &elf_ident, sizeof(elf_ident));
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
181 close(fd);
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
182
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
183 if (i < 0) {
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
184 THROW_NEW_DEBUGGER_EXCEPTION("cannot read binary file");
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
185 }
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
186 #ifndef _LP64
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
187 if (elf_ident[EI_CLASS] == ELFCLASS64) {
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
188 THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use 64-bit java for debugger");
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
189 }
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
190 #else
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
191 if (elf_ident[EI_CLASS] != ELFCLASS64) {
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
192 THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger");
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
193 }
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
194 #endif
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
195 }
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
196
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
197
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
199 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
200 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 * Signature: (I)V
a61af66fc99e Initial load
duke
parents:
diff changeset
202 */
a61af66fc99e Initial load
duke
parents:
diff changeset
203 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
a61af66fc99e Initial load
duke
parents:
diff changeset
204 (JNIEnv *env, jobject this_obj, jint jpid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
206 // For bitness checking, locate binary at /proc/jpid/exe
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
207 char buf[PATH_MAX];
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
208 snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
209 verifyBitness(env, (char *) &buf);
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
210 CHECK_EXCEPTION;
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
211
0
a61af66fc99e Initial load
duke
parents:
diff changeset
212 struct ps_prochandle* ph;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if ( (ph = Pgrab(jpid)) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 fillThreadsAndLoadObjects(env, this_obj, ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
221 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
222 * Method: attach0
a61af66fc99e Initial load
duke
parents:
diff changeset
223 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
a61af66fc99e Initial load
duke
parents:
diff changeset
224 */
a61af66fc99e Initial load
duke
parents:
diff changeset
225 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
a61af66fc99e Initial load
duke
parents:
diff changeset
226 (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 const char *execName_cstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 const char *coreName_cstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 struct ps_prochandle* ph;
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
235 CHECK_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
236
8670
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
237 verifyBitness(env, execName_cstr);
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
238 CHECK_EXCEPTION;
96bd4772ec62 8008807: SA: jstack crash when target has mismatched bitness (Linux)
kevinw
parents: 7994
diff changeset
239
0
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 fillThreadsAndLoadObjects(env, this_obj, ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
252 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
253 * Method: detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
254 * Signature: ()V
a61af66fc99e Initial load
duke
parents:
diff changeset
255 */
a61af66fc99e Initial load
duke
parents:
diff changeset
256 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0
a61af66fc99e Initial load
duke
parents:
diff changeset
257 (JNIEnv *env, jobject this_obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (ph != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 Prelease(ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
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 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
266 * Method: lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
267 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
a61af66fc99e Initial load
duke
parents:
diff changeset
268 */
a61af66fc99e Initial load
duke
parents:
diff changeset
269 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 const char *objectName_cstr, *symbolName_cstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
272 jlong addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 objectName_cstr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if (objectName != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (objectName_cstr != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 return addr;
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 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
295 * Method: lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
296 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 */
a61af66fc99e Initial load
duke
parents:
diff changeset
298 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0
a61af66fc99e Initial load
duke
parents:
diff changeset
299 (JNIEnv *env, jobject this_obj, jlong addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 uintptr_t offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 const char* sym = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (sym == NULL) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
a61af66fc99e Initial load
duke
parents:
diff changeset
307 (*env)->NewStringUTF(env, sym), (jlong)offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
311 * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
a61af66fc99e Initial load
duke
parents:
diff changeset
312 * Method: readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
313 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 */
a61af66fc99e Initial load
duke
parents:
diff changeset
315 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
a61af66fc99e Initial load
duke
parents:
diff changeset
316 (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 jbyteArray array;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 jbyte *bufPtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 ps_err_e err;
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 array = (*env)->NewByteArray(env, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return (err == PS_OK)? array : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
7994
9fae07c31641 6518907: cleanup IA64 specific code in Hotspot
morris
parents: 6641
diff changeset
333 #if defined(i386) || defined(amd64) || defined(sparc) || defined(sparcv9)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
a61af66fc99e Initial load
duke
parents:
diff changeset
335 (JNIEnv *env, jobject this_obj, jint lwp_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337 struct user_regs_struct gregs;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 jboolean isCopy;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 jlongArray array;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 jlong *regs;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 #undef NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
349 #ifdef i386
a61af66fc99e Initial load
duke
parents:
diff changeset
350 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
351 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
352 #ifdef amd64
a61af66fc99e Initial load
duke
parents:
diff changeset
353 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
354 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
355 #if defined(sparc) || defined(sparcv9)
a61af66fc99e Initial load
duke
parents:
diff changeset
356 #define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG
a61af66fc99e Initial load
duke
parents:
diff changeset
357 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 array = (*env)->NewLongArray(env, NPRGREG);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 CHECK_EXCEPTION_(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 regs = (*env)->GetLongArrayElements(env, array, &isCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 #undef REG_INDEX
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 #ifdef i386
a61af66fc99e Initial load
duke
parents:
diff changeset
366 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 regs[REG_INDEX(DS)] = (uintptr_t) gregs.xds;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss;
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 #endif /* i386 */
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 #ifdef amd64
a61af66fc99e Initial load
duke
parents:
diff changeset
387 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 regs[REG_INDEX(R15)] = gregs.r15;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 regs[REG_INDEX(R14)] = gregs.r14;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 regs[REG_INDEX(R13)] = gregs.r13;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 regs[REG_INDEX(R12)] = gregs.r12;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 regs[REG_INDEX(RBP)] = gregs.rbp;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 regs[REG_INDEX(RBX)] = gregs.rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 regs[REG_INDEX(R11)] = gregs.r11;
a61af66fc99e Initial load
duke
parents:
diff changeset
396 regs[REG_INDEX(R10)] = gregs.r10;
a61af66fc99e Initial load
duke
parents:
diff changeset
397 regs[REG_INDEX(R9)] = gregs.r9;
a61af66fc99e Initial load
duke
parents:
diff changeset
398 regs[REG_INDEX(R8)] = gregs.r8;
a61af66fc99e Initial load
duke
parents:
diff changeset
399 regs[REG_INDEX(RAX)] = gregs.rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 regs[REG_INDEX(RCX)] = gregs.rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 regs[REG_INDEX(RDX)] = gregs.rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 regs[REG_INDEX(RSI)] = gregs.rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 regs[REG_INDEX(RDI)] = gregs.rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 regs[REG_INDEX(RIP)] = gregs.rip;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 regs[REG_INDEX(CS)] = gregs.cs;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 regs[REG_INDEX(RSP)] = gregs.rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 regs[REG_INDEX(SS)] = gregs.ss;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 regs[REG_INDEX(FSBASE)] = gregs.fs_base;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 regs[REG_INDEX(GSBASE)] = gregs.gs_base;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 regs[REG_INDEX(DS)] = gregs.ds;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 regs[REG_INDEX(ES)] = gregs.es;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 regs[REG_INDEX(FS)] = gregs.fs;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 regs[REG_INDEX(GS)] = gregs.gs;
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 #endif /* amd64 */
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 #if defined(sparc) || defined(sparcv9)
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
422 regs[REG_INDEX(R_PSR)] = gregs.tstate;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 regs[REG_INDEX(R_PC)] = gregs.tpc;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 regs[REG_INDEX(R_nPC)] = gregs.tnpc;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 regs[REG_INDEX(R_Y)] = gregs.y;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
427 regs[REG_INDEX(R_PSR)] = gregs.psr;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 regs[REG_INDEX(R_PC)] = gregs.pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 regs[REG_INDEX(R_nPC)] = gregs.npc;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 regs[REG_INDEX(R_Y)] = gregs.y;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
432 regs[REG_INDEX(R_G0)] = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
433 regs[REG_INDEX(R_G1)] = gregs.u_regs[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
434 regs[REG_INDEX(R_G2)] = gregs.u_regs[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
435 regs[REG_INDEX(R_G3)] = gregs.u_regs[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
436 regs[REG_INDEX(R_G4)] = gregs.u_regs[3];
a61af66fc99e Initial load
duke
parents:
diff changeset
437 regs[REG_INDEX(R_G5)] = gregs.u_regs[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
438 regs[REG_INDEX(R_G6)] = gregs.u_regs[5];
a61af66fc99e Initial load
duke
parents:
diff changeset
439 regs[REG_INDEX(R_G7)] = gregs.u_regs[6];
a61af66fc99e Initial load
duke
parents:
diff changeset
440 regs[REG_INDEX(R_O0)] = gregs.u_regs[7];
a61af66fc99e Initial load
duke
parents:
diff changeset
441 regs[REG_INDEX(R_O1)] = gregs.u_regs[8];
a61af66fc99e Initial load
duke
parents:
diff changeset
442 regs[REG_INDEX(R_O2)] = gregs.u_regs[ 9];
a61af66fc99e Initial load
duke
parents:
diff changeset
443 regs[REG_INDEX(R_O3)] = gregs.u_regs[10];
a61af66fc99e Initial load
duke
parents:
diff changeset
444 regs[REG_INDEX(R_O4)] = gregs.u_regs[11];
a61af66fc99e Initial load
duke
parents:
diff changeset
445 regs[REG_INDEX(R_O5)] = gregs.u_regs[12];
a61af66fc99e Initial load
duke
parents:
diff changeset
446 regs[REG_INDEX(R_O6)] = gregs.u_regs[13];
a61af66fc99e Initial load
duke
parents:
diff changeset
447 regs[REG_INDEX(R_O7)] = gregs.u_regs[14];
a61af66fc99e Initial load
duke
parents:
diff changeset
448 #endif /* sparc */
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 return array;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
454 #endif