< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.cpp

Print this page

 43 #if defined(i386) && !defined(i586)
 44 #define i586 1
 45 #endif
 46 
 47 #ifdef i586
 48 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
 49 #endif
 50 
 51 #ifdef amd64
 52 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
 53 #endif
 54 
 55 #if defined(ppc64) || defined(ppc64le)
 56 #include "sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext.h"
 57 #endif
 58 
 59 #ifdef aarch64
 60 #include "sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext.h"
 61 #endif
 62 




 63 class AutoJavaString {
 64   JNIEnv* m_env;
 65   jstring m_str;
 66   const char* m_buf;
 67 
 68 public:
 69   // check env->ExceptionOccurred() after ctor
 70   AutoJavaString(JNIEnv* env, jstring str)
 71     : m_env(env), m_str(str), m_buf(str == NULL ? NULL : env->GetStringUTFChars(str, NULL)) {
 72   }
 73 
 74   ~AutoJavaString() {
 75     if (m_buf) {
 76       m_env->ReleaseStringUTFChars(m_str, m_buf);
 77     }
 78   }
 79 
 80   operator const char* () const {
 81     return m_buf;
 82   }

391  */
392 extern "C"
393 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
394   (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
395 
396   jboolean isCopy;
397   jbyteArray array;
398   jbyte *bufPtr;
399   ps_err_e err;
400 
401   array = env->NewByteArray(numBytes);
402   CHECK_EXCEPTION_(0);
403   bufPtr = env->GetByteArrayElements(array, &isCopy);
404   CHECK_EXCEPTION_(0);
405 
406   err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
407   env->ReleaseByteArrayElements(array, bufPtr, 0);
408   return (err == PS_OK)? array : 0;
409 }
410 
411 #if defined(i586) || defined(amd64) || defined(ppc64) || defined(ppc64le) || defined(aarch64)
412 extern "C"
413 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
414   (JNIEnv *env, jobject this_obj, jint lwp_id) {
415 
416   struct user_regs_struct gregs;
417   jboolean isCopy;
418   jlongArray array;
419   jlong *regs;
420   int i;
421 
422   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
423   if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
424     // This is not considered fatal and does happen on occassion, usually with an
425     // ESRCH error. The root cause is not fully understood, but by ignoring this error
426     // and returning NULL, stacking walking code will get null registers and fallback
427     // to using the "last java frame" if setup.
428     fprintf(stdout, "WARNING: getThreadIntegerRegisterSet0: get_lwp_regs failed for lwp (%d)\n", lwp_id);
429     fflush(stdout);
430     return NULL;
431   }
432 
433 #undef NPRGREG
434 #ifdef i586
435 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
436 #endif
437 #ifdef amd64
438 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
439 #endif
440 #ifdef aarch64
441 #define NPRGREG sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_NPRGREG
442 #endif



443 #if defined(ppc64) || defined(ppc64le)
444 #define NPRGREG sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_NPRGREG
445 #endif
446 
447 
448   array = env->NewLongArray(NPRGREG);
449   CHECK_EXCEPTION_(0);
450   regs = env->GetLongArrayElements(array, &isCopy);
451 
452 #undef REG_INDEX
453 
454 #ifdef i586
455 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
456 
457   regs[REG_INDEX(GS)]  = (uintptr_t) gregs.xgs;
458   regs[REG_INDEX(FS)]  = (uintptr_t) gregs.xfs;
459   regs[REG_INDEX(ES)]  = (uintptr_t) gregs.xes;
460   regs[REG_INDEX(DS)]  = (uintptr_t) gregs.xds;
461   regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
462   regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;

499   regs[REG_INDEX(DS)] = gregs.ds;
500   regs[REG_INDEX(ES)] = gregs.es;
501   regs[REG_INDEX(FS)] = gregs.fs;
502   regs[REG_INDEX(GS)] = gregs.gs;
503 
504 #endif /* amd64 */
505 
506 #if defined(aarch64)
507 
508 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_##reg
509 
510   {
511     int i;
512     for (i = 0; i < 31; i++)
513       regs[i] = gregs.regs[i];
514     regs[REG_INDEX(SP)] = gregs.sp;
515     regs[REG_INDEX(PC)] = gregs.pc;
516   }
517 #endif /* aarch64 */
518 






































519 #if defined(ppc64) || defined(ppc64le)
520 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_##reg
521 
522   regs[REG_INDEX(LR)] = gregs.link;
523   regs[REG_INDEX(NIP)] = gregs.nip;
524   regs[REG_INDEX(R0)]  = gregs.gpr[0];
525   regs[REG_INDEX(R1)]  = gregs.gpr[1];
526   regs[REG_INDEX(R2)]  = gregs.gpr[2];
527   regs[REG_INDEX(R3)]  = gregs.gpr[3];
528   regs[REG_INDEX(R4)]  = gregs.gpr[4];
529   regs[REG_INDEX(R5)]  = gregs.gpr[5];
530   regs[REG_INDEX(R6)]  = gregs.gpr[6];
531   regs[REG_INDEX(R7)]  = gregs.gpr[7];
532   regs[REG_INDEX(R8)]  = gregs.gpr[8];
533   regs[REG_INDEX(R9)]  = gregs.gpr[9];
534   regs[REG_INDEX(R10)] = gregs.gpr[10];
535   regs[REG_INDEX(R11)] = gregs.gpr[11];
536   regs[REG_INDEX(R12)] = gregs.gpr[12];
537   regs[REG_INDEX(R13)] = gregs.gpr[13];
538   regs[REG_INDEX(R14)] = gregs.gpr[14];

 43 #if defined(i386) && !defined(i586)
 44 #define i586 1
 45 #endif
 46 
 47 #ifdef i586
 48 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
 49 #endif
 50 
 51 #ifdef amd64
 52 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
 53 #endif
 54 
 55 #if defined(ppc64) || defined(ppc64le)
 56 #include "sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext.h"
 57 #endif
 58 
 59 #ifdef aarch64
 60 #include "sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext.h"
 61 #endif
 62 
 63 #ifdef riscv64
 64 #include "sun_jvm_hotspot_debugger_riscv64_RISCV64ThreadContext.h"
 65 #endif
 66 
 67 class AutoJavaString {
 68   JNIEnv* m_env;
 69   jstring m_str;
 70   const char* m_buf;
 71 
 72 public:
 73   // check env->ExceptionOccurred() after ctor
 74   AutoJavaString(JNIEnv* env, jstring str)
 75     : m_env(env), m_str(str), m_buf(str == NULL ? NULL : env->GetStringUTFChars(str, NULL)) {
 76   }
 77 
 78   ~AutoJavaString() {
 79     if (m_buf) {
 80       m_env->ReleaseStringUTFChars(m_str, m_buf);
 81     }
 82   }
 83 
 84   operator const char* () const {
 85     return m_buf;
 86   }

395  */
396 extern "C"
397 JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_readBytesFromProcess0
398   (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
399 
400   jboolean isCopy;
401   jbyteArray array;
402   jbyte *bufPtr;
403   ps_err_e err;
404 
405   array = env->NewByteArray(numBytes);
406   CHECK_EXCEPTION_(0);
407   bufPtr = env->GetByteArrayElements(array, &isCopy);
408   CHECK_EXCEPTION_(0);
409 
410   err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
411   env->ReleaseByteArrayElements(array, bufPtr, 0);
412   return (err == PS_OK)? array : 0;
413 }
414 
415 #if defined(i586) || defined(amd64) || defined(ppc64) || defined(ppc64le) || defined(aarch64) || defined(riscv64)
416 extern "C"
417 JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_getThreadIntegerRegisterSet0
418   (JNIEnv *env, jobject this_obj, jint lwp_id) {
419 
420   struct user_regs_struct gregs;
421   jboolean isCopy;
422   jlongArray array;
423   jlong *regs;
424   int i;
425 
426   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
427   if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
428     // This is not considered fatal and does happen on occassion, usually with an
429     // ESRCH error. The root cause is not fully understood, but by ignoring this error
430     // and returning NULL, stacking walking code will get null registers and fallback
431     // to using the "last java frame" if setup.
432     fprintf(stdout, "WARNING: getThreadIntegerRegisterSet0: get_lwp_regs failed for lwp (%d)\n", lwp_id);
433     fflush(stdout);
434     return NULL;
435   }
436 
437 #undef NPRGREG
438 #ifdef i586
439 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
440 #endif
441 #ifdef amd64
442 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
443 #endif
444 #ifdef aarch64
445 #define NPRGREG sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_NPRGREG
446 #endif
447 #ifdef riscv64
448 #define NPRGREG sun_jvm_hotspot_debugger_riscv64_RISCV64ThreadContext_NPRGREG
449 #endif
450 #if defined(ppc64) || defined(ppc64le)
451 #define NPRGREG sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_NPRGREG
452 #endif
453 
454 
455   array = env->NewLongArray(NPRGREG);
456   CHECK_EXCEPTION_(0);
457   regs = env->GetLongArrayElements(array, &isCopy);
458 
459 #undef REG_INDEX
460 
461 #ifdef i586
462 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
463 
464   regs[REG_INDEX(GS)]  = (uintptr_t) gregs.xgs;
465   regs[REG_INDEX(FS)]  = (uintptr_t) gregs.xfs;
466   regs[REG_INDEX(ES)]  = (uintptr_t) gregs.xes;
467   regs[REG_INDEX(DS)]  = (uintptr_t) gregs.xds;
468   regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
469   regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;

506   regs[REG_INDEX(DS)] = gregs.ds;
507   regs[REG_INDEX(ES)] = gregs.es;
508   regs[REG_INDEX(FS)] = gregs.fs;
509   regs[REG_INDEX(GS)] = gregs.gs;
510 
511 #endif /* amd64 */
512 
513 #if defined(aarch64)
514 
515 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_aarch64_AARCH64ThreadContext_##reg
516 
517   {
518     int i;
519     for (i = 0; i < 31; i++)
520       regs[i] = gregs.regs[i];
521     regs[REG_INDEX(SP)] = gregs.sp;
522     regs[REG_INDEX(PC)] = gregs.pc;
523   }
524 #endif /* aarch64 */
525 
526 #if defined(riscv64)
527 #define REG_INDEX(reg)  sun_jvm_hotspot_debugger_riscv64_RISCV64ThreadContext_##reg
528 
529   regs[REG_INDEX(PC)]  = gregs.pc;
530   regs[REG_INDEX(LR)]  = gregs.ra;
531   regs[REG_INDEX(SP)]  = gregs.sp;
532   regs[REG_INDEX(R3)]  = gregs.gp;
533   regs[REG_INDEX(R4)]  = gregs.tp;
534   regs[REG_INDEX(R5)]  = gregs.t0;
535   regs[REG_INDEX(R6)]  = gregs.t1;
536   regs[REG_INDEX(R7)]  = gregs.t2;
537   regs[REG_INDEX(R8)]  = gregs.s0;
538   regs[REG_INDEX(R9)]  = gregs.s1;
539   regs[REG_INDEX(R10)]  = gregs.a0;
540   regs[REG_INDEX(R11)]  = gregs.a1;
541   regs[REG_INDEX(R12)]  = gregs.a2;
542   regs[REG_INDEX(R13)]  = gregs.a3;
543   regs[REG_INDEX(R14)]  = gregs.a4;
544   regs[REG_INDEX(R15)]  = gregs.a5;
545   regs[REG_INDEX(R16)]  = gregs.a6;
546   regs[REG_INDEX(R17)]  = gregs.a7;
547   regs[REG_INDEX(R18)]  = gregs.s2;
548   regs[REG_INDEX(R19)]  = gregs.s3;
549   regs[REG_INDEX(R20)]  = gregs.s4;
550   regs[REG_INDEX(R21)]  = gregs.s5;
551   regs[REG_INDEX(R22)]  = gregs.s6;
552   regs[REG_INDEX(R23)]  = gregs.s7;
553   regs[REG_INDEX(R24)]  = gregs.s8;
554   regs[REG_INDEX(R25)]  = gregs.s9;
555   regs[REG_INDEX(R26)]  = gregs.s10;
556   regs[REG_INDEX(R27)]  = gregs.s11;
557   regs[REG_INDEX(R28)]  = gregs.t3;
558   regs[REG_INDEX(R29)]  = gregs.t4;
559   regs[REG_INDEX(R30)]  = gregs.t5;
560   regs[REG_INDEX(R31)]  = gregs.t6;
561 
562 #endif /* riscv64 */
563 
564 #if defined(ppc64) || defined(ppc64le)
565 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_ppc64_PPC64ThreadContext_##reg
566 
567   regs[REG_INDEX(LR)] = gregs.link;
568   regs[REG_INDEX(NIP)] = gregs.nip;
569   regs[REG_INDEX(R0)]  = gregs.gpr[0];
570   regs[REG_INDEX(R1)]  = gregs.gpr[1];
571   regs[REG_INDEX(R2)]  = gregs.gpr[2];
572   regs[REG_INDEX(R3)]  = gregs.gpr[3];
573   regs[REG_INDEX(R4)]  = gregs.gpr[4];
574   regs[REG_INDEX(R5)]  = gregs.gpr[5];
575   regs[REG_INDEX(R6)]  = gregs.gpr[6];
576   regs[REG_INDEX(R7)]  = gregs.gpr[7];
577   regs[REG_INDEX(R8)]  = gregs.gpr[8];
578   regs[REG_INDEX(R9)]  = gregs.gpr[9];
579   regs[REG_INDEX(R10)] = gregs.gpr[10];
580   regs[REG_INDEX(R11)] = gregs.gpr[11];
581   regs[REG_INDEX(R12)] = gregs.gpr[12];
582   regs[REG_INDEX(R13)] = gregs.gpr[13];
583   regs[REG_INDEX(R14)] = gregs.gpr[14];
< prev index next >