1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include <jni.h>
  26 #include "libproc.h"
  27 
  28 #include <elf.h>
  29 #include <sys/types.h>
  30 #include <sys/stat.h>
  31 #include <fcntl.h>
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <limits.h>
  35 
  36 #if defined(x86_64) && !defined(amd64)
  37 #define amd64 1
  38 #endif
  39 
  40 #ifdef i386
  41 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
  42 #endif
  43 
  44 #ifdef amd64
  45 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
  46 #endif
  47 
  48 #if defined(sparc) || defined(sparcv9)
  49 #include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h"
  50 #endif
  51 
  52 #ifdef ppc64
  53 #include "sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext.h"
  54 #endif
  55 
  56 #ifdef aarch64
  57 #include "sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext.h"
  58 #endif
  59 
  60 static jfieldID p_ps_prochandle_ID = 0;
  61 static jfieldID threadList_ID = 0;
  62 static jfieldID loadObjectList_ID = 0;
  63 
  64 static jmethodID createClosestSymbol_ID = 0;
  65 static jmethodID createLoadObject_ID = 0;
  66 static jmethodID getThreadForThreadId_ID = 0;
  67 static jmethodID listAdd_ID = 0;
  68 
  69 #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
  70 #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
  71 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
  72 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
  73 
  74 void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
  75   jclass clazz;
  76   clazz = (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException");
  77   CHECK_EXCEPTION;
  78   (*env)->ThrowNew(env, clazz, errMsg);
  79 }
  80 
  81 struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
  82   jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
  83   return (struct ps_prochandle*)(intptr_t)ptr;
  84 }
  85 
  86 /*
  87  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
  88  * Method:    init0
  89  * Signature: ()V
  90  */
  91 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_init0
  92   (JNIEnv *env, jclass cls) {
  93   jclass listClass;
  94 
  95   if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
  96      THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
  97   }
  98 
  99   // fields we use
 100   p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
 101   CHECK_EXCEPTION;
 102   threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;");
 103   CHECK_EXCEPTION;
 104   loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
 105   CHECK_EXCEPTION;
 106 
 107   // methods we use
 108   createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
 109                     "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
 110   CHECK_EXCEPTION;
 111   createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
 112                     "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
 113   CHECK_EXCEPTION;
 114   getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId",
 115                                                      "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
 116   CHECK_EXCEPTION;
 117   // java.util.List method we call
 118   listClass = (*env)->FindClass(env, "java/util/List");
 119   CHECK_EXCEPTION;
 120   listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
 121   CHECK_EXCEPTION;
 122 }
 123 
 124 JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getAddressSize
 125   (JNIEnv *env, jclass cls)
 126 {
 127 #ifdef _LP64
 128  return 8;
 129 #else
 130  return 4;
 131 #endif
 132 
 133 }
 134 
 135 
 136 static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
 137   int n = 0, i = 0;
 138 
 139   // add threads
 140   n = get_num_threads(ph);
 141   for (i = 0; i < n; i++) {
 142     jobject thread;
 143     jobject threadList;
 144     lwpid_t lwpid;
 145 
 146     lwpid = get_lwp_id(ph, i);
 147     thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID,
 148                                       (jlong)lwpid);
 149     CHECK_EXCEPTION;
 150     threadList = (*env)->GetObjectField(env, this_obj, threadList_ID);
 151     CHECK_EXCEPTION;
 152     (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread);
 153     CHECK_EXCEPTION;
 154   }
 155 
 156   // add load objects
 157   n = get_num_libs(ph);
 158   for (i = 0; i < n; i++) {
 159      uintptr_t base;
 160      const char* name;
 161      jobject loadObject;
 162      jobject loadObjectList;
 163      jstring str;
 164 
 165      base = get_lib_base(ph, i);
 166      name = get_lib_name(ph, i);
 167 
 168      str = (*env)->NewStringUTF(env, name);
 169      CHECK_EXCEPTION;
 170      loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID, str, (jlong)0, (jlong)base);
 171      CHECK_EXCEPTION;
 172      loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
 173      CHECK_EXCEPTION;
 174      (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
 175      CHECK_EXCEPTION;
 176   }
 177 }
 178 
 179 
 180 /*
 181  * Verify that a named ELF binary file (core or executable) has the same
 182  * bitness as ourselves.
 183  * Throw an exception if there is a mismatch or other problem.
 184  *
 185  * If we proceed using a mismatched debugger/debuggee, the best to hope
 186  * for is a missing symbol, the worst is a crash searching for debug symbols.
 187  */
 188 void verifyBitness(JNIEnv *env, const char *binaryName) {
 189   int fd = open(binaryName, O_RDONLY);
 190   if (fd < 0) {
 191     THROW_NEW_DEBUGGER_EXCEPTION("cannot open binary file");
 192   }
 193   unsigned char elf_ident[EI_NIDENT];
 194   int i = read(fd, &elf_ident, sizeof(elf_ident));
 195   close(fd);
 196 
 197   if (i < 0) {
 198     THROW_NEW_DEBUGGER_EXCEPTION("cannot read binary file");
 199   }
 200 #ifndef _LP64
 201   if (elf_ident[EI_CLASS] == ELFCLASS64) {
 202     THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use 64-bit java for debugger");
 203   }
 204 #else
 205   if (elf_ident[EI_CLASS] != ELFCLASS64) {
 206     THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 32 bit, use 32 bit java for debugger");
 207   }
 208 #endif
 209 }
 210 
 211 
 212 /*
 213  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 214  * Method:    attach0
 215  * Signature: (I)V
 216  */
 217 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
 218   (JNIEnv *env, jobject this_obj, jint jpid) {
 219 
 220   // For bitness checking, locate binary at /proc/jpid/exe
 221   char buf[PATH_MAX];
 222   snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
 223   verifyBitness(env, (char *) &buf);
 224   CHECK_EXCEPTION;
 225 
 226   struct ps_prochandle* ph;
 227   if ( (ph = Pgrab(jpid)) == NULL) {
 228     THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
 229   }
 230   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
 231   fillThreadsAndLoadObjects(env, this_obj, ph);
 232 }
 233 
 234 /*
 235  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 236  * Method:    attach0
 237  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 238  */
 239 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
 240   (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
 241   const char *execName_cstr;
 242   const char *coreName_cstr;
 243   jboolean isCopy;
 244   struct ps_prochandle* ph;
 245 
 246   execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
 247   CHECK_EXCEPTION;
 248   coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
 249   CHECK_EXCEPTION;
 250 
 251   verifyBitness(env, execName_cstr);
 252   CHECK_EXCEPTION;
 253 
 254   if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
 255     (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
 256     (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
 257     THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
 258   }
 259   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
 260   (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
 261   (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
 262   fillThreadsAndLoadObjects(env, this_obj, ph);
 263 }
 264 
 265 /*
 266  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 267  * Method:    detach0
 268  * Signature: ()V
 269  */
 270 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_detach0
 271   (JNIEnv *env, jobject this_obj) {
 272   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
 273   if (ph != NULL) {
 274      Prelease(ph);
 275   }
 276 }
 277 
 278 /*
 279  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 280  * Method:    lookupByName0
 281  * Signature: (Ljava/lang/String;Ljava/lang/String;)J
 282  */
 283 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByName0
 284   (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
 285   const char *objectName_cstr, *symbolName_cstr;
 286   jlong addr;
 287   jboolean isCopy;
 288   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
 289 
 290   objectName_cstr = NULL;
 291   if (objectName != NULL) {
 292     objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
 293     CHECK_EXCEPTION_(0);
 294   }
 295   symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
 296   CHECK_EXCEPTION_(0);
 297 
 298   addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
 299 
 300   if (objectName_cstr != NULL) {
 301     (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
 302   }
 303   (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
 304   return addr;
 305 }
 306 
 307 /*
 308  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 309  * Method:    lookupByAddress0
 310  * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
 311  */
 312 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_lookupByAddress0
 313   (JNIEnv *env, jobject this_obj, jlong addr) {
 314   uintptr_t offset;
 315   jobject obj;
 316   jstring str;
 317   const char* sym = NULL;
 318 
 319   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
 320   sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
 321   if (sym == NULL) return 0;
 322   str = (*env)->NewStringUTF(env, sym);
 323   CHECK_EXCEPTION_(NULL);
 324   obj = (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID, str, (jlong)offset);
 325   CHECK_EXCEPTION_(NULL);
 326   return obj;
 327 }
 328 
 329 /*
 330  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 331  * Method:    readBytesFromProcess0
 332  * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
 333  */
 334 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
 335   (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
 336 
 337   jboolean isCopy;
 338   jbyteArray array;
 339   jbyte *bufPtr;
 340   ps_err_e err;
 341 
 342   array = (*env)->NewByteArray(env, numBytes);
 343   CHECK_EXCEPTION_(0);
 344   bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
 345   CHECK_EXCEPTION_(0);
 346 
 347   err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
 348   (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
 349   return (err == PS_OK)? array : 0;
 350 }
 351 
 352 #if defined(i386) || defined(amd64) || defined(sparc) || defined(sparcv9) | defined(ppc64) || defined(aarch64)
 353 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
 354   (JNIEnv *env, jobject this_obj, jint lwp_id) {
 355 
 356   struct user_regs_struct gregs;
 357   jboolean isCopy;
 358   jlongArray array;
 359   jlong *regs;
 360   int i;
 361 
 362   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
 363   if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
 364      THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
 365   }
 366 
 367 #undef NPRGREG
 368 #ifdef i386
 369 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
 370 #endif
 371 #ifdef amd64
 372 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
 373 #endif
 374 #ifdef aarch64
 375 #define NPRGREG 33
 376 #endif
 377 #if defined(sparc) || defined(sparcv9)
 378 #define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG
 379 #endif
 380 #ifdef ppc64
 381 #define NPRGREG sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_NPRGREG
 382 #endif
 383 
 384 
 385   array = (*env)->NewLongArray(env, NPRGREG);
 386   CHECK_EXCEPTION_(0);
 387   regs = (*env)->GetLongArrayElements(env, array, &isCopy);
 388 
 389 #undef REG_INDEX
 390 
 391 #ifdef i386
 392 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
 393 
 394   regs[REG_INDEX(GS)]  = (uintptr_t) gregs.xgs;
 395   regs[REG_INDEX(FS)]  = (uintptr_t) gregs.xfs;
 396   regs[REG_INDEX(ES)]  = (uintptr_t) gregs.xes;
 397   regs[REG_INDEX(DS)]  = (uintptr_t) gregs.xds;
 398   regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
 399   regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;
 400   regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp;
 401   regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp;
 402   regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx;
 403   regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx;
 404   regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx;
 405   regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax;
 406   regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
 407   regs[REG_INDEX(CS)]  = (uintptr_t) gregs.xcs;
 408   regs[REG_INDEX(SS)]  = (uintptr_t) gregs.xss;
 409 
 410 #endif /* i386 */
 411 
 412 #ifdef amd64
 413 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
 414 
 415   regs[REG_INDEX(R15)] = gregs.r15;
 416   regs[REG_INDEX(R14)] = gregs.r14;
 417   regs[REG_INDEX(R13)] = gregs.r13;
 418   regs[REG_INDEX(R12)] = gregs.r12;
 419   regs[REG_INDEX(RBP)] = gregs.rbp;
 420   regs[REG_INDEX(RBX)] = gregs.rbx;
 421   regs[REG_INDEX(R11)] = gregs.r11;
 422   regs[REG_INDEX(R10)] = gregs.r10;
 423   regs[REG_INDEX(R9)] = gregs.r9;
 424   regs[REG_INDEX(R8)] = gregs.r8;
 425   regs[REG_INDEX(RAX)] = gregs.rax;
 426   regs[REG_INDEX(RCX)] = gregs.rcx;
 427   regs[REG_INDEX(RDX)] = gregs.rdx;
 428   regs[REG_INDEX(RSI)] = gregs.rsi;
 429   regs[REG_INDEX(RDI)] = gregs.rdi;
 430   regs[REG_INDEX(RIP)] = gregs.rip;
 431   regs[REG_INDEX(CS)] = gregs.cs;
 432   regs[REG_INDEX(RSP)] = gregs.rsp;
 433   regs[REG_INDEX(SS)] = gregs.ss;
 434   regs[REG_INDEX(FSBASE)] = gregs.fs_base;
 435   regs[REG_INDEX(GSBASE)] = gregs.gs_base;
 436   regs[REG_INDEX(DS)] = gregs.ds;
 437   regs[REG_INDEX(ES)] = gregs.es;
 438   regs[REG_INDEX(FS)] = gregs.fs;
 439   regs[REG_INDEX(GS)] = gregs.gs;
 440 
 441 #endif /* amd64 */
 442 
 443 #if defined(sparc) || defined(sparcv9)
 444 
 445 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg
 446 
 447 #ifdef _LP64
 448   regs[REG_INDEX(R_PSR)] = gregs.tstate;
 449   regs[REG_INDEX(R_PC)]  = gregs.tpc;
 450   regs[REG_INDEX(R_nPC)] = gregs.tnpc;
 451   regs[REG_INDEX(R_Y)]   = gregs.y;
 452 #else
 453   regs[REG_INDEX(R_PSR)] = gregs.psr;
 454   regs[REG_INDEX(R_PC)]  = gregs.pc;
 455   regs[REG_INDEX(R_nPC)] = gregs.npc;
 456   regs[REG_INDEX(R_Y)]   = gregs.y;
 457 #endif
 458   regs[REG_INDEX(R_G0)]  =            0 ;
 459   regs[REG_INDEX(R_G1)]  = gregs.u_regs[0];
 460   regs[REG_INDEX(R_G2)]  = gregs.u_regs[1];
 461   regs[REG_INDEX(R_G3)]  = gregs.u_regs[2];
 462   regs[REG_INDEX(R_G4)]  = gregs.u_regs[3];
 463   regs[REG_INDEX(R_G5)]  = gregs.u_regs[4];
 464   regs[REG_INDEX(R_G6)]  = gregs.u_regs[5];
 465   regs[REG_INDEX(R_G7)]  = gregs.u_regs[6];
 466   regs[REG_INDEX(R_O0)]  = gregs.u_regs[7];
 467   regs[REG_INDEX(R_O1)]  = gregs.u_regs[8];
 468   regs[REG_INDEX(R_O2)]  = gregs.u_regs[ 9];
 469   regs[REG_INDEX(R_O3)]  = gregs.u_regs[10];
 470   regs[REG_INDEX(R_O4)]  = gregs.u_regs[11];
 471   regs[REG_INDEX(R_O5)]  = gregs.u_regs[12];
 472   regs[REG_INDEX(R_O6)]  = gregs.u_regs[13];
 473   regs[REG_INDEX(R_O7)]  = gregs.u_regs[14];
 474 #endif /* sparc */
 475 
 476 #if defined(aarch64)
 477 
 478 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_##reg
 479 
 480   {
 481     int i;
 482     for (i = 0; i < 31; i++)
 483       regs[i] = gregs.regs[i];
 484     regs[REG_INDEX(SP)] = gregs.sp;
 485     regs[REG_INDEX(PC)] = gregs.pc;
 486   }
 487 #endif /* aarch64 */
 488 
 489 #ifdef ppc64
 490 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_##reg
 491 
 492   regs[REG_INDEX(LR)] = gregs.link;
 493   regs[REG_INDEX(NIP)] = gregs.nip;
 494   regs[REG_INDEX(R0)]  = gregs.gpr[0];
 495   regs[REG_INDEX(R1)]  = gregs.gpr[1];
 496   regs[REG_INDEX(R2)]  = gregs.gpr[2];
 497   regs[REG_INDEX(R3)]  = gregs.gpr[3];
 498   regs[REG_INDEX(R4)]  = gregs.gpr[4];
 499   regs[REG_INDEX(R5)]  = gregs.gpr[5];
 500   regs[REG_INDEX(R6)]  = gregs.gpr[6];
 501   regs[REG_INDEX(R7)]  = gregs.gpr[7];
 502   regs[REG_INDEX(R8)]  = gregs.gpr[8];
 503   regs[REG_INDEX(R9)]  = gregs.gpr[9];
 504   regs[REG_INDEX(R10)] = gregs.gpr[10];
 505   regs[REG_INDEX(R11)] = gregs.gpr[11];
 506   regs[REG_INDEX(R12)] = gregs.gpr[12];
 507   regs[REG_INDEX(R13)] = gregs.gpr[13];
 508   regs[REG_INDEX(R14)] = gregs.gpr[14];
 509   regs[REG_INDEX(R15)] = gregs.gpr[15];
 510   regs[REG_INDEX(R16)] = gregs.gpr[16];
 511   regs[REG_INDEX(R17)] = gregs.gpr[17];
 512   regs[REG_INDEX(R18)] = gregs.gpr[18];
 513   regs[REG_INDEX(R19)] = gregs.gpr[19];
 514   regs[REG_INDEX(R20)] = gregs.gpr[20];
 515   regs[REG_INDEX(R21)] = gregs.gpr[21];
 516   regs[REG_INDEX(R22)] = gregs.gpr[22];
 517   regs[REG_INDEX(R23)] = gregs.gpr[23];
 518   regs[REG_INDEX(R24)] = gregs.gpr[24];
 519   regs[REG_INDEX(R25)] = gregs.gpr[25];
 520   regs[REG_INDEX(R26)] = gregs.gpr[26];
 521   regs[REG_INDEX(R27)] = gregs.gpr[27];
 522   regs[REG_INDEX(R28)] = gregs.gpr[28];
 523   regs[REG_INDEX(R29)] = gregs.gpr[29];
 524   regs[REG_INDEX(R30)] = gregs.gpr[30];
 525   regs[REG_INDEX(R31)] = gregs.gpr[31];
 526 
 527 #endif
 528 
 529   (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
 530   return array;
 531 }
 532 #endif