hotspot/src/jdk.hotspot.agent/solaris/native/libsaproc/saproc.cpp
author dsamersoff
Wed, 23 Dec 2015 13:12:15 +0300
changeset 35217 ce4b5303a813
parent 26410 hotspot/agent/src/os/solaris/proc/saproc.cpp@a34c8032e674
child 42035 10e6e31dc1aa
permissions -rw-r--r--
8067194: Restructure hotspot/agent/src to conform the modular source layout Summary: Move sources under jdk.hotspot.agent Reviewed-by: ihse, erikj, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17310
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "salibproc.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h"
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    27
#ifndef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    28
#include <sys/utsname.h>
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    29
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#include <thread_db.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#include <strings.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#include <limits.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#include <demangle.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#include <stdarg.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#include <stdlib.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#include <errno.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
#define SYMBOL_BUF_SIZE  256
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#define ERR_MSG_SIZE     (PATH_MAX + 256)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    46
// debug modes
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
static int _libsaproc_debug = 0;
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    48
#ifndef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    49
static bool _Pstack_iter_debug = false;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    50
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    51
static void dprintf_2(const char* format,...) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    52
  if (_Pstack_iter_debug) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    53
    va_list alist;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    54
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    55
    va_start(alist, format);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    56
    fputs("Pstack_iter DEBUG: ", stderr);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    57
    vfprintf(stderr, format, alist);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    58
    va_end(alist);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    59
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    60
}
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
    61
#endif // !SOLARIS_11_B159_OR_LATER
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
static void print_debug(const char* format,...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  if (_libsaproc_debug) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    va_list alist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    va_start(alist, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    fputs("libsaproc DEBUG: ", stderr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    vfprintf(stderr, format, alist);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    va_end(alist);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
struct Debugger {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    JNIEnv* env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    jobject this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
struct DebuggerWithObject : Debugger {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    jobject obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
struct DebuggerWith2Objects : DebuggerWithObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    jobject obj2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
* Portions of user thread level detail gathering code is from pstack source
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
* code. See pstack.c in Solaris 2.8 user commands source code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
static void throwNewDebuggerException(JNIEnv* env, const char* errMsg) {
26410
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
    93
  jclass clazz = env->FindClass("sun/jvm/hotspot/debugger/DebuggerException");
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
    94
  CHECK_EXCEPTION;
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
    95
  env->ThrowNew(clazz, errMsg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// JNI ids for some fields, methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// libproc handler pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
static jfieldID p_ps_prochandle_ID = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// libthread.so dlopen handle, thread agent ptr and function pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
static jfieldID libthread_db_handle_ID   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
static jfieldID p_td_thragent_t_ID       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
static jfieldID p_td_init_ID             = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
static jfieldID p_td_ta_new_ID           = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
static jfieldID p_td_ta_delete_ID        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
static jfieldID p_td_ta_thr_iter_ID      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
static jfieldID p_td_thr_get_info_ID     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
static jfieldID p_td_ta_map_id2thr_ID    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
static jfieldID p_td_thr_getgregs_ID     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// reg index fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
static jfieldID pcRegIndex_ID            = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
static jfieldID fpRegIndex_ID            = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
static jfieldID classes_jsa_fd_ID        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
static jfieldID p_file_map_header_ID     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// method ids
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
static jmethodID getThreadForThreadId_ID = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
static jmethodID createSenderFrame_ID    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
static jmethodID createLoadObject_ID     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
static jmethodID createClosestSymbol_ID  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
static jmethodID listAdd_ID              = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
 * Functions we need from libthread_db
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        (*p_td_init_t)(void);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        (*p_td_ta_new_t)(void *, td_thragent_t **);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        (*p_td_ta_delete_t)(td_thragent_t *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        (*p_td_ta_thr_iter_t)(const td_thragent_t *, td_thr_iter_f *, void *,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                td_thr_state_e, int, sigset_t *, unsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        (*p_td_thr_get_info_t)(const td_thrhandle_t *, td_thrinfo_t *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        (*p_td_ta_map_id2thr_t)(const td_thragent_t *, thread_t,  td_thrhandle_t *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
typedef td_err_e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        (*p_td_thr_getgregs_t)(const td_thrhandle_t *, prgregset_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
static void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
clear_libthread_db_ptrs(JNIEnv* env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // release libthread_db agent, if we had created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  p_td_ta_delete_t p_td_ta_delete = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  p_td_ta_delete = (p_td_ta_delete_t) env->GetLongField(this_obj, p_td_ta_delete_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  td_thragent_t *p_td_thragent_t = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  if (p_td_thragent_t != 0 && p_td_ta_delete != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
     p_td_ta_delete(p_td_thragent_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // dlclose libthread_db.so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void* libthread_db_handle = (void*) env->GetLongField(this_obj, libthread_db_handle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  if (libthread_db_handle != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    dlclose(libthread_db_handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  env->SetLongField(this_obj, libthread_db_handle_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  env->SetLongField(this_obj, p_td_init_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  env->SetLongField(this_obj, p_td_ta_new_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  env->SetLongField(this_obj, p_td_ta_delete_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  env->SetLongField(this_obj, p_td_ta_thr_iter_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  env->SetLongField(this_obj, p_td_thr_get_info_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
static void detach_internal(JNIEnv* env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // clear libthread_db stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  clear_libthread_db_ptrs(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // release ptr to ps_prochandle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  jlong p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (p_ps_prochandle != 0L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    Prelease((struct ps_prochandle*) p_ps_prochandle, PRELEASE_CLEAR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  if (classes_jsa_fd != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    close(classes_jsa_fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    if (pheader != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      free(pheader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
// Is it okay to ignore libthread_db failure? Set env var to ignore
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// libthread_db failure. You can still debug, but will miss threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// related functionality.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
static bool sa_ignore_threaddb = (getenv("SA_IGNORE_THREADDB") != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
#define HANDLE_THREADDB_FAILURE(msg)          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  if (sa_ignore_threaddb) {                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
     printf("libsaproc WARNING: %s\n", msg);  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
     return;                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  } else {                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
     THROW_NEW_DEBUGGER_EXCEPTION(msg);       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
#define HANDLE_THREADDB_FAILURE_(msg, ret)    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (sa_ignore_threaddb) {                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
     printf("libsaproc WARNING: %s\n", msg);  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
     return ret;                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  } else {                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
     THROW_NEW_DEBUGGER_EXCEPTION_(msg, ret); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
static const char * alt_root = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
static int alt_root_len = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
#define SA_ALTROOT "SA_ALTROOT"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
static void init_alt_root() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  if (alt_root_len == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    alt_root = getenv(SA_ALTROOT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    if (alt_root)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      alt_root_len = strlen(alt_root);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      alt_root_len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   236
// This function is a complete substitute for the open system call
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   237
// since it's also used to override open calls from libproc to
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   238
// implement as a pathmap style facility for the SA.  If libproc
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   239
// starts using other interfaces then this might have to extended to
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   240
// cover other calls.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   241
extern "C" int libsaproc_open(const char * name, int oflag, ...) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   242
  if (oflag == O_RDONLY) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   243
    init_alt_root();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   245
    if (_libsaproc_debug) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   246
      printf("libsaproc DEBUG: libsaproc_open %s\n", name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   249
    if (alt_root_len > 0) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   250
      int fd = -1;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   251
      char alt_path[PATH_MAX+1];
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   252
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      strcpy(alt_path, alt_root);
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   254
      strcat(alt_path, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      fd = open(alt_path, O_RDONLY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      if (fd >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        if (_libsaproc_debug) {
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   258
          printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        return fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      }
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   262
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   263
      if (strrchr(name, '/')) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   264
        strcpy(alt_path, alt_root);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   265
        strcat(alt_path, strrchr(name, '/'));
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   266
        fd = open(alt_path, O_RDONLY);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   267
        if (fd >= 0) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   268
          if (_libsaproc_debug) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   269
            printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   270
          }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   271
          return fd;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   272
        }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   273
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   276
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   277
  {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   278
    mode_t mode;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   279
    va_list ap;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   280
    va_start(ap, oflag);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   281
    mode = va_arg(ap, mode_t);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   282
    va_end(ap);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   283
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   284
    return open(name, oflag, mode);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   285
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
static void * pathmap_dlopen(const char * name, int mode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  init_alt_root();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  if (_libsaproc_debug) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    printf("libsaproc DEBUG: pathmap_dlopen %s\n", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  void * handle = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  if (alt_root_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    char alt_path[PATH_MAX+1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    strcpy(alt_path, alt_root);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    strcat(alt_path, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    handle = dlopen(alt_path, mode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (_libsaproc_debug && handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      printf("libsaproc DEBUG: pathmap_dlopen substituted %s\n", alt_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    if (handle == NULL && strrchr(name, '/')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      strcpy(alt_path, alt_root);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      strcat(alt_path, strrchr(name, '/'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      handle = dlopen(alt_path, mode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      if (_libsaproc_debug && handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
        printf("libsaproc DEBUG: pathmap_dlopen substituted %s\n", alt_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  if (handle == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    handle = dlopen(name, mode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  if (_libsaproc_debug) {
25945
cb5dcc388aff 8049049: Unportable format string argument mismatch in hotspot/agent/src/os/solaris/proc/saproc.cpp
dsamersoff
parents: 25901
diff changeset
   319
    printf("libsaproc DEBUG: pathmap_dlopen %s return 0x%lx\n", name, (unsigned long) handle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  return handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// libproc and libthread_db callback functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
static int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
init_libthread_db_ptrs(void *cd, const prmap_t *pmp, const char *object_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  Debugger* dbg = (Debugger*) cd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  JNIEnv* env = dbg->env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  jobject this_obj = dbg->this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  struct ps_prochandle* ph = (struct ps_prochandle*) env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  char *s1 = 0, *s2 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  char libthread_db[PATH_MAX];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if (strstr(object_name, "/libthread.so.") == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
     return (0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
   * We found a libthread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
   * dlopen() the matching libthread_db and get the thread agent handle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (Pstatus(ph)->pr_dmodel == PR_MODEL_NATIVE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
     (void) strcpy(libthread_db, object_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
     s1 = (char*) strstr(object_name, ".so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
     s2 = (char*) strstr(libthread_db, ".so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
     (void) strcpy(s2, "_db");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
     s2 += 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
     (void) strcpy(s2, s1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
     /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      * The victim process is 32-bit, we are 64-bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      * We have to find the 64-bit version of libthread_db
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      * that matches the victim's 32-bit version of libthread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
     (void) strcpy(libthread_db, object_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
     s1 = (char*) strstr(object_name, "/libthread.so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
     s2 = (char*) strstr(libthread_db, "/libthread.so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
     (void) strcpy(s2, "/64");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
     s2 += 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
     (void) strcpy(s2, s1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
     s1 = (char*) strstr(s1, ".so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
     s2 = (char*) strstr(s2, ".so.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
     (void) strcpy(s2, "_db");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
     s2 += 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
     (void) strcpy(s2, s1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
     return (0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
#endif  /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  void* libthread_db_handle = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  if ((libthread_db_handle = pathmap_dlopen(libthread_db, RTLD_LAZY|RTLD_LOCAL)) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
     char errMsg[PATH_MAX + 256];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
     sprintf(errMsg, "Can't load %s!", libthread_db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
     HANDLE_THREADDB_FAILURE_(errMsg, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  env->SetLongField(this_obj, libthread_db_handle_ID, (jlong)(uintptr_t)libthread_db_handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  void* tmpPtr = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  tmpPtr = dlsym(libthread_db_handle, "td_init");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_init!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  env->SetLongField(this_obj, p_td_init_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  tmpPtr =dlsym(libthread_db_handle, "td_ta_new");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_new!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  env->SetLongField(this_obj, p_td_ta_new_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  tmpPtr = dlsym(libthread_db_handle, "td_ta_delete");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_delete!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  env->SetLongField(this_obj, p_td_ta_delete_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  tmpPtr = dlsym(libthread_db_handle, "td_ta_thr_iter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_thr_iter!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  env->SetLongField(this_obj, p_td_ta_thr_iter_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  tmpPtr = dlsym(libthread_db_handle, "td_thr_get_info");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_thr_get_info!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  env->SetLongField(this_obj, p_td_thr_get_info_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  tmpPtr = dlsym(libthread_db_handle, "td_ta_map_id2thr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_ta_map_id2thr!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  env->SetLongField(this_obj, p_td_ta_map_id2thr_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  tmpPtr = dlsym(libthread_db_handle, "td_thr_getgregs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  if (tmpPtr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
     HANDLE_THREADDB_FAILURE_("dlsym failed on td_thr_getgregs!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  env->SetLongField(this_obj, p_td_thr_getgregs_ID, (jlong)(uintptr_t) tmpPtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
static int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
fill_thread_list(const td_thrhandle_t *p_td_thragent_t, void* cd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  DebuggerWithObject* dbgo = (DebuggerWithObject*) cd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  JNIEnv* env = dbgo->env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  jobject this_obj = dbgo->this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  jobject list = dbgo->obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  td_thrinfo_t thrinfo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  p_td_thr_get_info_t p_td_thr_get_info = (p_td_thr_get_info_t) env->GetLongField(this_obj, p_td_thr_get_info_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  if (p_td_thr_get_info(p_td_thragent_t, &thrinfo) != TD_OK)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    return (0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  jobject threadProxy = env->CallObjectMethod(this_obj, getThreadForThreadId_ID, (jlong)(uintptr_t) thrinfo.ti_tid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  env->CallBooleanMethod(list, listAdd_ID, threadProxy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
static int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
fill_load_object_list(void *cd, const prmap_t* pmp, const char* obj_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  if (obj_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
     DebuggerWithObject* dbgo = (DebuggerWithObject*) cd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
     JNIEnv* env = dbgo->env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
     jobject this_obj = dbgo->this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
     jobject list = dbgo->obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
     jstring objectName = env->NewStringUTF(obj_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
     CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
     jlong mapSize = (jlong) pmp->pr_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
     jobject sharedObject = env->CallObjectMethod(this_obj, createLoadObject_ID,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
                                  objectName, mapSize, (jlong)(uintptr_t)pmp->pr_vaddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
     CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
     env->CallBooleanMethod(list, listAdd_ID, sharedObject);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
     CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   472
// Pstack_iter() proc_stack_f callback prior to Nevada-B159
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
static int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc, const long *argv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  DebuggerWith2Objects* dbgo2 = (DebuggerWith2Objects*) cd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  JNIEnv* env = dbgo2->env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  jobject this_obj = dbgo2->this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  jobject curFrame = dbgo2->obj2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  jint pcRegIndex = env->GetIntField(this_obj, pcRegIndex_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  jint fpRegIndex = env->GetIntField(this_obj, fpRegIndex_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  jlong pc = (jlong) (uintptr_t) regs[pcRegIndex];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  jlong fp = (jlong) (uintptr_t) regs[fpRegIndex];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  dbgo2->obj2 = env->CallObjectMethod(this_obj, createSenderFrame_ID,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                                    curFrame, pc, fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  CHECK_EXCEPTION_(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  if (dbgo2->obj == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
     dbgo2->obj = dbgo2->obj2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   495
// Pstack_iter() proc_stack_f callback in Nevada-B159 or later
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   496
/*ARGSUSED*/
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   497
static int
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   498
wrapper_fill_cframe_list(void *cd, const prgregset_t regs, uint_t argc,
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   499
                         const long *argv, int frame_flags, int sig) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   500
  return(fill_cframe_list(cd, regs, argc, argv));
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   501
}
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
   502
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
// part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
// FIXME: !!HACK ALERT!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
// The format of sharing achive file header is needed to read shared heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
// file mappings. For now, I am hard coding portion of FileMapHeader here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
// Refer to filemap.hpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
// FileMapHeader describes the shared space data in the file to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
// mapped.  This structure gets written to a file.  It is not a class, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
// that the compilers don't add any compiler-private data to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
const int NUM_SHARED_MAPS = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
// Refer to FileMapInfo::_current_version in filemap.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
const int CURRENT_ARCHIVE_VERSION = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
struct FileMapHeader {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
 int   _magic;              // identify file type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
 int   _version;            // (from enum, above.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
 size_t _alignment;         // how shared archive should be aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
 struct space_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
   int    _file_offset;     // sizeof(this) rounded to vm page size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
   char*  _base;            // copy-on-write base address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
   size_t _capacity;        // for validity checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
   size_t _used;            // for setting space top on read
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
   bool   _read_only;       // read only space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
   bool   _allow_exec;      // executable code in space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9407
diff changeset
   535
 } _space[NUM_SHARED_MAPS];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
 // Ignore the rest of the FileMapHeader. We don't need those fields here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
static bool
1905
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   541
read_jboolean(struct ps_prochandle* ph, psaddr_t addr, jboolean* pvalue) {
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   542
  jboolean i;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  if (ps_pread(ph, addr, &i, sizeof(i)) == PS_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    *pvalue = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
static bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
read_pointer(struct ps_prochandle* ph, psaddr_t addr, uintptr_t* pvalue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  uintptr_t uip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  if (ps_pread(ph, addr, &uip, sizeof(uip)) == PS_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    *pvalue = uip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
static bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
read_string(struct ps_prochandle* ph, psaddr_t addr, char* buf, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  char ch = ' ';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  size_t i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  while (ch != '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    if (ps_pread(ph, addr, &ch, sizeof(ch)) != PS_OK)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    if (i < size - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      buf[i] = ch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    } else { // smaller buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    i++; addr++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  buf[i] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
#define USE_SHARED_SPACES_SYM   "UseSharedSpaces"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
// mangled symbol name for Arguments::SharedArchivePath
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
#define SHARED_ARCHIVE_PATH_SYM "__1cJArgumentsRSharedArchivePath_"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
static int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
init_classsharing_workaround(void *cd, const prmap_t* pmap, const char* obj_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  Debugger* dbg = (Debugger*) cd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  JNIEnv*   env = dbg->env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  jobject this_obj = dbg->this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  const char* jvm_name = 0;
17310
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   594
  if ((jvm_name = strstr(obj_name, "libjvm.so")) != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    jvm_name = obj_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  struct ps_prochandle* ph = (struct ps_prochandle*) env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
17310
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   602
  // initialize classes.jsa file descriptor field.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  // check whether class sharing is on by reading variable "UseSharedSpaces"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  psaddr_t useSharedSpacesAddr = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  ps_pglobal_lookup(ph, jvm_name, USE_SHARED_SPACES_SYM, &useSharedSpacesAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  if (useSharedSpacesAddr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    THROW_NEW_DEBUGGER_EXCEPTION_("can't find 'UseSharedSpaces' flag\n", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // read the value of the flag "UseSharedSpaces"
1905
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   613
  // Since hotspot types are not available to build this library. So
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   614
  // equivalent type "jboolean" is used to read the value of "UseSharedSpaces"
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   615
  // which is same as hotspot type "bool".
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   616
  jboolean value = 0;
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   617
  if (read_jboolean(ph, useSharedSpacesAddr, &value) != true) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    THROW_NEW_DEBUGGER_EXCEPTION_("can't read 'UseSharedSpaces' flag", 1);
1905
059ce1b8f69e 6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
swamyv
parents: 1
diff changeset
   619
  } else if ((int)value == 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  char classes_jsa[PATH_MAX];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  psaddr_t sharedArchivePathAddrAddr = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  ps_pglobal_lookup(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM, &sharedArchivePathAddrAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  if (sharedArchivePathAddrAddr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    print_debug("can't find symbol 'Arguments::SharedArchivePath'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  uintptr_t sharedArchivePathAddr = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    print_debug("can't find read pointer 'Arguments::SharedArchivePath'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  if (read_string(ph, (psaddr_t)sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    print_debug("can't find read 'Arguments::SharedArchivePath' value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    THROW_NEW_DEBUGGER_EXCEPTION_("can't get shared archive path from debuggee", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  print_debug("looking for %s\n", classes_jsa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
17310
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   645
  // open the classes.jsa
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents: 2105
diff changeset
   646
  int fd = libsaproc_open(classes_jsa, O_RDONLY);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  if (fd < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    char errMsg[ERR_MSG_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    sprintf(errMsg, "can't open shared archive file %s", classes_jsa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    print_debug("opened shared archive file %s\n", classes_jsa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
17310
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   655
  // parse classes.jsa
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  struct FileMapHeader* pheader = (struct FileMapHeader*) malloc(sizeof(struct FileMapHeader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  if (pheader == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    close(fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    THROW_NEW_DEBUGGER_EXCEPTION_("can't allocate memory for shared file map header", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  memset(pheader, 0, sizeof(struct FileMapHeader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  // read FileMapHeader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  size_t n = read(fd, pheader, sizeof(struct FileMapHeader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  if (n != sizeof(struct FileMapHeader)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    char errMsg[ERR_MSG_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    sprintf(errMsg, "unable to read shared archive file map header from %s", classes_jsa);
25901
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   668
    close(fd);
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   669
    free(pheader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  // check file magic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  if (pheader->_magic != 0xf00baba2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    char errMsg[ERR_MSG_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    sprintf(errMsg, "%s has bad shared archive magic 0x%x, expecting 0xf00baba2",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
                   classes_jsa, pheader->_magic);
25901
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   678
    close(fd);
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   679
    free(pheader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  // check version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  if (pheader->_version != CURRENT_ARCHIVE_VERSION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    char errMsg[ERR_MSG_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    sprintf(errMsg, "%s has wrong shared archive version %d, expecting %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                   classes_jsa, pheader->_version, CURRENT_ARCHIVE_VERSION);
25901
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   688
    close(fd);
34036ccd1364 8025667: Warning from b62 for hotspot.agent.src.os.solaris.proc: use after free
dsamersoff
parents: 22234
diff changeset
   689
    free(pheader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    THROW_NEW_DEBUGGER_EXCEPTION_(errMsg, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  if (_libsaproc_debug) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    for (int m = 0; m < NUM_SHARED_MAPS; m++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
       print_debug("shared file offset %d mapped at 0x%lx, size = %ld, read only? = %d\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
          pheader->_space[m]._file_offset, pheader->_space[m]._base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
          pheader->_space[m]._used, pheader->_space[m]._read_only);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // FIXME: For now, omitting other checks such as VM version etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  // store class archive file fd and map header in debugger object fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  dbg->env->SetIntField(this_obj, classes_jsa_fd_ID, fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  dbg->env->SetLongField(this_obj, p_file_map_header_ID, (jlong)(uintptr_t) pheader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
} // extern "C"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
// error messages for proc_arg_grab failure codes. The messages are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
// modified versions of comments against corresponding #defines in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
// libproc.h.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
static const char* proc_arg_grab_errmsgs[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
                      "",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
 /* G_NOPROC */       "No such process",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
 /* G_NOCORE */       "No such core file",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
 /* G_NOPROCORCORE */ "No such process or core",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
 /* G_NOEXEC */       "Cannot locate executable file",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
 /* G_ZOMB   */       "Zombie processs",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
 /* G_PERM   */       "No permission to attach",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
 /* G_BUSY   */       "Another process has already attached",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
 /* G_SYS    */       "System process - can not attach",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
 /* G_SELF   */       "Process is self - can't debug myself!",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
 /* G_INTR   */       "Interrupt received while grabbing",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
 /* G_LP64   */       "debuggee is 64 bit, use java -d64 for debugger",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
 /* G_FORMAT */       "File is not an ELF format core file - corrupted core?",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
 /* G_ELF    */       "Libelf error while parsing an ELF file",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
 /* G_NOTE   */       "Required PT_NOTE Phdr not present - corrupted core?",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
static void attach_internal(JNIEnv* env, jobject this_obj, jstring cmdLine, jboolean isProcess) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  int gcode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  const char* cmdLine_cstr = env->GetStringUTFChars(cmdLine, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  // some older versions of libproc.so crash when trying to attach 32 bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  // debugger to 64 bit core file. check and throw error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  atoi(cmdLine_cstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  if (errno) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
     // core file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
     int core_fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
     if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
        Elf32_Ehdr e32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
        if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
            memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
            e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
              close(core_fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
              THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
        close(core_fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
     // all other conditions are handled by libproc.so.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  // connect to process/core
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  struct ps_prochandle* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  if (! ph) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
     if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
        char errMsg[ERR_MSG_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
        sprintf(errMsg, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
        THROW_NEW_DEBUGGER_EXCEPTION(errMsg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
        if (_libsaproc_debug && gcode == G_STRANGE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
           perror("libsaproc DEBUG: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
        if (isProcess) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
           THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to process!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
           THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to core file!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // even though libproc.so supports 64 bit debugger and 32 bit debuggee, we don't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  // support such cross-bit-debugging. check for that combination and throw error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  int data_model;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  if (ps_pdmodel(ph, &data_model) != PS_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
     Prelease(ph, PRELEASE_CLEAR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
     THROW_NEW_DEBUGGER_EXCEPTION("can't determine debuggee data model (ILP32? or LP64?)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  if (data_model == PR_MODEL_ILP32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
     Prelease(ph, PRELEASE_CLEAR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
     THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  env->SetLongField(this_obj, p_ps_prochandle_ID, (jlong)(uintptr_t)ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  Debugger dbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  dbg.env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  dbg.this_obj = this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  jthrowable exception = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  if (! isProcess) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
     * With class sharing, shared perm. gen heap is allocated in with MAP_SHARED|PROT_READ.
17310
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   802
     * These pages are mapped from the file "classes.jsa". MAP_SHARED pages are not dumped
b4118c427cc0 8005038: remove crufty '_g' support from SA
sla
parents: 13728
diff changeset
   803
     * in Solaris core.To read shared heap pages, we have to read classes.jsa file.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    Pobject_iter(ph, init_classsharing_workaround, &dbg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    exception = env->ExceptionOccurred();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    if (exception) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      env->ExceptionClear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
      env->Throw(exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
   * Iterate over the process mappings looking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
   * for libthread and then dlopen the appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
   * libthread_db and get function pointers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  Pobject_iter(ph, init_libthread_db_ptrs, &dbg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  exception = env->ExceptionOccurred();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  if (exception) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    env->ExceptionClear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    if (!sa_ignore_threaddb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      env->Throw(exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  // init libthread_db and create thread_db agent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  p_td_init_t p_td_init = (p_td_init_t) env->GetLongField(this_obj, p_td_init_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  if (p_td_init == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    if (!sa_ignore_threaddb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    HANDLE_THREADDB_FAILURE("Did not find libthread in target process/core!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  if (p_td_init() != TD_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    if (!sa_ignore_threaddb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    HANDLE_THREADDB_FAILURE("Can't initialize thread_db!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  p_td_ta_new_t p_td_ta_new = (p_td_ta_new_t) env->GetLongField(this_obj, p_td_ta_new_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  td_thragent_t *p_td_thragent_t = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  if (p_td_ta_new(ph, &p_td_thragent_t) != TD_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    if (!sa_ignore_threaddb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
      detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    HANDLE_THREADDB_FAILURE("Can't create thread_db agent!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  env->SetLongField(this_obj, p_td_thragent_t_ID, (jlong)(uintptr_t) p_td_thragent_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
 * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
 * Method:    attach0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
 * Signature: (Ljava/lang/String;)V
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
 * Description: process detach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_attach0__Ljava_lang_String_2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  (JNIEnv *env, jobject this_obj, jstring pid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  attach_internal(env, this_obj, pid, JNI_TRUE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
 * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
 * Method:    attach0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
 * Description: core file detach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  (JNIEnv *env, jobject this_obj, jstring executable, jstring corefile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  // ignore executable file name, libproc.so can detect a.out name anyway.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  attach_internal(env, this_obj, corefile, JNI_FALSE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
 * Method:      detach0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
 * Signature:   ()V
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
 * Description: process/core file detach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_detach0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  (JNIEnv *env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  detach_internal(env, this_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
 * Method:      getRemoteProcessAddressSize0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
 * Signature:   ()I
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
 * Description: get process/core address size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getRemoteProcessAddressSize0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  (JNIEnv *env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  jlong p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  int data_model = PR_MODEL_ILP32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  ps_pdmodel((struct ps_prochandle*) p_ps_prochandle, &data_model);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  print_debug("debuggee is %d bit\n", data_model == PR_MODEL_ILP32? 32 : 64);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  return (jint) data_model == PR_MODEL_ILP32? 32 : 64;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
 * Method:      getPageSize0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
 * Signature:   ()I
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
 * Description: get process/core page size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getPageSize0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  (JNIEnv *env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  We are not yet attached to a java process or core file. getPageSize is called from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  the constructor of ProcDebuggerLocal. The following won't work!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    jlong p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
    p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
    CHECK_EXCEPTION_(-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    struct ps_prochandle* prochandle = (struct ps_prochandle*) p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    return (Pstate(prochandle) == PS_DEAD) ? Pgetauxval(prochandle, AT_PAGESZ)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
                                           : getpagesize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  So even though core may have been generated with a different page size settings, for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  call getpagesize.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  return getpagesize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
 * Method:      getThreadIntegerRegisterSet0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
 * Signature:   (J)[J
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
 * Description: get gregset for a given thread specified by thread id
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_getThreadIntegerRegisterSet0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  (JNIEnv *env, jobject this_obj, jlong tid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  // map the thread id to thread handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  p_td_ta_map_id2thr_t p_td_ta_map_id2thr = (p_td_ta_map_id2thr_t) env->GetLongField(this_obj, p_td_ta_map_id2thr_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  td_thragent_t* p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  if (p_td_thragent_t == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
     return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  td_thrhandle_t thr_handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  if (p_td_ta_map_id2thr(p_td_thragent_t, (thread_t) tid, &thr_handle) != TD_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
     THROW_NEW_DEBUGGER_EXCEPTION_("can't map thread id to thread handle!", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  p_td_thr_getgregs_t p_td_thr_getgregs = (p_td_thr_getgregs_t) env->GetLongField(this_obj, p_td_thr_getgregs_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  prgregset_t gregs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  p_td_thr_getgregs(&thr_handle, gregs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  jlongArray res = env->NewLongArray(NPRGREG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  jlong* ptr = env->GetLongArrayElements(res, &isCopy);
26410
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
   967
  CHECK_EXCEPTION_(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  for (int i = 0; i < NPRGREG; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    ptr[i] = (jlong) (uintptr_t) gregs[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  env->ReleaseLongArrayElements(res, ptr, JNI_COMMIT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
 * Method:      fillThreadList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
 * Signature:   (Ljava/util/List;)V
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
 * Description: fills thread list of the debuggee process/core
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillThreadList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  (JNIEnv *env, jobject this_obj, jobject list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  td_thragent_t* p_td_thragent_t = (td_thragent_t*) env->GetLongField(this_obj, p_td_thragent_t_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  if (p_td_thragent_t == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
     return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  p_td_ta_thr_iter_t p_td_ta_thr_iter = (p_td_ta_thr_iter_t) env->GetLongField(this_obj, p_td_ta_thr_iter_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  DebuggerWithObject dbgo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  dbgo.env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  dbgo.this_obj = this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  dbgo.obj = list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  p_td_ta_thr_iter(p_td_thragent_t, fill_thread_list, &dbgo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
                   TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1000
#ifndef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1001
// building on Nevada-B158 or earlier so more hoops to jump through
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1002
static bool has_newer_Pstack_iter = false;  // older version by default
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1003
#endif
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1004
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
 * Method:      fillCFrameList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
 * Signature:   ([J)Lsun/jvm/hotspot/debugger/proc/ProcCFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
 * Description: fills CFrame list for a given thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillCFrameList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  (JNIEnv *env, jobject this_obj, jlongArray regsArray) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  DebuggerWith2Objects dbgo2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  dbgo2.env  = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  dbgo2.this_obj = this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  dbgo2.obj  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  dbgo2.obj2 = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  jlong* ptr = env->GetLongArrayElements(regsArray, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  prgregset_t gregs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  for (int i = 0; i < NPRGREG; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
     gregs[i] = (uintptr_t) ptr[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  env->ReleaseLongArrayElements(regsArray, ptr, JNI_ABORT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  CHECK_EXCEPTION_(0);
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1032
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1033
#ifdef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1034
  // building on Nevada-B159 or later so use the new callback
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1035
  Pstack_iter((struct ps_prochandle*) p_ps_prochandle, gregs,
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1036
              wrapper_fill_cframe_list, &dbgo2);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1037
#else
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1038
  // building on Nevada-B158 or earlier so figure out which callback to use
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1039
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1040
  if (has_newer_Pstack_iter) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1041
    // Since we're building on Nevada-B158 or earlier, we have to
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1042
    // cast wrapper_fill_cframe_list to make the compiler happy.
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1043
    Pstack_iter((struct ps_prochandle*) p_ps_prochandle, gregs,
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1044
                (proc_stack_f *)wrapper_fill_cframe_list, &dbgo2);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1045
  } else {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1046
    Pstack_iter((struct ps_prochandle*) p_ps_prochandle, gregs,
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1047
                fill_cframe_list, &dbgo2);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1048
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1049
#endif // SOLARIS_11_B159_OR_LATER
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  return dbgo2.obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
 * Method:      fillLoadObjectList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
 * Signature:   (Ljava/util/List;)V
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
 * Description: fills shared objects of the debuggee process/core
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_fillLoadObjectList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  (JNIEnv *env, jobject this_obj, jobject list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  DebuggerWithObject dbgo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  dbgo.env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  dbgo.this_obj = this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  dbgo.obj = list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  Pobject_iter((struct ps_prochandle*) p_ps_prochandle, fill_load_object_list, &dbgo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
 * Method:      readBytesFromProcess0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
 * Signature:   (JJ)[B
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
 * Description: read bytes from debuggee process/core
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_readBytesFromProcess0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  (JNIEnv *env, jobject this_obj, jlong address, jlong numBytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  jbyteArray array = env->NewByteArray(numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  jbyte* bufPtr = env->GetByteArrayElements(array, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  ps_err_e ret = ps_pread((struct ps_prochandle*) p_ps_prochandle,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
                       (psaddr_t)address, bufPtr, (size_t)numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  if (ret != PS_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    // part of the class sharing workaround. try shared heap area
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    int classes_jsa_fd = env->GetIntField(this_obj, classes_jsa_fd_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
    if (classes_jsa_fd != -1 && address != (jlong)0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
      print_debug("read failed at 0x%lx, attempting shared heap area\n", (long) address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
      struct FileMapHeader* pheader = (struct FileMapHeader*) env->GetLongField(this_obj, p_file_map_header_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
      // walk through the shared mappings -- we just have 4 of them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
      // so, linear walking is okay.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
      for (int m = 0; m < NUM_SHARED_MAPS; m++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
        // We can skip the non-read-only maps. These are mapped as MAP_PRIVATE
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
        // and hence will be read by libproc. Besides, the file copy may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
        // stale because the process might have modified those pages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
        if (pheader->_space[m]._read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
          jlong baseAddress = (jlong) (uintptr_t) pheader->_space[m]._base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
          size_t usedSize = pheader->_space[m]._used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
          if (address >= baseAddress && address < (baseAddress + usedSize)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
            // the given address falls in this shared heap area
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
            print_debug("found shared map at 0x%lx\n", (long) baseAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
            // If more data is asked than actually mapped from file, we need to zero fill
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
            // till the end-of-page boundary. But, java array new does that for us. we just
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
            // need to read as much as data available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
#define MIN2(x, y) (((x) < (y))? (x) : (y))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
            jlong diff = address - baseAddress;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
            jlong bytesToRead = MIN2(numBytes, usedSize - diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
            off_t offset = pheader->_space[m]._file_offset  + off_t(diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
            ssize_t bytesRead = pread(classes_jsa_fd, bufPtr, bytesToRead, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
            if (bytesRead != bytesToRead) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
              env->ReleaseByteArrayElements(array, bufPtr, JNI_ABORT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
              print_debug("shared map read failed\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
              return jbyteArray(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
              print_debug("shared map read succeeded\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
              env->ReleaseByteArrayElements(array, bufPtr, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
              return array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
          } // is in current map
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
        } // is read only map
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      } // for shared maps
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    } // classes_jsa_fd != -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
    env->ReleaseByteArrayElements(array, bufPtr, JNI_ABORT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    return jbyteArray(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    env->ReleaseByteArrayElements(array, bufPtr, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
    return array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
 * Method:      writeBytesToProcess0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
 * Signature:   (JJ[B)V
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
 * Description: write bytes into debugger process
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_writeBytesToProcess0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
  (JNIEnv *env, jobject this_obj, jlong address, jlong numBytes, jbyteArray data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
  jbyte* ptr = env->GetByteArrayElements(data, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  if (ps_pwrite((struct ps_prochandle*) p_ps_prochandle, address, ptr, numBytes) != PS_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
     env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
     THROW_NEW_DEBUGGER_EXCEPTION("Process write failed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
 * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
 * Method:    suspend0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
 * Signature: ()V
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_suspend0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  (JNIEnv *env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  // for now don't check return value. revisit this again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
  Pstop((struct ps_prochandle*) p_ps_prochandle, 1000);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
 * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
 * Method:    resume0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
 * Signature: ()V
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_resume0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  (JNIEnv *env, jobject this_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  jlong p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  // for now don't check return value. revisit this again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  Psetrun((struct ps_prochandle*) p_ps_prochandle, 0, PRCFAULT|PRSTOP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  * Method:      lookupByName0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  * Signature:   (Ljava/lang/String;Ljava/lang/String;)J
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  * Description: symbol lookup by name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByName0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
   (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
   jlong p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
   p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
   jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
   const char* objectName_cstr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
   if (objectName != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
     objectName_cstr = env->GetStringUTFChars(objectName, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
     CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
   } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
     objectName_cstr = PR_OBJ_EVERY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
   const char* symbolName_cstr = env->GetStringUTFChars(symbolName, &isCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
   CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
   psaddr_t symbol_addr = (psaddr_t) 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
   ps_pglobal_lookup((struct ps_prochandle*) p_ps_prochandle,  objectName_cstr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
                    symbolName_cstr, &symbol_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
   if (symbol_addr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
      print_debug("lookup for %s in %s failed\n", symbolName_cstr, objectName_cstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
   if (objectName_cstr != PR_OBJ_EVERY) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
     env->ReleaseStringUTFChars(objectName, objectName_cstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
   env->ReleaseStringUTFChars(symbolName, symbolName_cstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
   return (jlong) (uintptr_t) symbol_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
 * Method:      lookupByAddress0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
 * Signature:   (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
 * Description: lookup symbol name for a given address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByAddress0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
   (JNIEnv *env, jobject this_obj, jlong address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
   jlong p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
   p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
   char nameBuf[SYMBOL_BUF_SIZE + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
   GElf_Sym sym;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
   int res = Plookup_by_addr((struct ps_prochandle*) p_ps_prochandle, (uintptr_t) address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
                                 nameBuf, sizeof(nameBuf), &sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
   if (res != 0) { // failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
   jstring resSym = env->NewStringUTF(nameBuf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
   CHECK_EXCEPTION_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
   return env->CallObjectMethod(this_obj, createClosestSymbol_ID, resSym, (address - sym.st_value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
 * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
 * Method:    demangle0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_demangle0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
  (JNIEnv *env, jobject this_object, jstring name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  jboolean isCopy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  const char* ptr = env->GetStringUTFChars(name, &isCopy);
26410
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
  1259
  CHECK_EXCEPTION_(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  char  buf[2*SYMBOL_BUF_SIZE + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  jstring res = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  if (cplus_demangle((char*) ptr, buf, sizeof(buf)) != DEMANGLE_ESPACE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    res = env->NewStringUTF(buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    res = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  env->ReleaseStringUTFChars(name, ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1271
#ifndef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1272
// Determine if the OS we're running on has the newer version
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1273
// of libproc's Pstack_iter.
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1274
//
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1275
// Set env var PSTACK_ITER_DEBUG=true to debug this logic.
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1276
// Set env var PSTACK_ITER_DEBUG_RELEASE to simulate a 'release' value.
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1277
// Set env var PSTACK_ITER_DEBUG_VERSION to simulate a 'version' value.
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1278
//
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1279
// frankenputer 'uname -r -v': 5.10 Generic_141445-09
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1280
// jurassic 'uname -r -v':     5.11 snv_164
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1281
// lonepeak 'uname -r -v':     5.11 snv_127
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1282
//
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1283
static void set_has_newer_Pstack_iter(JNIEnv *env) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1284
  static bool done_set = false;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1285
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1286
  if (done_set) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1287
    // already set has_newer_Pstack_iter
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1288
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1289
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1290
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1291
  struct utsname name;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1292
  if (uname(&name) == -1) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1293
    THROW_NEW_DEBUGGER_EXCEPTION("uname() failed!");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1294
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1295
  dprintf_2("release='%s'  version='%s'\n", name.release, name.version);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1296
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1297
  if (_Pstack_iter_debug) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1298
    char *override = getenv("PSTACK_ITER_DEBUG_RELEASE");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1299
    if (override != NULL) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1300
      strncpy(name.release, override, SYS_NMLN - 1);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1301
      name.release[SYS_NMLN - 2] = '\0';
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1302
      dprintf_2("overriding with release='%s'\n", name.release);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1303
    }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1304
    override = getenv("PSTACK_ITER_DEBUG_VERSION");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1305
    if (override != NULL) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1306
      strncpy(name.version, override, SYS_NMLN - 1);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1307
      name.version[SYS_NMLN - 2] = '\0';
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1308
      dprintf_2("overriding with version='%s'\n", name.version);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1309
    }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1310
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1311
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1312
  // the major number corresponds to the old SunOS major number
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1313
  int major = atoi(name.release);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1314
  if (major >= 6) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1315
    dprintf_2("release is SunOS 6 or later\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1316
    has_newer_Pstack_iter = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1317
    done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1318
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1319
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1320
  if (major < 5) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1321
    dprintf_2("release is SunOS 4 or earlier\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1322
    done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1323
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1324
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1325
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1326
  // some SunOS 5.* build so now check for Solaris versions
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1327
  char *dot = strchr(name.release, '.');
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1328
  int minor = 0;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1329
  if (dot != NULL) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1330
    // release is major.minor format
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1331
    *dot = NULL;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1332
    minor = atoi(dot + 1);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1333
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1334
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1335
  if (minor <= 10) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1336
    dprintf_2("release is Solaris 10 or earlier\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1337
    done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1338
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1339
  } else if (minor >= 12) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1340
    dprintf_2("release is Solaris 12 or later\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1341
    has_newer_Pstack_iter = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1342
    done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1343
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1344
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1345
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1346
  // some Solaris 11 build so now check for internal build numbers
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1347
  if (strncmp(name.version, "snv_", 4) != 0) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1348
    dprintf_2("release is Solaris 11 post-GA or later\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1349
    has_newer_Pstack_iter = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1350
    done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1351
    return;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1352
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1353
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1354
  // version begins with "snv_" so a pre-GA build of Solaris 11
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1355
  int build = atoi(&name.version[4]);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1356
  if (build >= 159) {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1357
    dprintf_2("release is Nevada-B159 or later\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1358
    has_newer_Pstack_iter = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1359
  } else {
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1360
    dprintf_2("release is Nevada-B158 or earlier\n");
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1361
  }
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1362
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1363
  done_set = true;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1364
}
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1365
#endif // !SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1366
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
 * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
 * Method:      initIDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
 * Signature:   ()V
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
 * Description: get JNI ids for fields and methods of ProcDebuggerLocal class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_initIDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
  (JNIEnv *env, jclass clazz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
  _libsaproc_debug = getenv("LIBSAPROC_DEBUG") != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  if (_libsaproc_debug) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
     // propagate debug mode to libproc.so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
     static const char* var = "LIBPROC_DEBUG=1";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
     putenv((char*)var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
  void* libproc_handle = dlopen("libproc.so", RTLD_LAZY | RTLD_GLOBAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
  if (libproc_handle == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
     THROW_NEW_DEBUGGER_EXCEPTION("can't load libproc.so, if you are using Solaris 5.7 or below, copy libproc.so from 5.8!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
9407
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1386
#ifndef SOLARIS_11_B159_OR_LATER
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1387
  _Pstack_iter_debug = getenv("PSTACK_ITER_DEBUG") != NULL;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1388
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1389
  set_has_newer_Pstack_iter(env);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1390
  CHECK_EXCEPTION;
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1391
  dprintf_2("has_newer_Pstack_iter=%d\n", has_newer_Pstack_iter);
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1392
#endif
c985006c2940 7028172: 3/4 SA needs to adapt to Solaris libproc change made in 6748307
dcubed
parents: 5547
diff changeset
  1393
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  p_ps_prochandle_ID = env->GetFieldID(clazz, "p_ps_prochandle", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  libthread_db_handle_ID = env->GetFieldID(clazz, "libthread_db_handle", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  p_td_thragent_t_ID = env->GetFieldID(clazz, "p_td_thragent_t", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  p_td_init_ID = env->GetFieldID(clazz, "p_td_init", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  p_td_ta_new_ID = env->GetFieldID(clazz, "p_td_ta_new", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  p_td_ta_delete_ID = env->GetFieldID(clazz, "p_td_ta_delete", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  p_td_ta_thr_iter_ID = env->GetFieldID(clazz, "p_td_ta_thr_iter", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  p_td_thr_get_info_ID = env->GetFieldID(clazz, "p_td_thr_get_info", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
  p_td_ta_map_id2thr_ID = env->GetFieldID(clazz, "p_td_ta_map_id2thr", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  p_td_thr_getgregs_ID = env->GetFieldID(clazz, "p_td_thr_getgregs", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  getThreadForThreadId_ID = env->GetMethodID(clazz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
                            "getThreadForThreadId", "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  pcRegIndex_ID = env->GetFieldID(clazz, "pcRegIndex", "I");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
  fpRegIndex_ID = env->GetFieldID(clazz, "fpRegIndex", "I");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  createSenderFrame_ID = env->GetMethodID(clazz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
                            "createSenderFrame", "(Lsun/jvm/hotspot/debugger/proc/ProcCFrame;JJ)Lsun/jvm/hotspot/debugger/proc/ProcCFrame;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  createLoadObject_ID = env->GetMethodID(clazz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
                            "createLoadObject", "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  createClosestSymbol_ID = env->GetMethodID(clazz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
                            "createClosestSymbol", "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
26410
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
  1446
  jclass list_clazz = env->FindClass("java/util/List");
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
  1447
  CHECK_EXCEPTION;
a34c8032e674 8031583: warnings from b03 for hotspot/agent/src/os/solaris/proc: JNI exception pending
dsamersoff
parents: 25945
diff changeset
  1448
  listAdd_ID = env->GetMethodID(list_clazz, "add", "(Ljava/lang/Object;)Z");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  // part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  classes_jsa_fd_ID = env->GetFieldID(clazz, "classes_jsa_fd", "I");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  p_file_map_header_ID = env->GetFieldID(clazz, "p_file_map_header", "J");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  CHECK_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
}