Skip to content

Commit dad1c36

Browse files
author
duke
committed
Backport 1bfb57dca4a65ea64a15914b1e8b5c4c509db6f5
1 parent d0949c8 commit dad1c36

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,21 @@ void os::print_context(outputStream *st, const void *context) {
560560
st->print(", ERR=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_ERR]);
561561
st->cr();
562562
st->print(" TRAPNO=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_TRAPNO]);
563+
// Add XMM registers + MXCSR. Note that C2 uses XMM to spill GPR values including pointers.
564+
st->cr();
565+
st->cr();
566+
// Sanity check: fpregs should point into the context.
567+
if ((address)uc->uc_mcontext.fpregs < (address)uc ||
568+
pointer_delta(uc->uc_mcontext.fpregs, uc, 1) >= sizeof(ucontext_t)) {
569+
st->print_cr("bad uc->uc_mcontext.fpregs: " INTPTR_FORMAT " (uc: " INTPTR_FORMAT ")",
570+
p2i(uc->uc_mcontext.fpregs), p2i(uc));
571+
} else {
572+
for (int i = 0; i < 16; ++i) {
573+
const int64_t* xmm_val_addr = (int64_t*)&(uc->uc_mcontext.fpregs->_xmm[i]);
574+
st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT, i, xmm_val_addr[1], xmm_val_addr[0]);
575+
}
576+
st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->uc_mcontext.fpregs->mxcsr);
577+
}
563578
#else
564579
st->print( "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EAX]);
565580
st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBX]);

src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,15 @@ void os::print_context(outputStream *st, const void *context) {
432432
st->cr();
433433
st->print( "RIP=" INTPTR_FORMAT, uc->Rip);
434434
st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
435+
// Add XMM registers + MXCSR. Note that C2 uses XMM to spill GPR values including pointers.
436+
st->cr();
437+
st->cr();
438+
for (int i = 0; i < 16; ++i) {
439+
const uint64_t *xmm = ((const uint64_t*)&(uc->Xmm0)) + 2 * i;
440+
st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT,
441+
i, xmm[1], xmm[0]);
442+
}
443+
st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->MxCsr);
435444
#else
436445
st->print( "EAX=" INTPTR_FORMAT, uc->Eax);
437446
st->print(", EBX=" INTPTR_FORMAT, uc->Ebx);

src/hotspot/share/utilities/debug.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,22 @@ void disarm_assert_poison() {
743743

744744
static void store_context(const void* context) {
745745
memcpy(&g_stored_assertion_context, context, sizeof(ucontext_t));
746-
#if defined(LINUX) && defined(PPC64)
746+
#if defined(LINUX)
747747
// on Linux ppc64, ucontext_t contains pointers into itself which have to be patched up
748748
// after copying the context (see comment in sys/ucontext.h):
749+
#if defined(PPC64)
749750
*((void**) &g_stored_assertion_context.uc_mcontext.regs) = &(g_stored_assertion_context.uc_mcontext.gp_regs);
751+
#elif defined(AMD64)
752+
// In the copied version, fpregs should point to the copied contents.
753+
// Sanity check: fpregs should point into the context.
754+
if ((address)((const ucontext_t*)context)->uc_mcontext.fpregs > (address)context) {
755+
size_t fpregs_offset = pointer_delta(((const ucontext_t*)context)->uc_mcontext.fpregs, context, 1);
756+
if (fpregs_offset < sizeof(ucontext_t)) {
757+
// Preserve the offset.
758+
*((void**) &g_stored_assertion_context.uc_mcontext.fpregs) = (void*)((address)(void*)&g_stored_assertion_context + fpregs_offset);
759+
}
760+
}
761+
#endif
750762
#endif
751763
}
752764

0 commit comments

Comments
 (0)