hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m
author sla
Fri, 08 Feb 2013 12:48:24 +0100
changeset 15593 860cf6c70c06
parent 13873 7b72e3873785
child 15738 fb4662f9df5b
permissions -rw-r--r--
8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67) Summary: Do not rely on mach thread port names to identify threads from SA Reviewed-by: dholmes, minqi, rbackman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
     1
/*
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
     2
 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
10739
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>
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    34
#import <stdio.h>
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    35
#import <stdarg.h>
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    36
#import <stdlib.h>
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    37
#import <strings.h>
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    38
#import <dlfcn.h>
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    39
#import <limits.h>
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    40
#import <errno.h>
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    41
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    42
jboolean debug = JNI_FALSE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    43
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    44
static jfieldID symbolicatorID = 0; // set in _init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    45
static jfieldID taskID = 0; // set in _init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    46
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    47
static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    48
  (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    49
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    50
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    51
static id getSymbolicator(JNIEnv *env, jobject this_obj) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    52
  jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    53
  return (id)(intptr_t)ptr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    54
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    55
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    56
static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    57
  (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    58
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    59
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    60
static task_t getTask(JNIEnv *env, jobject this_obj) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    61
  jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    62
  return (task_t)ptr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    63
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    64
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    65
#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    66
#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    67
#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
    68
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    69
#define CHECK_EXCEPTION_CLEAR if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); } 
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    70
#define CHECK_EXCEPTION_CLEAR_VOID if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return; } 
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
    71
#define CHECK_EXCEPTION_CLEAR_(value) if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return value; } 
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    72
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    73
static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    74
  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    75
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    76
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    77
#if defined(__i386__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    78
    #define hsdb_thread_state_t     x86_thread_state32_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    79
    #define hsdb_float_state_t      x86_float_state32_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    80
    #define HSDB_THREAD_STATE       x86_THREAD_STATE32
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    81
    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE32
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    82
    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    83
    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE32_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    84
#elif defined(__x86_64__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    85
    #define hsdb_thread_state_t     x86_thread_state64_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    86
    #define hsdb_float_state_t      x86_float_state64_t
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    87
    #define HSDB_THREAD_STATE       x86_THREAD_STATE64
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    88
    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE64
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    89
    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    90
    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE64_COUNT
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    91
#else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    92
    #error "Unsupported architecture"
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    93
#endif
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    94
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    95
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    96
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    97
 * Method:    init0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    98
 * Signature: ()V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
    99
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   100
JNIEXPORT void JNICALL 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   101
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   102
  symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   103
  taskID = (*env)->GetFieldID(env, cls, "task", "J");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   104
  CHECK_EXCEPTION;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   105
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   106
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   107
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   108
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   109
 * Method:    lookupByName0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   110
 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   111
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   112
JNIEXPORT jlong JNICALL 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   113
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   114
  JNIEnv *env, jobject this_obj, 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   115
  jstring objectName, jstring symbolName) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   116
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   117
  jlong address = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   118
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   119
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   120
  NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   121
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   122
  if (debug) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   123
    printf("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
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
  id symbolicator = getSymbolicator(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   127
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   128
    uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   129
    address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   130
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   131
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   132
  if (debug) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   133
    printf("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   134
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   135
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   136
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   137
  return address;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   138
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   139
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   140
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   141
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   142
 * Method:    readBytesFromProcess0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   143
 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   144
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   145
JNIEXPORT jbyteArray JNICALL
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   146
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   147
  JNIEnv *env, jobject this_obj, 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   148
  jlong addr, jlong numBytes) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   149
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   150
  if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   151
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   152
  // must allocate storage instead of using former parameter buf
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   153
  jboolean isCopy;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   154
  jbyteArray array;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   155
  jbyte *bufPtr;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   156
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   157
  array = (*env)->NewByteArray(env, numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   158
  CHECK_EXCEPTION_(0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   159
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   160
  unsigned long alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   161
  unsigned long alignedLength;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   162
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   163
  vm_offset_t *pages;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   164
  int *mapped;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   165
  long pageCount;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   166
  uint byteCount;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   167
  int i;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   168
  unsigned long remaining;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   169
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   170
  alignedAddress = trunc_page(addr);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   171
  if (addr != alignedAddress) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   172
    alignedLength += addr - alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   173
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   174
  alignedLength = round_page(numBytes);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   175
  pageCount = alignedLength/vm_page_size;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   176
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   177
  // Allocate storage for pages and flags.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   178
  pages = malloc(pageCount * sizeof(vm_offset_t));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   179
  mapped = calloc(pageCount, sizeof(int));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   180
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   181
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   182
  // Try to read each of the pages.
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   183
  for (i = 0; i < pageCount; i++) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   184
    result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   185
		     &pages[i], &byteCount);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   186
    mapped[i] = (result == KERN_SUCCESS); 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   187
    // assume all failures are unmapped pages
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   188
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   189
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   190
  if (debug) fprintf(stderr, "%ld pages\n", pageCount);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   191
	
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   192
  remaining = numBytes;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   193
	
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   194
  for (i = 0; i < pageCount; i++) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   195
    unsigned long len = vm_page_size;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   196
    unsigned long start = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   197
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   198
    if (i == 0) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   199
      start = addr - alignedAddress;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   200
      len = vm_page_size - start;
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
    if (i == (pageCount - 1)) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   204
      len = remaining;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   205
    }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   206
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   207
    if (mapped[i]) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   208
      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
   209
      (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   210
      vm_deallocate(mach_task_self(), pages[i], vm_page_size);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   211
    }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   212
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   213
    remaining -= len;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   214
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   215
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   216
  free (pages);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   217
  free (mapped);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   218
  return array;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   219
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   220
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   221
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   222
/*
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   223
 * Lookup the thread_t that corresponds to the given thread_id.
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   224
 * The thread_id should be the result from calling thread_info() with THREAD_IDENTIFIER_INFO
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   225
 * and reading the m_ident_info.thread_id returned.
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   226
 * The returned thread_t is the mach send right to the kernel port for the corresponding thread.
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   227
 *
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   228
 * We cannot simply use the OSThread._thread_id field in the JVM. This is set to ::mach_thread_self()
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   229
 * in the VM, but that thread port is not valid for a remote debugger to access the thread.
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   230
 */
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   231
thread_t
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   232
lookupThreadFromThreadId(task_t task, jlong thread_id) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   233
  if (debug) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   234
    printf("lookupThreadFromThreadId thread_id=0x%llx\n", thread_id);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   235
  }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   236
  
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   237
  thread_array_t thread_list = NULL;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   238
  mach_msg_type_number_t thread_list_count = 0;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   239
  thread_t result_thread = 0;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   240
  int i;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   241
  
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   242
  // get the list of all the send rights
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   243
  kern_return_t result = task_threads(task, &thread_list, &thread_list_count);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   244
  if (result != KERN_SUCCESS) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   245
    if (debug) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   246
      printf("task_threads returned 0x%x\n", result);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   247
    }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   248
    return 0;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   249
  }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   250
  
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   251
  for(i = 0 ; i < thread_list_count; i++) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   252
    thread_identifier_info_data_t m_ident_info;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   253
    mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   254
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   255
    // get the THREAD_IDENTIFIER_INFO for the send right
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   256
    result = thread_info(thread_list[i], THREAD_IDENTIFIER_INFO, (thread_info_t) &m_ident_info, &count);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   257
    if (result != KERN_SUCCESS) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   258
      if (debug) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   259
        printf("thread_info returned 0x%x\n", result);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   260
      }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   261
      break;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   262
    }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   263
    
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   264
    // if this is the one we're looking for, return the send right
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   265
    if (thread_id == m_ident_info.thread_id)
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   266
    {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   267
      result_thread = thread_list[i];
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   268
      break;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   269
    }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   270
  }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   271
  
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   272
  vm_size_t thread_list_size = (vm_size_t) (thread_list_count * sizeof (thread_t));
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   273
  vm_deallocate(mach_task_self(), (vm_address_t) thread_list, thread_list_count);
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   274
  
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   275
  return result_thread;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   276
}
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   277
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   278
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   279
/*
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   280
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   281
 * Method:    getThreadIntegerRegisterSet0
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   282
 * Signature: (J)[J
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   283
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   284
JNIEXPORT jlongArray JNICALL 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   285
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   286
  JNIEnv *env, jobject this_obj, 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   287
  jlong thread_id) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   288
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   289
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   290
    printf("getThreadRegisterSet0 called\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   291
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   292
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   293
  thread_t tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   294
  mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   295
  hsdb_thread_state_t state;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   296
  unsigned int *r;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   297
  int i;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   298
  jlongArray registerArray;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   299
  jlong *primitiveArray;
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   300
  task_t gTask = getTask(env, this_obj);
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   301
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   302
  tid = lookupThreadFromThreadId(gTask, thread_id);
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   303
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   304
  result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   305
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   306
  if (result != KERN_SUCCESS) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   307
    if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   308
      printf("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   309
    return NULL;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   310
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   311
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   312
  // 40 32-bit registers on ppc, 16 on x86. 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   313
  // 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
   314
#if defined(__i386__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   315
	r = (unsigned int *)&state;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   316
	registerArray = (*env)->NewLongArray(env, 8);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   317
	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   318
	primitiveArray[0] = r[0];  // eax
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   319
	primitiveArray[1] = r[2];  // ecx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   320
	primitiveArray[2] = r[3];  // edx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   321
	primitiveArray[3] = r[1];  // ebx
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   322
	primitiveArray[4] = r[7];  // esp
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   323
	primitiveArray[5] = r[6];  // ebp
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   324
	primitiveArray[6] = r[5];  // esi
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   325
	primitiveArray[7] = r[4];  // edi
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   326
	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   327
#elif defined(__x86_64__)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   328
	/* From AMD64ThreadContext.java
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   329
	   public static final int R15 = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   330
	   public static final int R14 = 1;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   331
	   public static final int R13 = 2;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   332
	   public static final int R12 = 3;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   333
	   public static final int R11 = 4;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   334
	   public static final int R10 = 5;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   335
	   public static final int R9  = 6;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   336
	   public static final int R8  = 7;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   337
	   public static final int RDI = 8;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   338
	   public static final int RSI = 9;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   339
	   public static final int RBP = 10;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   340
	   public static final int RBX = 11;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   341
	   public static final int RDX = 12;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   342
	   public static final int RCX = 13;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   343
	   public static final int RAX = 14;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   344
	   public static final int TRAPNO = 15;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   345
	   public static final int ERR = 16;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   346
	   public static final int RIP = 17;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   347
	   public static final int CS = 18;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   348
	   public static final int RFL = 19;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   349
	   public static final int RSP = 20;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   350
	   public static final int SS = 21;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   351
	   public static final int FS = 22;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   352
	   public static final int GS = 23;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   353
	   public static final int ES = 24;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   354
	   public static final int DS = 25;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   355
	   public static final int FSBASE = 26;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   356
	   public static final int GSBASE = 27;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   357
	 */
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   358
	// 64 bit
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   359
	if (debug) printf("Getting threads for a 64-bit process\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   360
	registerArray = (*env)->NewLongArray(env, 28);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   361
	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   362
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   363
	primitiveArray[0] = state.__r15;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   364
	primitiveArray[1] = state.__r14;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   365
	primitiveArray[2] = state.__r13;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   366
	primitiveArray[3] = state.__r12;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   367
	primitiveArray[4] = state.__r11;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   368
	primitiveArray[5] = state.__r10;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   369
	primitiveArray[6] = state.__r9;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   370
	primitiveArray[7] = state.__r8;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   371
	primitiveArray[8] = state.__rdi;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   372
	primitiveArray[9] = state.__rsi;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   373
	primitiveArray[10] = state.__rbp;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   374
	primitiveArray[11] = state.__rbx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   375
	primitiveArray[12] = state.__rdx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   376
	primitiveArray[13] = state.__rcx;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   377
	primitiveArray[14] = state.__rax;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   378
	primitiveArray[15] = 0;             // trapno ?
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   379
	primitiveArray[16] = 0;             // err ?
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   380
	primitiveArray[17] = state.__rip;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   381
	primitiveArray[18] = state.__cs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   382
	primitiveArray[19] = state.__rflags;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   383
	primitiveArray[20] = state.__rsp;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   384
	primitiveArray[21] = 0;            // We don't have SS
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   385
	primitiveArray[22] = state.__fs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   386
	primitiveArray[23] = state.__gs;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   387
	primitiveArray[24] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   388
	primitiveArray[25] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   389
	primitiveArray[26] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   390
	primitiveArray[27] = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   391
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   392
	if (debug) printf("set registers\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   393
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   394
	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   395
#else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   396
#error Unsupported architecture
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   397
#endif
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   398
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   399
  return registerArray;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   400
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   401
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   402
/*
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   403
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   404
 * Method:    translateTID0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   405
 * Signature: (I)I
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   406
 */
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   407
JNIEXPORT jint JNICALL
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   408
Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   409
  JNIEnv *env, jobject this_obj, jint tid) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   410
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   411
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   412
    printf("translateTID0 called on tid = 0x%x\n", (int)tid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   413
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   414
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   415
  thread_t foreign_tid, usable_tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   416
  mach_msg_type_name_t type;
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   417
  
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   418
  foreign_tid = tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   419
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   420
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   421
  result = mach_port_extract_right(gTask, foreign_tid, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   422
				   MACH_MSG_TYPE_COPY_SEND, 
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   423
				   &usable_tid, &type);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   424
  if (result != KERN_SUCCESS)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   425
    return -1;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   426
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   427
  if (debug)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   428
    printf("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   429
    
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   430
  return (jint) usable_tid;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   431
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   432
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   433
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   434
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   435
 * Method:    attach0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   436
 * Signature: (I)V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   437
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   438
JNIEXPORT void JNICALL 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   439
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   440
  JNIEnv *env, jobject this_obj, jint jpid) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   441
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   442
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   443
  if (getenv("JAVA_SAPROC_DEBUG") != NULL)
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   444
    debug = JNI_TRUE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   445
  else
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   446
    debug = JNI_FALSE;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   447
  if (debug) printf("attach0 called for jpid=%d\n", (int)jpid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   448
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   449
  kern_return_t result;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   450
  task_t gTask = 0;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   451
  result = task_for_pid(mach_task_self(), jpid, &gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   452
  if (result != KERN_SUCCESS) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   453
    fprintf(stderr, "attach: task_for_pid(%d) failed (%d)\n", (int)jpid, result);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   454
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   455
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   456
  putTask(env, this_obj, gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   457
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   458
  id symbolicator = nil;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   459
  id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   460
  if (jrsSymbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   461
    id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   462
    symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   463
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   464
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   465
    CFRetain(symbolicator); // pin symbolicator while in java heap
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   466
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   467
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   468
  putSymbolicator(env, this_obj, symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   469
  if (symbolicator == nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   470
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   471
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   472
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   473
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   474
}
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   475
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   476
/*
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   477
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   478
 * Method:    detach0
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   479
 * Signature: ()V
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   480
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   481
JNIEXPORT void JNICALL 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   482
Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   483
  JNIEnv *env, jobject this_obj) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   484
{
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   485
JNF_COCOA_ENTER(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   486
  if (debug) printf("detach0 called\n");
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   487
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   488
  task_t gTask = getTask(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   489
  mach_port_deallocate(mach_task_self(), gTask);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   490
  id symbolicator = getSymbolicator(env, this_obj);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   491
  if (symbolicator != nil) {
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   492
    CFRelease(symbolicator);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   493
  }
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   494
JNF_COCOA_EXIT(env);
91935236600e 7098194: integrate macosx-port changes
dcubed
parents:
diff changeset
   495
}
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   496
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   497
/*
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   498
 * Class:     sun_jvm_hotspot_asm_Disassembler
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   499
 * Method:    load_library
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   500
 * Signature: (Ljava/lang/String;)L
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   501
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   502
JNIEXPORT jlong JNICALL
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   503
Java_sun_jvm_hotspot_asm_Disassembler_load_1library(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   504
  JNIEnv * env, 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   505
  jclass disclass,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   506
  jstring jrepath_s,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   507
  jstring libname_s) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   508
{
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   509
  uintptr_t func = 0;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   510
  const char* error_message = NULL;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   511
  const char* java_home;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   512
  jboolean isCopy;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   513
  uintptr_t *handle = NULL;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   514
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   515
  const char * jrepath = (*env)->GetStringUTFChars(env, jrepath_s, &isCopy); // like $JAVA_HOME/jre/lib/sparc/
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   516
  const char * libname = (*env)->GetStringUTFChars(env, libname_s, &isCopy);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   517
  char buffer[128];
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   518
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   519
  /* Load the hsdis library */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   520
  void* hsdis_handle;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   521
  hsdis_handle = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   522
  if (hsdis_handle == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   523
    snprintf(buffer, sizeof(buffer), "%s%s", jrepath, libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   524
    hsdis_handle = dlopen(buffer, RTLD_LAZY | RTLD_GLOBAL);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   525
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   526
  if (hsdis_handle != NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   527
    func = (uintptr_t)dlsym(hsdis_handle, "decode_instructions_virtual");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   528
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   529
  if (func == 0) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   530
    error_message = dlerror();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   531
    fprintf(stderr, "%s\n", error_message);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   532
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   533
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   534
  (*env)->ReleaseStringUTFChars(env, libname_s, libname);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   535
  (*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   536
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   537
  if (func == 0) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   538
    /* Couldn't find entry point.  error_message should contain some
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   539
     * platform dependent error message.
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   540
     */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   541
    THROW_NEW_DEBUGGER_EXCEPTION(error_message);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   542
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   543
  return (jlong)func;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   544
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   545
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   546
/* signature of decode_instructions_virtual from hsdis.h */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   547
typedef void* (*decode_func)(uintptr_t start_va, uintptr_t end_va,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   548
                             unsigned char* start, uintptr_t length,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   549
                             void* (*event_callback)(void*, const char*, void*),
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   550
                             void* event_stream,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   551
                             int (*printf_callback)(void*, const char*, ...),
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   552
                             void* printf_stream,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   553
                             const char* options);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   554
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   555
/* container for call back state when decoding instructions */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   556
typedef struct {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   557
  JNIEnv* env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   558
  jobject dis;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   559
  jobject visitor;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   560
  jmethodID handle_event;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   561
  jmethodID raw_print;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   562
  char buffer[4096];
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   563
} decode_env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   564
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   565
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   566
/* event callback binding to Disassembler.handleEvent */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   567
static void* event_to_env(void* env_pv, const char* event, void* arg) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   568
  decode_env* denv = (decode_env*)env_pv;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   569
  JNIEnv* env = denv->env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   570
  jstring event_string = (*env)->NewStringUTF(env, event);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   571
  jlong result = (*env)->CallLongMethod(env, denv->dis, denv->handle_event, denv->visitor,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   572
                                        event_string, (jlong) (uintptr_t)arg);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   573
  /* ignore exceptions for now */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   574
  CHECK_EXCEPTION_CLEAR_((void *)0);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   575
  return (void*)(uintptr_t)result;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   576
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   577
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   578
/* printing callback binding to Disassembler.rawPrint */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   579
static int printf_to_env(void* env_pv, const char* format, ...) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   580
  jstring output;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   581
  va_list ap;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   582
  int cnt;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   583
  decode_env* denv = (decode_env*)env_pv;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   584
  JNIEnv* env = denv->env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   585
  size_t flen = strlen(format);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   586
  const char* raw = NULL;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   587
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   588
  if (flen == 0)  return 0;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   589
  if (flen < 2 ||
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   590
      strchr(format, '%') == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   591
    raw = format;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   592
  } else if (format[0] == '%' && format[1] == '%' &&
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   593
             strchr(format+2, '%') == NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   594
    // happens a lot on machines with names like %foo
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   595
    flen--;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   596
    raw = format+1;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   597
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   598
  if (raw != NULL) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   599
    jstring output = (*env)->NewStringUTF(env, raw);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   600
    (*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   601
    CHECK_EXCEPTION_CLEAR;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   602
    return (int) flen;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   603
  }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   604
  va_start(ap, format);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   605
  cnt = vsnprintf(denv->buffer, sizeof(denv->buffer), format, ap);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   606
  va_end(ap);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   607
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   608
  output = (*env)->NewStringUTF(env, denv->buffer);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   609
  (*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   610
  CHECK_EXCEPTION_CLEAR;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   611
  return cnt;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   612
}
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   613
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   614
/*
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   615
 * Class:     sun_jvm_hotspot_asm_Disassembler
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   616
 * Method:    decode
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   617
 * Signature: (Lsun/jvm/hotspot/asm/InstructionVisitor;J[BLjava/lang/String;J)V
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   618
 */
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   619
JNIEXPORT void JNICALL
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   620
Java_sun_jvm_hotspot_asm_Disassembler_decode(
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   621
   JNIEnv * env,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   622
   jobject dis,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   623
   jobject visitor,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   624
   jlong startPc,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   625
   jbyteArray code,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   626
   jstring options_s,
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   627
   jlong decode_instructions_virtual) 
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 13873
diff changeset
   628
{
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   629
  jboolean isCopy;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   630
  jbyte* start = (*env)->GetByteArrayElements(env, code, &isCopy);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   631
  jbyte* end = start + (*env)->GetArrayLength(env, code);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   632
  const char * options = (*env)->GetStringUTFChars(env, options_s, &isCopy);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   633
  jclass disclass = (*env)->GetObjectClass(env, dis);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   634
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   635
  decode_env denv;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   636
  denv.env = env;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   637
  denv.dis = dis;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   638
  denv.visitor = visitor;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   639
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   640
  /* find Disassembler.handleEvent callback */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   641
  denv.handle_event = (*env)->GetMethodID(env, disclass, "handleEvent",
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   642
                                          "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;J)J");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   643
  CHECK_EXCEPTION_CLEAR_VOID
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   644
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   645
  /* find Disassembler.rawPrint callback */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   646
  denv.raw_print = (*env)->GetMethodID(env, disclass, "rawPrint",
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   647
                                       "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;)V");
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   648
  CHECK_EXCEPTION_CLEAR_VOID
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   649
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   650
  /* decode the buffer */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   651
  (*(decode_func)(uintptr_t)decode_instructions_virtual)(startPc,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   652
                                                         startPc + end - start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   653
                                                         (unsigned char*)start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   654
                                                         end - start,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   655
                                                         &event_to_env,  (void*) &denv,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   656
                                                         &printf_to_env, (void*) &denv,
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   657
                                                         options);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   658
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   659
  /* cleanup */
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   660
  (*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   661
  (*env)->ReleaseStringUTFChars(env, options_s, options);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10739
diff changeset
   662
}