annotate agent/src/os/bsd/MacosxDebuggerLocal.m @ 13450:5f07ec8bb982 jdk8-b121

Added tag hs25-b63 for changeset 41f4cad94c58
author amurillo
date Fri, 13 Dec 2013 09:40:58 -0800
parents e4614b063fe1
children f2294a37e723
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
1 /*
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
4 *
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
7 * published by the Free Software Foundation.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
8 *
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
13 * accompanied this code).
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
14 *
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
18 *
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
21 * questions.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
22 *
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
23 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
24
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
25 #include <objc/objc-runtime.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
26 #import <Foundation/Foundation.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
27 #import <JavaNativeFoundation/JavaNativeFoundation.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
28
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
29 #include <JavaVM/jni.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
30
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
31 #import <mach/mach.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
32 #import <mach/mach_types.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
33 #import <sys/sysctl.h>
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
34 #import <stdio.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
35 #import <stdarg.h>
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
36 #import <stdlib.h>
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
37 #import <strings.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
38 #import <dlfcn.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
39 #import <limits.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
40 #import <errno.h>
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
41 #import <sys/types.h>
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
42 #import <sys/ptrace.h>
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
43 #include "libproc_impl.h"
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
44
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
45 #define UNSUPPORTED_ARCH "Unsupported architecture!"
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
46
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
47 #if defined(x86_64) && !defined(amd64)
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
48 #define amd64 1
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
49 #endif
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
50
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
51 #if amd64
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
52 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
53 #else
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
54 #error UNSUPPORTED_ARCH
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
55 #endif
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
56
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
57 static jfieldID symbolicatorID = 0; // set in _init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
58 static jfieldID taskID = 0; // set in _init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
59
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
60 static jfieldID p_ps_prochandle_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
61 static jfieldID loadObjectList_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
62 static jmethodID listAdd_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
63
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
64 static jmethodID createClosestSymbol_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
65 static jmethodID createLoadObject_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
66 static jmethodID getJavaThreadsInfo_ID = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
67
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
68 // indicator if thread id (lwpid_t) was set
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
69 static bool _threads_filled = false;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
70
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
71 static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
72 (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
73 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
74
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
75 static id getSymbolicator(JNIEnv *env, jobject this_obj) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
76 jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
77 return (id)(intptr_t)ptr;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
78 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
79
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
80 static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
81 (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
82 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
83
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
84 static task_t getTask(JNIEnv *env, jobject this_obj) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
85 jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
86 return (task_t)ptr;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
87 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
88
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
89 #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
90 #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
91 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
92 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
93 #define CHECK_EXCEPTION_CLEAR if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); }
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
94 #define CHECK_EXCEPTION_CLEAR_VOID if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return; }
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4006
diff changeset
95 #define CHECK_EXCEPTION_CLEAR_(value) if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return value; }
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
96
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
97 static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
98 (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
99 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
100
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
101 static struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
102 jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
103 return (struct ps_prochandle*)(intptr_t)ptr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
104 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
105
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
106 #if defined(__i386__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
107 #define hsdb_thread_state_t x86_thread_state32_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
108 #define hsdb_float_state_t x86_float_state32_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
109 #define HSDB_THREAD_STATE x86_THREAD_STATE32
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
110 #define HSDB_FLOAT_STATE x86_FLOAT_STATE32
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
111 #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
112 #define HSDB_FLOAT_STATE_COUNT x86_FLOAT_STATE32_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
113 #elif defined(__x86_64__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
114 #define hsdb_thread_state_t x86_thread_state64_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
115 #define hsdb_float_state_t x86_float_state64_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
116 #define HSDB_THREAD_STATE x86_THREAD_STATE64
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
117 #define HSDB_FLOAT_STATE x86_FLOAT_STATE64
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
118 #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
119 #define HSDB_FLOAT_STATE_COUNT x86_FLOAT_STATE64_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
120 #else
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
121 #error UNSUPPORTED_ARCH
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
122 #endif
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
123
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
124 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
125 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
126 * Method: init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
127 * Signature: ()V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
128 */
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
129 JNIEXPORT void JNICALL
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
130 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
131 symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
132 taskID = (*env)->GetFieldID(env, cls, "task", "J");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
133 CHECK_EXCEPTION;
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
134
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
135 // for core file
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
136 p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
137 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
138 loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
139 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
140
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
141 // methods we use
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
142 createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
143 "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
144 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
145 createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
146 "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
147 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
148
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
149 // java.util.List method we call
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
150 jclass listClass = (*env)->FindClass(env, "java/util/List");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
151 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
152 listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
153 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
154 getJavaThreadsInfo_ID = (*env)->GetMethodID(env, cls, "getJavaThreadsInfo",
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
155 "()[J");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
156 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
157
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
158 init_libproc(getenv("LIBSAPROC_DEBUG") != NULL);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
159 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
160
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
161 JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
162 (JNIEnv *env, jclass cls)
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
163 {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
164 #ifdef _LP64
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
165 return 8;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
166 #else
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
167 #error UNSUPPORTED_ARCH
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
168 #endif
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
169 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
170
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
171 /** called by Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
172 jlong lookupByNameIncore(
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
173 JNIEnv *env, struct ps_prochandle *ph, jobject this_obj, jstring objectName, jstring symbolName)
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
174 {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
175 const char *objectName_cstr, *symbolName_cstr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
176 jlong addr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
177 jboolean isCopy;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
178 objectName_cstr = NULL;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
179 if (objectName != NULL) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
180 objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
181 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
182 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
183 symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
184 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
185
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
186 print_debug("look for %s \n", symbolName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
187 addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
188
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
189 if (objectName_cstr != NULL) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
190 (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
191 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
192 (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
193 return addr;
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
194 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
195
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
196 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
197 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
198 * Method: lookupByName0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
199 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
200 */
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
201 JNIEXPORT jlong JNICALL
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
202 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
203 JNIEnv *env, jobject this_obj,
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
204 jstring objectName, jstring symbolName)
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
205 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
206 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
207 if (ph != NULL && ph->core != NULL) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
208 return lookupByNameIncore(env, ph, this_obj, objectName, symbolName);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
209 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
210
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
211 jlong address = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
212
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
213 JNF_COCOA_ENTER(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
214 NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
215
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
216 print_debug("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
217
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
218 id symbolicator = getSymbolicator(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
219 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
220 uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
221 address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
222 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
223
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
224 print_debug("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
225 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
226
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
227 return address;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
228 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
229
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
230 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
231 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
232 * Method: lookupByAddress0
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
233 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
234 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
235 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
236 (JNIEnv *env, jobject this_obj, jlong addr) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
237 uintptr_t offset;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
238 const char* sym = NULL;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
239
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
240 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
241 if (ph != NULL && ph->core != NULL) {
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
242 sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
243 if (sym == NULL) return 0;
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
244 return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
245 (*env)->NewStringUTF(env, sym), (jlong)offset);
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
246 }
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
247 return 0;
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
248 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
249
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
250 /** called from Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
251 jbyteArray readBytesFromCore(
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
252 JNIEnv *env, struct ps_prochandle *ph, jobject this_obj, jlong addr, jlong numBytes)
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
253 {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
254 jboolean isCopy;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
255 jbyteArray array;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
256 jbyte *bufPtr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
257 ps_err_e err;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
258
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
259 array = (*env)->NewByteArray(env, numBytes);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
260 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
261 bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
262 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
263
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
264 err = ps_pread(ph, (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
265 (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
266 return (err == PS_OK)? array : 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
267 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
268
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
269 /*
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
270 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
271 * Method: readBytesFromProcess0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
272 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
273 */
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
274 JNIEXPORT jbyteArray JNICALL
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
275 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
276 JNIEnv *env, jobject this_obj,
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
277 jlong addr, jlong numBytes)
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
278 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
279 print_debug("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
280
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
281 // must allocate storage instead of using former parameter buf
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
282 jbyteArray array;
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
283
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
284 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
285 if (ph != NULL && ph->core != NULL) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
286 return readBytesFromCore(env, ph, this_obj, addr, numBytes);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
287 }
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
288
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
289 array = (*env)->NewByteArray(env, numBytes);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
290 CHECK_EXCEPTION_(0);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
291
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
292 unsigned long alignedAddress;
8688
40b7c6b800ab 8008327: [parfait] Unitialized variable in hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m
morris
parents: 8062
diff changeset
293 unsigned long alignedLength = 0;
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
294 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
295 vm_offset_t *pages;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
296 int *mapped;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
297 long pageCount;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
298 uint byteCount;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
299 int i;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
300 unsigned long remaining;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
301
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
302 alignedAddress = trunc_page(addr);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
303 if (addr != alignedAddress) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
304 alignedLength += addr - alignedAddress;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
305 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
306 alignedLength = round_page(numBytes);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
307 pageCount = alignedLength/vm_page_size;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
308
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
309 // Allocate storage for pages and flags.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
310 pages = malloc(pageCount * sizeof(vm_offset_t));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
311 mapped = calloc(pageCount, sizeof(int));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
312
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
313 task_t gTask = getTask(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
314 // Try to read each of the pages.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
315 for (i = 0; i < pageCount; i++) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
316 result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
317 &pages[i], &byteCount);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
318 mapped[i] = (result == KERN_SUCCESS);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
319 // assume all failures are unmapped pages
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
320 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
321
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
322 print_debug("%ld pages\n", pageCount);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
323
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
324 remaining = numBytes;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
325
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
326 for (i = 0; i < pageCount; i++) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
327 unsigned long len = vm_page_size;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
328 unsigned long start = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
329
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
330 if (i == 0) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
331 start = addr - alignedAddress;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
332 len = vm_page_size - start;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
333 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
334
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
335 if (i == (pageCount - 1)) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
336 len = remaining;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
337 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
338
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
339 if (mapped[i]) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
340 print_debug("page %d mapped (len %ld start %ld)\n", i, len, start);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
341 (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
342 vm_deallocate(mach_task_self(), pages[i], vm_page_size);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
343 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
344
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
345 remaining -= len;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
346 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
347
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
348 free (pages);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
349 free (mapped);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
350 return array;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
351 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
352
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
353 /** Only used for core file reading, set thread_id for threads which is got after core file parsed.
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
354 * Thread context is available in Mach-O core file but thread id is not. We can get thread id
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
355 * from Threads which store all java threads information when they are created. Here we can identify
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
356 * them as java threads by checking if a thread's rsp or rbp within a java thread's stack.
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
357 * Note Macosx uses unique_thread_id which is different from other platforms though printed ids
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
358 * are still pthread id. Function BsdDebuggerLocal.getJavaThreadsInfo returns an array of long
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
359 * integers to host all java threads' id, stack_start, stack_end as:
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
360 * [uid0, stack_start0, stack_end0, uid1, stack_start1, stack_end1, ...]
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
361 *
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
362 * The work cannot be done at init0 since Threads is not available yet(VM not initialized yet).
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
363 * This function should be called only once if succeeded
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
364 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
365 bool fill_java_threads(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
366 int n = 0, i = 0, j;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
367 struct reg regs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
368
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
369 jlongArray thrinfos = (*env)->CallObjectMethod(env, this_obj, getJavaThreadsInfo_ID);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
370 CHECK_EXCEPTION_(false);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
371 int len = (int)(*env)->GetArrayLength(env, thrinfos);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
372 uint64_t* cinfos = (uint64_t *)(*env)->GetLongArrayElements(env, thrinfos, NULL);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
373 CHECK_EXCEPTION_(false);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
374 n = get_num_threads(ph);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
375 print_debug("fill_java_threads called, num_of_thread = %d\n", n);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
376 for (i = 0; i < n; i++) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
377 if (!get_nth_lwp_regs(ph, i, &regs)) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
378 print_debug("Could not get regs of thread %d, already set!\n", i);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
379 return false;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
380 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
381 for (j = 0; j < len; j += 3) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
382 lwpid_t uid = cinfos[j];
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
383 uint64_t beg = cinfos[j + 1];
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
384 uint64_t end = cinfos[j + 2];
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
385 if ((regs.r_rsp < end && regs.r_rsp >= beg) ||
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
386 (regs.r_rbp < end && regs.r_rbp >= beg)) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
387 set_lwp_id(ph, i, uid);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
388 break;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
389 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
390 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
391 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
392 (*env)->ReleaseLongArrayElements(env, thrinfos, (jlong*)cinfos, 0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
393 CHECK_EXCEPTION_(false);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
394 return true;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
395 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
396
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
397 /* For core file only, called from
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
398 * Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
399 */
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
400 jlongArray getThreadIntegerRegisterSetFromCore(JNIEnv *env, jobject this_obj, long lwp_id, struct ps_prochandle* ph) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
401 if (!_threads_filled) {
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
402 if (!fill_java_threads(env, this_obj, ph)) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
403 throw_new_debugger_exception(env, "Failed to fill in threads");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
404 return 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
405 } else {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
406 _threads_filled = true;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
407 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
408 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
409
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
410 struct reg gregs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
411 jboolean isCopy;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
412 jlongArray array;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
413 jlong *regs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
414
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
415 if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
416 THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
417 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
418
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
419 #undef NPRGREG
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
420 #undef REG_INDEX
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
421 #if amd64
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
422 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
423 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
424
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
425 array = (*env)->NewLongArray(env, NPRGREG);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
426 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
427 regs = (*env)->GetLongArrayElements(env, array, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
428
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
429 regs[REG_INDEX(R15)] = gregs.r_r15;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
430 regs[REG_INDEX(R14)] = gregs.r_r14;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
431 regs[REG_INDEX(R13)] = gregs.r_r13;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
432 regs[REG_INDEX(R12)] = gregs.r_r12;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
433 regs[REG_INDEX(RBP)] = gregs.r_rbp;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
434 regs[REG_INDEX(RBX)] = gregs.r_rbx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
435 regs[REG_INDEX(R11)] = gregs.r_r11;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
436 regs[REG_INDEX(R10)] = gregs.r_r10;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
437 regs[REG_INDEX(R9)] = gregs.r_r9;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
438 regs[REG_INDEX(R8)] = gregs.r_r8;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
439 regs[REG_INDEX(RAX)] = gregs.r_rax;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
440 regs[REG_INDEX(RCX)] = gregs.r_rcx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
441 regs[REG_INDEX(RDX)] = gregs.r_rdx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
442 regs[REG_INDEX(RSI)] = gregs.r_rsi;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
443 regs[REG_INDEX(RDI)] = gregs.r_rdi;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
444 regs[REG_INDEX(RIP)] = gregs.r_rip;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
445 regs[REG_INDEX(CS)] = gregs.r_cs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
446 regs[REG_INDEX(RSP)] = gregs.r_rsp;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
447 regs[REG_INDEX(SS)] = gregs.r_ss;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
448 regs[REG_INDEX(FSBASE)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
449 regs[REG_INDEX(GSBASE)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
450 regs[REG_INDEX(DS)] = gregs.r_ds;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
451 regs[REG_INDEX(ES)] = gregs.r_es;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
452 regs[REG_INDEX(FS)] = gregs.r_fs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
453 regs[REG_INDEX(GS)] = gregs.r_gs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
454 regs[REG_INDEX(TRAPNO)] = gregs.r_trapno;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
455 regs[REG_INDEX(RFL)] = gregs.r_rflags;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
456
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
457 #endif /* amd64 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
458 (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
459 return array;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
460 }
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
461
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
462 /*
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
463 * Lookup the thread_t that corresponds to the given thread_id.
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
464 * The thread_id should be the result from calling thread_info() with THREAD_IDENTIFIER_INFO
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
465 * and reading the m_ident_info.thread_id returned.
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
466 * The returned thread_t is the mach send right to the kernel port for the corresponding thread.
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
467 *
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
468 * We cannot simply use the OSThread._thread_id field in the JVM. This is set to ::mach_thread_self()
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
469 * in the VM, but that thread port is not valid for a remote debugger to access the thread.
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
470 */
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
471 thread_t
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
472 lookupThreadFromThreadId(task_t task, jlong thread_id) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
473 print_debug("lookupThreadFromThreadId thread_id=0x%llx\n", thread_id);
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
474
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
475 thread_array_t thread_list = NULL;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
476 mach_msg_type_number_t thread_list_count = 0;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
477 thread_t result_thread = 0;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
478 int i;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
479
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
480 // get the list of all the send rights
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
481 kern_return_t result = task_threads(task, &thread_list, &thread_list_count);
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
482 if (result != KERN_SUCCESS) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
483 print_debug("task_threads returned 0x%x\n", result);
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
484 return 0;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
485 }
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
486
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
487 for(i = 0 ; i < thread_list_count; i++) {
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
488 thread_identifier_info_data_t m_ident_info;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
489 mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
490
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
491 // get the THREAD_IDENTIFIER_INFO for the send right
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
492 result = thread_info(thread_list[i], THREAD_IDENTIFIER_INFO, (thread_info_t) &m_ident_info, &count);
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
493 if (result != KERN_SUCCESS) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
494 print_debug("thread_info returned 0x%x\n", result);
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
495 break;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
496 }
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
497
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
498 // if this is the one we're looking for, return the send right
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
499 if (thread_id == m_ident_info.thread_id)
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
500 {
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
501 result_thread = thread_list[i];
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
502 break;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
503 }
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
504 }
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
505
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
506 vm_size_t thread_list_size = (vm_size_t) (thread_list_count * sizeof (thread_t));
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
507 vm_deallocate(mach_task_self(), (vm_address_t) thread_list, thread_list_count);
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
508
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
509 return result_thread;
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
510 }
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
511
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
512
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
513 /*
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
514 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
515 * Method: getThreadIntegerRegisterSet0
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
516 * Signature: (J)[J
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
517 */
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
518 JNIEXPORT jlongArray JNICALL
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
519 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
520 JNIEnv *env, jobject this_obj,
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
521 jlong thread_id)
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
522 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
523 print_debug("getThreadRegisterSet0 called\n");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
524
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
525 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
10158
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
526 if (ph != NULL && ph->core != NULL) {
9f96b7a853bc 8013466: SA crashes when attaching to a process on OS X
sla
parents: 8750
diff changeset
527 return getThreadIntegerRegisterSetFromCore(env, this_obj, thread_id, ph);
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
528 }
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
529
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
530 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
531 thread_t tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
532 mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
533 hsdb_thread_state_t state;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
534 jlongArray registerArray;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
535 jlong *primitiveArray;
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
536 task_t gTask = getTask(env, this_obj);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
537
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
538 tid = lookupThreadFromThreadId(gTask, thread_id);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
539
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
540 result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
541
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
542 if (result != KERN_SUCCESS) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
543 print_error("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
544 return NULL;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
545 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
546
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
547 #if amd64
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
548 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
549 #undef REG_INDEX
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
550 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
551
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
552 // 64 bit
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
553 print_debug("Getting threads for a 64-bit process\n");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
554 registerArray = (*env)->NewLongArray(env, NPRGREG);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
555 CHECK_EXCEPTION_(0);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
556 primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
557
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
558 primitiveArray[REG_INDEX(R15)] = state.__r15;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
559 primitiveArray[REG_INDEX(R14)] = state.__r14;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
560 primitiveArray[REG_INDEX(R13)] = state.__r13;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
561 primitiveArray[REG_INDEX(R12)] = state.__r12;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
562 primitiveArray[REG_INDEX(R11)] = state.__r11;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
563 primitiveArray[REG_INDEX(R10)] = state.__r10;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
564 primitiveArray[REG_INDEX(R9)] = state.__r9;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
565 primitiveArray[REG_INDEX(R8)] = state.__r8;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
566 primitiveArray[REG_INDEX(RDI)] = state.__rdi;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
567 primitiveArray[REG_INDEX(RSI)] = state.__rsi;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
568 primitiveArray[REG_INDEX(RBP)] = state.__rbp;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
569 primitiveArray[REG_INDEX(RBX)] = state.__rbx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
570 primitiveArray[REG_INDEX(RDX)] = state.__rdx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
571 primitiveArray[REG_INDEX(RCX)] = state.__rcx;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
572 primitiveArray[REG_INDEX(RAX)] = state.__rax;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
573 primitiveArray[REG_INDEX(TRAPNO)] = 0; // trapno, not used
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
574 primitiveArray[REG_INDEX(ERR)] = 0; // err, not used
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
575 primitiveArray[REG_INDEX(RIP)] = state.__rip;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
576 primitiveArray[REG_INDEX(CS)] = state.__cs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
577 primitiveArray[REG_INDEX(RFL)] = state.__rflags;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
578 primitiveArray[REG_INDEX(RSP)] = state.__rsp;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
579 primitiveArray[REG_INDEX(SS)] = 0; // We don't have SS
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
580 primitiveArray[REG_INDEX(FS)] = state.__fs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
581 primitiveArray[REG_INDEX(GS)] = state.__gs;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
582 primitiveArray[REG_INDEX(ES)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
583 primitiveArray[REG_INDEX(DS)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
584 primitiveArray[REG_INDEX(FSBASE)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
585 primitiveArray[REG_INDEX(GSBASE)] = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
586 print_debug("set registers\n");
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
587
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
588 (*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
589
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
590 #else
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
591 #error UNSUPPORTED_ARCH
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
592 #endif /* amd64 */
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
593
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
594 return registerArray;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
595 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
596
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
597 /*
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
598 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
599 * Method: translateTID0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
600 * Signature: (I)I
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
601 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
602 JNIEXPORT jint JNICALL
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
603 Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
604 JNIEnv *env, jobject this_obj, jint tid)
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
605 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
606 print_debug("translateTID0 called on tid = 0x%x\n", (int)tid);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
607
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
608 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
609 thread_t foreign_tid, usable_tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
610 mach_msg_type_name_t type;
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
611
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
612 foreign_tid = tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
613
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
614 task_t gTask = getTask(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
615 result = mach_port_extract_right(gTask, foreign_tid,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
616 MACH_MSG_TYPE_COPY_SEND,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
617 &usable_tid, &type);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
618 if (result != KERN_SUCCESS)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
619 return -1;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
620
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
621 print_debug("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
622
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
623 return (jint) usable_tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
624 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
625
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
626
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
627 static bool ptrace_continue(pid_t pid, int signal) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
628 // pass the signal to the process so we don't swallow it
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
629 int res;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
630 if ((res = ptrace(PT_CONTINUE, pid, (caddr_t)1, signal)) < 0) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
631 print_error("attach: ptrace(PT_CONTINUE, %d) failed with %d\n", pid, res);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
632 return false;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
633 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
634 return true;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
635 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
636
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
637 // waits until the ATTACH has stopped the process
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
638 // by signal SIGSTOP
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
639 static bool ptrace_waitpid(pid_t pid) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
640 int ret;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
641 int status;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
642 while (true) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
643 // Wait for debuggee to stop.
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
644 ret = waitpid(pid, &status, 0);
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
645 if (ret >= 0) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
646 if (WIFSTOPPED(status)) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
647 // Any signal will stop the thread, make sure it is SIGSTOP. Otherwise SIGSTOP
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
648 // will still be pending and delivered when the process is DETACHED and the process
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
649 // will go to sleep.
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
650 if (WSTOPSIG(status) == SIGSTOP) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
651 // Debuggee stopped by SIGSTOP.
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
652 return true;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
653 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
654 if (!ptrace_continue(pid, WSTOPSIG(status))) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
655 print_error("attach: Failed to correctly attach to VM. VM might HANG! [PTRACE_CONT failed, stopped by %d]\n", WSTOPSIG(status));
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
656 return false;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
657 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
658 } else {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
659 print_error("attach: waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
660 return false;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
661 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
662 } else {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
663 switch (errno) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
664 case EINTR:
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
665 continue;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
666 break;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
667 case ECHILD:
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
668 print_error("attach: waitpid() failed. Child process pid (%d) does not exist \n", pid);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
669 break;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
670 case EINVAL:
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
671 print_error("attach: waitpid() failed. Invalid options argument.\n");
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
672 break;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
673 default:
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
674 print_error("attach: waitpid() failed. Unexpected error %d\n",errno);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
675 break;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
676 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
677 return false;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
678 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
679 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
680 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
681
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
682 // attach to a process/thread specified by "pid"
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
683 static bool ptrace_attach(pid_t pid) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
684 int res;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
685 if ((res = ptrace(PT_ATTACH, pid, 0, 0)) < 0) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
686 print_error("ptrace(PT_ATTACH, %d) failed with %d\n", pid, res);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
687 return false;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
688 } else {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
689 return ptrace_waitpid(pid);
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
690 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
691 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
692
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
693 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
694 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
695 * Method: attach0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
696 * Signature: (I)V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
697 */
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
698 JNIEXPORT void JNICALL
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
699 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
700 JNIEnv *env, jobject this_obj, jint jpid)
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
701 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
702 print_debug("attach0 called for jpid=%d\n", (int)jpid);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
703
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
704 JNF_COCOA_ENTER(env);
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
705
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
706 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
707 task_t gTask = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
708 result = task_for_pid(mach_task_self(), jpid, &gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
709 if (result != KERN_SUCCESS) {
10162
e4614b063fe1 8013364: SA-JDI exceptions caused by lack of permissions on OSX should be more verbose about issue cause
sla
parents: 10158
diff changeset
710 print_error("attach: task_for_pid(%d) failed: '%s' (%d)\n", (int)jpid, mach_error_string(result), result);
e4614b063fe1 8013364: SA-JDI exceptions caused by lack of permissions on OSX should be more verbose about issue cause
sla
parents: 10158
diff changeset
711 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.");
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
712 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
713 putTask(env, this_obj, gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
714
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
715 // use ptrace to stop the process
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
716 // on os x, ptrace only needs to be called on the process, not the individual threads
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
717 if (ptrace_attach(jpid) != true) {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
718 mach_port_deallocate(mach_task_self(), gTask);
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
719 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
720 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
721
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
722 id symbolicator = nil;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
723 id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
724 if (jrsSymbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
725 id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
726 symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
727 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
728 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
729 CFRetain(symbolicator); // pin symbolicator while in java heap
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
730 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
731
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
732 putSymbolicator(env, this_obj, symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
733 if (symbolicator == nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
734 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
735 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
736
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
737 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
738 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
739
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
740 /** For core file,
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
741 called from Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
742 static void fillLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
743 int n = 0, i = 0;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
744
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
745 // add load objects
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
746 n = get_num_libs(ph);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
747 for (i = 0; i < n; i++) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
748 uintptr_t base;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
749 const char* name;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
750 jobject loadObject;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
751 jobject loadObjectList;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
752
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
753 base = get_lib_base(ph, i);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
754 name = get_lib_name(ph, i);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
755 loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
756 (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
757 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
758 loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
759 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
760 (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
761 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
762 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
763 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
764
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
765 /*
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
766 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
767 * Method: attach0
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
768 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
769 */
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
770 JNIEXPORT void JNICALL
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
771 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2(
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
772 JNIEnv *env, jobject this_obj, jstring execName, jstring coreName)
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
773 {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
774 const char *execName_cstr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
775 const char *coreName_cstr;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
776 jboolean isCopy;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
777 struct ps_prochandle* ph;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
778
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
779 execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
780 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
781 coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
782 CHECK_EXCEPTION;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
783
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
784 print_debug("attach: %s %s\n", execName_cstr, coreName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
785
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
786 if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
787 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
788 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
789 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
790 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
791 (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
792 (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
793 (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
794 fillLoadObjects(env, this_obj, ph);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
795 }
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
796
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
797 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
798 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
799 * Method: detach0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
800 * Signature: ()V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
801 */
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
802 JNIEXPORT void JNICALL
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
803 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
804 JNIEnv *env, jobject this_obj)
8023
758935f7c23f 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 6782
diff changeset
805 {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
806 print_debug("detach0 called\n");
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
807 struct ps_prochandle* ph = get_proc_handle(env, this_obj);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
808 if (ph != NULL && ph->core != NULL) {
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
809 Prelease(ph);
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
810 return;
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
811 }
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
812 JNF_COCOA_ENTER(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
813 task_t gTask = getTask(env, this_obj);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
814
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
815 // detach from the ptraced process causing it to resume execution
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
816 int pid;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
817 kern_return_t k_res;
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
818 k_res = pid_for_task(gTask, &pid);
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
819 if (k_res != KERN_SUCCESS) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
820 print_error("detach: pid_for_task(%d) failed (%d)\n", pid, k_res);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
821 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
822 else {
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
823 int res = ptrace(PT_DETACH, pid, 0, 0);
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
824 if (res < 0) {
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
825 print_error("detach: ptrace(PT_DETACH, %d) failed (%d)\n", pid, res);
8062
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
826 }
5d5c577296fd 8008102: SA on OS X does not stop the attached process
sla
parents: 8023
diff changeset
827 }
8750
39432a1cefdd 8003348: SA can not read core file on OS
minqi
parents: 8688
diff changeset
828
4006
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
829 mach_port_deallocate(mach_task_self(), gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
830 id symbolicator = getSymbolicator(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
831 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
832 CFRelease(symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
833 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
834 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
835 }