hotspot/src/jdk.hotspot.agent/macosx/native/libsaproc/BsdDebuggerLocal.c
author sspitsyn
Wed, 03 May 2017 02:32:02 +0000
changeset 46426 02a1fc064144
parent 35217 ce4b5303a813
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     2
 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
#include <stdlib.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    26
#include <jni.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
#include "libproc.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#if defined(x86_64) && !defined(amd64)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
#define amd64 1
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#ifdef i386
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
#include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
#ifdef amd64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
#include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
#if defined(sparc) || defined(sparcv9)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
#include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
static jfieldID p_ps_prochandle_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
static jfieldID threadList_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
static jfieldID loadObjectList_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
static jmethodID createClosestSymbol_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
static jmethodID createLoadObject_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
static jmethodID getThreadForThreadId_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
static jmethodID listAdd_ID = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
static struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
  jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
  return (struct ps_prochandle*)(intptr_t)ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
 * Method:    init0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
 * Signature: ()V
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
  (JNIEnv *env, jclass cls) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
  jclass listClass;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
  if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
     THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
  // fields we use
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
  p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
  threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
  loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
  // methods we use
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
  createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
                    "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
  createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
                    "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
  getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
                                                     "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
  // java.util.List method we call
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
  listClass = (*env)->FindClass(env, "java/util/List");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
  listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
  (JNIEnv *env, jclass cls)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
{
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
#ifdef _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
 return 8;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
 return 4;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
  int n = 0, i = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
  // add threads
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
  n = get_num_threads(ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
  for (i = 0; i < n; i++) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
    jobject thread;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
    jobject threadList;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
    lwpid_t lwpid;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
    lwpid = get_lwp_id(ph, i);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
    thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
                                      (jlong)lwpid);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
    CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
    threadList = (*env)->GetObjectField(env, this_obj, threadList_ID);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
    CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
    (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
    CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   138
  // add load objects
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
  n = get_num_libs(ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
  for (i = 0; i < n; i++) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
     uintptr_t base;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
     const char* name;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
     jobject loadObject;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
     jobject loadObjectList;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
     base = get_lib_base(ph, i);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
     name = get_lib_name(ph, i);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
     loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
                                   (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
     CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
     loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
     CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
     (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
     CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
 * Method:    attach0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
 * Signature: (I)V
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   162
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   163
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   164
  (JNIEnv *env, jobject this_obj, jint jpid) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   165
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   166
  struct ps_prochandle* ph;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   167
  if ( (ph = Pgrab(jpid)) == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   168
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   169
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   170
  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   171
  fillThreadsAndLoadObjects(env, this_obj, ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   172
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   173
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   174
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   175
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   176
 * Method:    attach0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   178
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
  (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   181
  const char *execName_cstr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
  const char *coreName_cstr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
  jboolean isCopy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
  struct ps_prochandle* ph;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
  execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   188
  coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   189
  CHECK_EXCEPTION;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   190
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   191
  if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   192
    (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   193
    (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   194
    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
  (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   198
  (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   199
  fillThreadsAndLoadObjects(env, this_obj, ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   200
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   201
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   202
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   203
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
 * Method:    detach0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   205
 * Signature: ()V
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   208
  (JNIEnv *env, jobject this_obj) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
  if (ph != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
     Prelease(ph);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   214
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   215
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   216
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   217
 * Method:    lookupByName0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   218
 * Signature: (Ljava/lang/String;Ljava/lang/String;)J
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   219
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   220
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
  (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
  const char *objectName_cstr, *symbolName_cstr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
  jlong addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
  jboolean isCopy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   225
  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   226
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   227
  objectName_cstr = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   228
  if (objectName != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   229
    objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   230
    CHECK_EXCEPTION_(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   231
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   232
  symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   233
  CHECK_EXCEPTION_(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   234
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   235
  addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   236
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   237
  if (objectName_cstr != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   238
    (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   239
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   240
  (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   241
  return addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   242
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   243
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   244
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   245
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   246
 * Method:    lookupByAddress0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   247
 * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   248
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   249
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   250
  (JNIEnv *env, jobject this_obj, jlong addr) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   251
  uintptr_t offset;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   252
  const char* sym = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   253
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   254
  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   255
  sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   256
  if (sym == NULL) return 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   257
  return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   258
                          (*env)->NewStringUTF(env, sym), (jlong)offset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   259
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   260
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   261
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   262
 * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   263
 * Method:    readBytesFromProcess0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   264
 * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   265
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   266
JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   267
  (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   268
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   269
  jboolean isCopy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   270
  jbyteArray array;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   271
  jbyte *bufPtr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   272
  ps_err_e err;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   273
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   274
  array = (*env)->NewByteArray(env, numBytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   275
  CHECK_EXCEPTION_(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   276
  bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   277
  CHECK_EXCEPTION_(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   278
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   279
  err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   280
  (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   281
  return (err == PS_OK)? array : 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   282
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   283
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   284
JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   285
  (JNIEnv *env, jobject this_obj, jint lwp_id) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   286
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   287
  struct reg gregs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   288
  jboolean isCopy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   289
  jlongArray array;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   290
  jlong *regs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   291
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   292
  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   293
  if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   294
     THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   295
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   296
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   297
#undef NPRGREG
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   298
#ifdef i386
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   299
#define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   300
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   301
#ifdef ia64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   302
#define NPRGREG IA64_REG_COUNT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   303
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   304
#ifdef amd64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   305
#define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   306
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   307
#if defined(sparc) || defined(sparcv9)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   308
#define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   309
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   310
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   311
  array = (*env)->NewLongArray(env, NPRGREG);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   312
  CHECK_EXCEPTION_(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   313
  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   314
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   315
#undef REG_INDEX
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   316
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   317
#ifdef i386
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   318
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   319
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   320
  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.r_gs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   321
  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.r_fs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   322
  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.r_es;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   323
  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.r_ds;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   324
  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   325
  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   326
  regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   327
  regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   328
  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   329
  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   330
  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   331
  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   332
  regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   333
  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.r_cs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   334
  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.r_ss;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   335
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   336
#endif /* i386 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   337
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   338
#if ia64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   339
  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   340
  int i;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   341
  for (i = 0; i < NPRGREG; i++ ) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   342
    regs[i] = 0xDEADDEAD;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   343
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   344
#endif /* ia64 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   345
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   346
#ifdef amd64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   347
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   348
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   349
  regs[REG_INDEX(R15)] = gregs.r_r15;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   350
  regs[REG_INDEX(R14)] = gregs.r_r14;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   351
  regs[REG_INDEX(R13)] = gregs.r_r13;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   352
  regs[REG_INDEX(R12)] = gregs.r_r12;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   353
  regs[REG_INDEX(RBP)] = gregs.r_rbp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   354
  regs[REG_INDEX(RBX)] = gregs.r_rbx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   355
  regs[REG_INDEX(R11)] = gregs.r_r11;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   356
  regs[REG_INDEX(R10)] = gregs.r_r10;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   357
  regs[REG_INDEX(R9)] = gregs.r_r9;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   358
  regs[REG_INDEX(R8)] = gregs.r_r8;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   359
  regs[REG_INDEX(RAX)] = gregs.r_rax;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   360
  regs[REG_INDEX(RCX)] = gregs.r_rcx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   361
  regs[REG_INDEX(RDX)] = gregs.r_rdx;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   362
  regs[REG_INDEX(RSI)] = gregs.r_rsi;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   363
  regs[REG_INDEX(RDI)] = gregs.r_rdi;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   364
  regs[REG_INDEX(RIP)] = gregs.r_rip;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   365
  regs[REG_INDEX(CS)] = gregs.r_cs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   366
  regs[REG_INDEX(RSP)] = gregs.r_rsp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   367
  regs[REG_INDEX(SS)] = gregs.r_ss;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   368
//  regs[REG_INDEX(FSBASE)] = gregs.fs_base;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   369
//  regs[REG_INDEX(GSBASE)] = gregs.gs_base;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   370
//  regs[REG_INDEX(DS)] = gregs.ds;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   371
//  regs[REG_INDEX(ES)] = gregs.es;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   372
//  regs[REG_INDEX(FS)] = gregs.fs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   373
//  regs[REG_INDEX(GS)] = gregs.gs;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   374
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   375
#endif /* amd64 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   376
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   377
#if defined(sparc) || defined(sparcv9)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   378
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   379
#define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   380
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   381
#ifdef _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   382
  regs[REG_INDEX(R_PSR)] = gregs.tstate;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   383
  regs[REG_INDEX(R_PC)]  = gregs.tpc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   384
  regs[REG_INDEX(R_nPC)] = gregs.tnpc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   385
  regs[REG_INDEX(R_Y)]   = gregs.y;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   386
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   387
  regs[REG_INDEX(R_PSR)] = gregs.psr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   388
  regs[REG_INDEX(R_PC)]  = gregs.pc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   389
  regs[REG_INDEX(R_nPC)] = gregs.npc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   390
  regs[REG_INDEX(R_Y)]   = gregs.y;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   391
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   392
  regs[REG_INDEX(R_G0)]  =            0 ;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   393
  regs[REG_INDEX(R_G1)]  = gregs.u_regs[0];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   394
  regs[REG_INDEX(R_G2)]  = gregs.u_regs[1];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   395
  regs[REG_INDEX(R_G3)]  = gregs.u_regs[2];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   396
  regs[REG_INDEX(R_G4)]  = gregs.u_regs[3];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   397
  regs[REG_INDEX(R_G5)]  = gregs.u_regs[4];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   398
  regs[REG_INDEX(R_G6)]  = gregs.u_regs[5];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   399
  regs[REG_INDEX(R_G7)]  = gregs.u_regs[6];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   400
  regs[REG_INDEX(R_O0)]  = gregs.u_regs[7];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   401
  regs[REG_INDEX(R_O1)]  = gregs.u_regs[8];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   402
  regs[REG_INDEX(R_O2)]  = gregs.u_regs[ 9];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   403
  regs[REG_INDEX(R_O3)]  = gregs.u_regs[10];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   404
  regs[REG_INDEX(R_O4)]  = gregs.u_regs[11];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   405
  regs[REG_INDEX(R_O5)]  = gregs.u_regs[12];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   406
  regs[REG_INDEX(R_O6)]  = gregs.u_regs[13];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   407
  regs[REG_INDEX(R_O7)]  = gregs.u_regs[14];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   408
#endif /* sparc */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   409
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   410
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   411
  (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   412
  return array;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   413
}