Skip to content

Commit

Permalink
8342607: Enhance register printing on x86_64 platforms
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: 1bfb57dca4a65ea64a15914b1e8b5c4c509db6f5
  • Loading branch information
TheRealMDoerr committed Dec 10, 2024
1 parent 6f16a44 commit 131a032
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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]);
Expand Down
9 changes: 9 additions & 0 deletions src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,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);
Expand Down
14 changes: 13 additions & 1 deletion src/hotspot/share/utilities/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,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
}

Expand Down
10 changes: 6 additions & 4 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ class oopDesc;
#define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")

// Format 32-bit quantities.
#define INT32_FORMAT "%" PRId32
#define UINT32_FORMAT "%" PRIu32
#define INT32_FORMAT_W(width) "%" #width PRId32
#define UINT32_FORMAT_W(width) "%" #width PRIu32
#define INT32_FORMAT "%" PRId32
#define INT32_FORMAT_X_0 "0x%08" PRIx32
#define INT32_FORMAT_W(width) "%" #width PRId32
#define UINT32_FORMAT "%" PRIu32
#define UINT32_FORMAT_X_0 "0x%08" PRIx32
#define UINT32_FORMAT_W(width) "%" #width PRIu32

#define PTR32_FORMAT "0x%08" PRIx32
#define PTR32_FORMAT_W(width) "0x%" #width PRIx32
Expand Down

0 comments on commit 131a032

Please sign in to comment.