annotate agent/src/os/bsd/MacosxDebuggerLocal.m @ 4006:436b4a3231bf

7098194: integrate macosx-port changes Summary: Integrate bsd-port/hotspot and macosx-port/hotspot changes as of 2011.09.29. Reviewed-by: kvn, dholmes, never, phh Contributed-by: Christos Zoulas <christos@zoulas.com>, Greg Lewis <glewis@eyesbeyond.com>, Kurt Miller <kurt@intricatesoftware.com>, Alexander Strange <astrange@apple.com>, Mike Swingler <swingler@apple.com>, Roger Hoover <rhoover@apple.com>, Victor Hernandez <vhernandez@apple.com>, Pratik Solanki <psolanki@apple.com>
author dcubed
date Thu, 13 Oct 2011 09:35:42 -0700
parents
children 5a98bf7d847b
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 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
2 * Copyright (c) 2002, 2007, 2011, Oracle and/or its affiliates. All rights reserved.
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>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
34 #import <stdlib.h>
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
35
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
36 jboolean debug = JNI_FALSE;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
37
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
38 static jfieldID symbolicatorID = 0; // set in _init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
39 static jfieldID taskID = 0; // set in _init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
40
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
41 static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
42 (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
43 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
44
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
45 static id getSymbolicator(JNIEnv *env, jobject this_obj) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
46 jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
47 return (id)(intptr_t)ptr;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
48 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
49
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
50 static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
51 (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
52 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
53
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
54 static task_t getTask(JNIEnv *env, jobject this_obj) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
55 jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
56 return (task_t)ptr;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
57 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
58
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
59 #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
60 #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
61 #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
62 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
63
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
64 static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
65 (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
66 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
67
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
68 #if defined(__i386__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
69 #define hsdb_thread_state_t x86_thread_state32_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
70 #define hsdb_float_state_t x86_float_state32_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
71 #define HSDB_THREAD_STATE x86_THREAD_STATE32
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
72 #define HSDB_FLOAT_STATE x86_FLOAT_STATE32
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
73 #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
74 #define HSDB_FLOAT_STATE_COUNT x86_FLOAT_STATE32_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
75 #elif defined(__x86_64__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
76 #define hsdb_thread_state_t x86_thread_state64_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
77 #define hsdb_float_state_t x86_float_state64_t
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
78 #define HSDB_THREAD_STATE x86_THREAD_STATE64
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
79 #define HSDB_FLOAT_STATE x86_FLOAT_STATE64
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
80 #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
81 #define HSDB_FLOAT_STATE_COUNT x86_FLOAT_STATE64_COUNT
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
82 #else
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
83 #error "Unsupported architecture"
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
84 #endif
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
85
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
86 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
87 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
88 * Method: init0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
89 * Signature: ()V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
90 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
91 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
92 symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
93 taskID = (*env)->GetFieldID(env, cls, "task", "J");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
94 CHECK_EXCEPTION;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
95 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
96
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
97 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
98 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
99 * Method: lookupByName0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
100 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
101 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
102 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
103 jlong address = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
104
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
105 JNF_COCOA_ENTER(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
106 NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
107
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
108 if (debug) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
109 printf("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
110 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
111
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
112 id symbolicator = getSymbolicator(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
113 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
114 uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
115 address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
116 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
117
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
118 if (debug) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
119 printf("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
120 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
121 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
122
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
123 return address;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
124 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
125
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
126 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
127 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
128 * Method: readBytesFromProcess0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
129 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
130 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
131 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
132 if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
133
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
134 // must allocate storage instead of using former parameter buf
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
135 jboolean isCopy;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
136 jbyteArray array;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
137 jbyte *bufPtr;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
138
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
139 array = (*env)->NewByteArray(env, numBytes);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
140 CHECK_EXCEPTION_(0);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
141
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
142 unsigned long alignedAddress;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
143 unsigned long alignedLength;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
144 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
145 vm_offset_t *pages;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
146 int *mapped;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
147 long pageCount;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
148 uint byteCount;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
149 int i;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
150 unsigned long remaining;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
151
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
152 alignedAddress = trunc_page(addr);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
153 if (addr != alignedAddress) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
154 alignedLength += addr - alignedAddress;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
155 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
156 alignedLength = round_page(numBytes);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
157 pageCount = alignedLength/vm_page_size;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
158
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
159 // Allocate storage for pages and flags.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
160 pages = malloc(pageCount * sizeof(vm_offset_t));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
161 mapped = calloc(pageCount, sizeof(int));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
162
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
163 task_t gTask = getTask(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
164 // Try to read each of the pages.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
165 for (i = 0; i < pageCount; i++) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
166 result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
167 &pages[i], &byteCount);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
168 mapped[i] = (result == KERN_SUCCESS);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
169 // assume all failures are unmapped pages
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
170 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
171
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
172 if (debug) fprintf(stderr, "%ld pages\n", pageCount);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
173
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
174 remaining = numBytes;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
175
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
176 for (i = 0; i < pageCount; i++) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
177 unsigned long len = vm_page_size;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
178 unsigned long start = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
179
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
180 if (i == 0) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
181 start = addr - alignedAddress;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
182 len = vm_page_size - start;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
183 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
184
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
185 if (i == (pageCount - 1)) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
186 len = remaining;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
187 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
188
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
189 if (mapped[i]) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
190 if (debug) fprintf(stderr, "page %d mapped (len %ld start %ld)\n", i, len, start);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
191 (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
192 vm_deallocate(mach_task_self(), pages[i], vm_page_size);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
193 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
194
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
195 remaining -= len;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
196 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
197
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
198 free (pages);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
199 free (mapped);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
200 return array;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
201 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
202
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
203 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
204 * Class: sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
205 * Method: getThreadIntegerRegisterSet0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
206 * Signature: (I)[J
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
207 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
208 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(JNIEnv *env, jobject this_obj, jint lwp_id) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
209 if (debug)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
210 printf("getThreadRegisterSet0 called\n");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
211
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
212 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
213 thread_t tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
214 mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
215 hsdb_thread_state_t state;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
216 unsigned int *r;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
217 int i;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
218 jlongArray registerArray;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
219 jlong *primitiveArray;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
220
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
221 tid = lwp_id;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
222
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
223 result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
224
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
225 if (result != KERN_SUCCESS) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
226 if (debug)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
227 printf("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
228 return NULL;
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 // 40 32-bit registers on ppc, 16 on x86.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
232 // Output order is the same as the order in the ppc_thread_state/i386_thread_state struct.
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
233 #if defined(__i386__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
234 r = (unsigned int *)&state;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
235 registerArray = (*env)->NewLongArray(env, 8);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
236 primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
237 primitiveArray[0] = r[0]; // eax
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
238 primitiveArray[1] = r[2]; // ecx
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
239 primitiveArray[2] = r[3]; // edx
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
240 primitiveArray[3] = r[1]; // ebx
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
241 primitiveArray[4] = r[7]; // esp
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
242 primitiveArray[5] = r[6]; // ebp
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
243 primitiveArray[6] = r[5]; // esi
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
244 primitiveArray[7] = r[4]; // edi
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
245 (*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
246 #elif defined(__x86_64__)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
247 /* From AMD64ThreadContext.java
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
248 public static final int R15 = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
249 public static final int R14 = 1;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
250 public static final int R13 = 2;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
251 public static final int R12 = 3;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
252 public static final int R11 = 4;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
253 public static final int R10 = 5;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
254 public static final int R9 = 6;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
255 public static final int R8 = 7;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
256 public static final int RDI = 8;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
257 public static final int RSI = 9;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
258 public static final int RBP = 10;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
259 public static final int RBX = 11;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
260 public static final int RDX = 12;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
261 public static final int RCX = 13;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
262 public static final int RAX = 14;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
263 public static final int TRAPNO = 15;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
264 public static final int ERR = 16;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
265 public static final int RIP = 17;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
266 public static final int CS = 18;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
267 public static final int RFL = 19;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
268 public static final int RSP = 20;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
269 public static final int SS = 21;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
270 public static final int FS = 22;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
271 public static final int GS = 23;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
272 public static final int ES = 24;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
273 public static final int DS = 25;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
274 public static final int FSBASE = 26;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
275 public static final int GSBASE = 27;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
276 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
277 // 64 bit
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
278 if (debug) printf("Getting threads for a 64-bit process\n");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
279 registerArray = (*env)->NewLongArray(env, 28);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
280 primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
281
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
282 primitiveArray[0] = state.__r15;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
283 primitiveArray[1] = state.__r14;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
284 primitiveArray[2] = state.__r13;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
285 primitiveArray[3] = state.__r12;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
286 primitiveArray[4] = state.__r11;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
287 primitiveArray[5] = state.__r10;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
288 primitiveArray[6] = state.__r9;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
289 primitiveArray[7] = state.__r8;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
290 primitiveArray[8] = state.__rdi;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
291 primitiveArray[9] = state.__rsi;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
292 primitiveArray[10] = state.__rbp;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
293 primitiveArray[11] = state.__rbx;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
294 primitiveArray[12] = state.__rdx;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
295 primitiveArray[13] = state.__rcx;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
296 primitiveArray[14] = state.__rax;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
297 primitiveArray[15] = 0; // trapno ?
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
298 primitiveArray[16] = 0; // err ?
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
299 primitiveArray[17] = state.__rip;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
300 primitiveArray[18] = state.__cs;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
301 primitiveArray[19] = state.__rflags;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
302 primitiveArray[20] = state.__rsp;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
303 primitiveArray[21] = 0; // We don't have SS
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
304 primitiveArray[22] = state.__fs;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
305 primitiveArray[23] = state.__gs;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
306 primitiveArray[24] = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
307 primitiveArray[25] = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
308 primitiveArray[26] = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
309 primitiveArray[27] = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
310
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
311 if (debug) printf("set registers\n");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
312
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
313 (*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
314 #else
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
315 #error Unsupported architecture
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
316 #endif
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
317
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
318 return registerArray;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
319 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
320
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
321 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
322 * Class: sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
323 * Method: translateTID0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
324 * Signature: (I)I
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
325 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
326 JNIEXPORT jint JNICALL
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
327 Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(JNIEnv *env, jobject this_obj, jint tid) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
328 if (debug)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
329 printf("translateTID0 called on tid = 0x%x\n", (int)tid);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
330
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
331 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
332 thread_t foreign_tid, usable_tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
333 mach_msg_type_name_t type;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
334
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
335 foreign_tid = tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
336
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
337 task_t gTask = getTask(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
338 result = mach_port_extract_right(gTask, foreign_tid,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
339 MACH_MSG_TYPE_COPY_SEND,
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
340 &usable_tid, &type);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
341 if (result != KERN_SUCCESS)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
342 return -1;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
343
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
344 if (debug)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
345 printf("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
346
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
347 return (jint) usable_tid;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
348 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
349
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
350 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
351 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
352 * Method: attach0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
353 * Signature: (I)V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
354 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
355 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(JNIEnv *env, jobject this_obj, jint jpid) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
356 JNF_COCOA_ENTER(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
357 if (getenv("JAVA_SAPROC_DEBUG") != NULL)
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
358 debug = JNI_TRUE;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
359 else
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
360 debug = JNI_FALSE;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
361 if (debug) printf("attach0 called for jpid=%d\n", (int)jpid);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
362
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
363 kern_return_t result;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
364 task_t gTask = 0;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
365 result = task_for_pid(mach_task_self(), jpid, &gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
366 if (result != KERN_SUCCESS) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
367 fprintf(stderr, "attach: task_for_pid(%d) failed (%d)\n", (int)jpid, result);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
368 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
369 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
370 putTask(env, this_obj, gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
371
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
372 id symbolicator = nil;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
373 id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
374 if (jrsSymbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
375 id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
376 symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
377 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
378 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
379 CFRetain(symbolicator); // pin symbolicator while in java heap
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
380 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
381
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
382 putSymbolicator(env, this_obj, symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
383 if (symbolicator == nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
384 THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
385 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
386
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
387 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
388 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
389
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
390 /*
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
391 * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
392 * Method: detach0
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
393 * Signature: ()V
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
394 */
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
395 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(JNIEnv *env, jobject this_obj) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
396 JNF_COCOA_ENTER(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
397 if (debug) printf("detach0 called\n");
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
398
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
399 task_t gTask = getTask(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
400 mach_port_deallocate(mach_task_self(), gTask);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
401 id symbolicator = getSymbolicator(env, this_obj);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
402 if (symbolicator != nil) {
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
403 CFRelease(symbolicator);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
404 }
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
405 JNF_COCOA_EXIT(env);
436b4a3231bf 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
406 }