From d8b3685d36873904248e9701f66459e074a4a8ab Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Tue, 29 Oct 2024 13:30:26 +0000 Subject: [PATCH] 8342607: Enhance register printing on x86_64 platforms Co-authored-by: Richard Reingruber Reviewed-by: rrich, stuefe, mbaesken --- src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp | 15 +++++++++++++++ src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp | 9 +++++++++ src/hotspot/share/utilities/debug.cpp | 14 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp index 0d5d07fc8a8..8fdcbe63c7e 100644 --- a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp +++ b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp @@ -544,6 +544,21 @@ void os::print_context(outputStream *st, const void *context) { st->print(", ERR=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_ERR]); st->cr(); st->print(" TRAPNO=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_TRAPNO]); + // Add XMM registers + MXCSR. Note that C2 uses XMM to spill GPR values including pointers. + st->cr(); + st->cr(); + // Sanity check: fpregs should point into the context. + if ((address)uc->uc_mcontext.fpregs < (address)uc || + pointer_delta(uc->uc_mcontext.fpregs, uc, 1) >= sizeof(ucontext_t)) { + st->print_cr("bad uc->uc_mcontext.fpregs: " INTPTR_FORMAT " (uc: " INTPTR_FORMAT ")", + p2i(uc->uc_mcontext.fpregs), p2i(uc)); + } else { + for (int i = 0; i < 16; ++i) { + const int64_t* xmm_val_addr = (int64_t*)&(uc->uc_mcontext.fpregs->_xmm[i]); + st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT, i, xmm_val_addr[1], xmm_val_addr[0]); + } + st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->uc_mcontext.fpregs->mxcsr); + } #else st->print( "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EAX]); st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBX]); diff --git a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp index 62022d780a2..de59a74cc24 100644 --- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp +++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp @@ -437,6 +437,15 @@ void os::print_context(outputStream *st, const void *context) { st->cr(); st->print( "RIP=" INTPTR_FORMAT, uc->Rip); st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags); + // Add XMM registers + MXCSR. Note that C2 uses XMM to spill GPR values including pointers. + st->cr(); + st->cr(); + for (int i = 0; i < 16; ++i) { + const uint64_t *xmm = ((const uint64_t*)&(uc->Xmm0)) + 2 * i; + st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT, + i, xmm[1], xmm[0]); + } + st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->MxCsr); #else st->print( "EAX=" INTPTR_FORMAT, uc->Eax); st->print(", EBX=" INTPTR_FORMAT, uc->Ebx); diff --git a/src/hotspot/share/utilities/debug.cpp b/src/hotspot/share/utilities/debug.cpp index 119d1cf17fd..88730c1e6ec 100644 --- a/src/hotspot/share/utilities/debug.cpp +++ b/src/hotspot/share/utilities/debug.cpp @@ -725,10 +725,22 @@ void disarm_assert_poison() { static void store_context(const void* context) { memcpy(&g_stored_assertion_context, context, sizeof(ucontext_t)); -#if defined(LINUX) && defined(PPC64) +#if defined(LINUX) // on Linux ppc64, ucontext_t contains pointers into itself which have to be patched up // after copying the context (see comment in sys/ucontext.h): +#if defined(PPC64) *((void**) &g_stored_assertion_context.uc_mcontext.regs) = &(g_stored_assertion_context.uc_mcontext.gp_regs); +#elif defined(AMD64) + // In the copied version, fpregs should point to the copied contents. + // Sanity check: fpregs should point into the context. + if ((address)((const ucontext_t*)context)->uc_mcontext.fpregs > (address)context) { + size_t fpregs_offset = pointer_delta(((const ucontext_t*)context)->uc_mcontext.fpregs, context, 1); + if (fpregs_offset < sizeof(ucontext_t)) { + // Preserve the offset. + *((void**) &g_stored_assertion_context.uc_mcontext.fpregs) = (void*)((address)(void*)&g_stored_assertion_context + fpregs_offset); + } + } +#endif #endif }