hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m
author dcubed
Thu, 13 Oct 2011 09:35:42 -0700
changeset 10739 91935236600e
child 13873 7b72e3873785
permissions -rw-r--r--
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>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     1
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     2
 * Copyright (c) 2002, 2007, 2011, Oracle and/or its affiliates. All rights reserved.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     4
 *
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     7
 * published by the Free Software Foundation.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     8
 *
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    13
 * accompanied this code).
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    14
 *
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    18
 *
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    21
 * questions.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    22
 *
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    23
 */
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    24
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    25
#include <objc/objc-runtime.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    26
#import <Foundation/Foundation.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    27
#import <JavaNativeFoundation/JavaNativeFoundation.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    28
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    29
#include <JavaVM/jni.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    30
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    31
#import <mach/mach.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    32
#import <mach/mach_types.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    33
#import <sys/sysctl.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    34
#import <stdlib.h>
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    35
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    36
jboolean debug = JNI_FALSE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    37
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    38
static jfieldID symbolicatorID = 0; // set in _init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    39
static jfieldID taskID = 0; // set in _init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    40
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    41
static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    42
  (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    43
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    44
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    45
static id getSymbolicator(JNIEnv *env, jobject this_obj) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    46
  jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    47
  return (id)(intptr_t)ptr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    48
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    49
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    50
static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    51
  (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    52
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    53
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    54
static task_t getTask(JNIEnv *env, jobject this_obj) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    55
  jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    56
  return (task_t)ptr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    57
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    58
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    59
#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    60
#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
91935236600e 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; }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    62
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    63
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    64
static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    65
  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    66
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    67
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    68
#if defined(__i386__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    69
    #define hsdb_thread_state_t     x86_thread_state32_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    70
    #define hsdb_float_state_t      x86_float_state32_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    71
    #define HSDB_THREAD_STATE       x86_THREAD_STATE32
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    72
    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE32
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    73
    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    74
    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE32_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    75
#elif defined(__x86_64__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    76
    #define hsdb_thread_state_t     x86_thread_state64_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    77
    #define hsdb_float_state_t      x86_float_state64_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    78
    #define HSDB_THREAD_STATE       x86_THREAD_STATE64
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    79
    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE64
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    80
    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    81
    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE64_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    82
#else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    83
    #error "Unsupported architecture"
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    84
#endif
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    85
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    86
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    87
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    88
 * Method:    init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    89
 * Signature: ()V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    90
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    92
  symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    93
  taskID = (*env)->GetFieldID(env, cls, "task", "J");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    94
  CHECK_EXCEPTION;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    95
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    96
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    97
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    98
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    99
 * Method:    lookupByName0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   100
 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   101
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   103
  jlong address = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   104
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   105
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   106
  NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   107
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   108
  if (debug) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   109
    printf("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   110
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   111
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   112
  id symbolicator = getSymbolicator(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   113
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   114
    uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   115
    address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   116
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   117
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   118
  if (debug) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   119
    printf("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   120
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   121
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   122
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   123
  return address;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   124
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   125
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   126
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   127
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   128
 * Method:    readBytesFromProcess0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   129
 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   130
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   132
  if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   133
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   134
  // must allocate storage instead of using former parameter buf
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   135
  jboolean isCopy;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   136
  jbyteArray array;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   137
  jbyte *bufPtr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   138
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   139
  array = (*env)->NewByteArray(env, numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   140
  CHECK_EXCEPTION_(0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   141
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   142
  unsigned long alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   143
  unsigned long alignedLength;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   144
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   145
  vm_offset_t *pages;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   146
  int *mapped;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   147
  long pageCount;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   148
  uint byteCount;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   149
  int i;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   150
  unsigned long remaining;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   151
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   152
  alignedAddress = trunc_page(addr);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   153
  if (addr != alignedAddress) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   154
    alignedLength += addr - alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   155
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   156
  alignedLength = round_page(numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   157
  pageCount = alignedLength/vm_page_size;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   158
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   159
  // Allocate storage for pages and flags.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   160
  pages = malloc(pageCount * sizeof(vm_offset_t));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   161
  mapped = calloc(pageCount, sizeof(int));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   162
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   163
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   164
  // Try to read each of the pages.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   165
  for (i = 0; i < pageCount; i++) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   166
    result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   167
		     &pages[i], &byteCount);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   168
    mapped[i] = (result == KERN_SUCCESS); 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   169
    // assume all failures are unmapped pages
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   170
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   171
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   172
  if (debug) fprintf(stderr, "%ld pages\n", pageCount);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   173
	
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   174
  remaining = numBytes;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   175
	
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   176
  for (i = 0; i < pageCount; i++) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   177
    unsigned long len = vm_page_size;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   178
    unsigned long start = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   179
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   180
    if (i == 0) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   181
      start = addr - alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   182
      len = vm_page_size - start;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   183
    }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   184
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   185
    if (i == (pageCount - 1)) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   186
      len = remaining;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   187
    }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   188
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   189
    if (mapped[i]) {
91935236600e 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);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   191
      (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   192
      vm_deallocate(mach_task_self(), pages[i], vm_page_size);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   193
    }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   194
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   195
    remaining -= len;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   196
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   197
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   198
  free (pages);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   199
  free (mapped);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   200
  return array;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   201
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   202
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   203
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   204
 * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   205
 * Method:    getThreadIntegerRegisterSet0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   206
 * Signature: (I)[J
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   207
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   209
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   210
    printf("getThreadRegisterSet0 called\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   211
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   212
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   213
  thread_t tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   214
  mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   215
  hsdb_thread_state_t state;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   216
  unsigned int *r;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   217
  int i;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   218
  jlongArray registerArray;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   219
  jlong *primitiveArray;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   220
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   221
  tid = lwp_id;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   222
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   223
  result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   224
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   225
  if (result != KERN_SUCCESS) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   226
    if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   227
      printf("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   228
    return NULL;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   229
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   230
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   231
  // 40 32-bit registers on ppc, 16 on x86. 
91935236600e 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.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   233
#if defined(__i386__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   234
	r = (unsigned int *)&state;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   235
	registerArray = (*env)->NewLongArray(env, 8);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   236
	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   237
	primitiveArray[0] = r[0];  // eax
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   238
	primitiveArray[1] = r[2];  // ecx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   239
	primitiveArray[2] = r[3];  // edx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   240
	primitiveArray[3] = r[1];  // ebx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   241
	primitiveArray[4] = r[7];  // esp
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   242
	primitiveArray[5] = r[6];  // ebp
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   243
	primitiveArray[6] = r[5];  // esi
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   244
	primitiveArray[7] = r[4];  // edi
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   245
	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   246
#elif defined(__x86_64__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   247
	/* From AMD64ThreadContext.java
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   248
	   public static final int R15 = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   249
	   public static final int R14 = 1;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   250
	   public static final int R13 = 2;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   251
	   public static final int R12 = 3;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   252
	   public static final int R11 = 4;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   253
	   public static final int R10 = 5;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   254
	   public static final int R9  = 6;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   255
	   public static final int R8  = 7;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   256
	   public static final int RDI = 8;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   257
	   public static final int RSI = 9;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   258
	   public static final int RBP = 10;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   259
	   public static final int RBX = 11;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   260
	   public static final int RDX = 12;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   261
	   public static final int RCX = 13;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   262
	   public static final int RAX = 14;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   263
	   public static final int TRAPNO = 15;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   264
	   public static final int ERR = 16;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   265
	   public static final int RIP = 17;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   266
	   public static final int CS = 18;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   267
	   public static final int RFL = 19;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   268
	   public static final int RSP = 20;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   269
	   public static final int SS = 21;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   270
	   public static final int FS = 22;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   271
	   public static final int GS = 23;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   272
	   public static final int ES = 24;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   273
	   public static final int DS = 25;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   274
	   public static final int FSBASE = 26;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   275
	   public static final int GSBASE = 27;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   276
	 */
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   277
	// 64 bit
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   278
	if (debug) printf("Getting threads for a 64-bit process\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   279
	registerArray = (*env)->NewLongArray(env, 28);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   280
	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   281
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   282
	primitiveArray[0] = state.__r15;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   283
	primitiveArray[1] = state.__r14;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   284
	primitiveArray[2] = state.__r13;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   285
	primitiveArray[3] = state.__r12;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   286
	primitiveArray[4] = state.__r11;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   287
	primitiveArray[5] = state.__r10;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   288
	primitiveArray[6] = state.__r9;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   289
	primitiveArray[7] = state.__r8;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   290
	primitiveArray[8] = state.__rdi;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   291
	primitiveArray[9] = state.__rsi;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   292
	primitiveArray[10] = state.__rbp;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   293
	primitiveArray[11] = state.__rbx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   294
	primitiveArray[12] = state.__rdx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   295
	primitiveArray[13] = state.__rcx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   296
	primitiveArray[14] = state.__rax;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   297
	primitiveArray[15] = 0;             // trapno ?
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   298
	primitiveArray[16] = 0;             // err ?
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   299
	primitiveArray[17] = state.__rip;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   300
	primitiveArray[18] = state.__cs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   301
	primitiveArray[19] = state.__rflags;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   302
	primitiveArray[20] = state.__rsp;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   303
	primitiveArray[21] = 0;            // We don't have SS
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   304
	primitiveArray[22] = state.__fs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   305
	primitiveArray[23] = state.__gs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   306
	primitiveArray[24] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   307
	primitiveArray[25] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   308
	primitiveArray[26] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   309
	primitiveArray[27] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   310
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   311
	if (debug) printf("set registers\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   312
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   313
	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   314
#else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   315
#error Unsupported architecture
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   316
#endif
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   317
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   318
  return registerArray;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   319
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   320
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   321
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   322
 * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   323
 * Method:    translateTID0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   324
 * Signature: (I)I
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   325
 */
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   326
JNIEXPORT jint JNICALL
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   328
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   329
    printf("translateTID0 called on tid = 0x%x\n", (int)tid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   330
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   331
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   332
  thread_t foreign_tid, usable_tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   333
  mach_msg_type_name_t type;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   334
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   335
  foreign_tid = tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   336
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   337
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   338
  result = mach_port_extract_right(gTask, foreign_tid, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   339
				   MACH_MSG_TYPE_COPY_SEND, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   340
				   &usable_tid, &type);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   341
  if (result != KERN_SUCCESS)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   342
    return -1;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   343
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   344
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   345
    printf("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   346
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   347
  return (jint) usable_tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   348
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   349
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   350
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   351
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   352
 * Method:    attach0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   353
 * Signature: (I)V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   354
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   356
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   357
  if (getenv("JAVA_SAPROC_DEBUG") != NULL)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   358
    debug = JNI_TRUE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   359
  else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   360
    debug = JNI_FALSE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   361
  if (debug) printf("attach0 called for jpid=%d\n", (int)jpid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   362
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   363
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   364
  task_t gTask = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   365
  result = task_for_pid(mach_task_self(), jpid, &gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   366
  if (result != KERN_SUCCESS) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   367
    fprintf(stderr, "attach: task_for_pid(%d) failed (%d)\n", (int)jpid, result);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   368
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   369
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   370
  putTask(env, this_obj, gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   371
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   372
  id symbolicator = nil;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   373
  id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   374
  if (jrsSymbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   375
    id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   376
    symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   377
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   378
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   379
    CFRetain(symbolicator); // pin symbolicator while in java heap
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   380
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   381
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   382
  putSymbolicator(env, this_obj, symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   383
  if (symbolicator == nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   384
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   385
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   386
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   387
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   388
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   389
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   390
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   391
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   392
 * Method:    detach0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   393
 * Signature: ()V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   394
 */
91935236600e 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) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   396
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   397
  if (debug) printf("detach0 called\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   398
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   399
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   400
  mach_port_deallocate(mach_task_self(), gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   401
  id symbolicator = getSymbolicator(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   402
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   403
    CFRelease(symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   404
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   405
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   406
}