How to native debug Java on macOS?
Alexander Miloslavskiy
alexandr.miloslavskiy at gmail.com
Mon Sep 9 16:18:50 UTC 2019
> It seems as if you have some great tricks for debugging on Windows and Linux.
Yes, I managed to convince debuggers to auto-skip internal exceptions
and pause on anything unexpected.
On Linux, this is rather easy to setup (a small gdb script), but on
Windows, it's quite more complicated (needs JDK with debugging
information, debugger plugin and a script for it).
The GDB script is below. If you think that it's bad, then I don't know
who written it; but if you find it useful, then it was me :)
---------------------------------------------
# Ignore java's internal SIGSEGV
catch signal SIGSEGV
commands
# SIGSEGV
if (11 == $_siginfo.si_signo)
# Doing this results in very weird behavior, assigning to
'$sigsegv_rwAddr' will replace value in 'si_addr' instead.
# This crashes VM later, because 'si_addr' gets corrupted.
# set $sigsegv_rwAddr = $_siginfo._sifields._sigfault.si_addr
# Didn't find a way to 'return' from 'commands'
set $sigsegv_Known = 0
# Skip polling page exceptions used in safepoints
if (!$sigsegv_Known)
if ((os::_polling_page <= $_siginfo._sifields._sigfault.si_addr) &&
($_siginfo._sifields._sigfault.si_addr < os::_polling_page + 4096))
printf "SIGSEGV(%p): os::is_poll_address()=true\n",
$_siginfo._sifields._sigfault.si_addr
set $sigsegv_Known = 1
end
end
# Skip implicit NullPointer exceptions
if (!$sigsegv_Known)
set $sigsegv_Thread = 'ThreadLocalStorage::thread'()
if ($sigsegv_Thread)
if ($sigsegv_Thread->is_Java_thread())
set $sigsegv_JThread = (JavaThread*)$sigsegv_Thread
set $sigsegv_stub =
'SharedRuntime::continuation_for_implicit_exception'($sigsegv_JThread,
(address)$pc, SharedRuntime::IMPLICIT_NULL)
if ($sigsegv_stub)
printf "SIGSEGV(%p):
SharedRuntime::continuation_for_implicit_exception()=%p\n",
$_siginfo._sifields._sigfault.si_addr, (void*)$sigsegv_stub
set $sigsegv_Known = 1
end
end
end
end
# Skip cpuinfo
if (!$sigsegv_Known)
if ($pc == VM_Version::_cpuinfo_segv_addr)
printf "SIGSEGV(%p): VM_Version::is_cpuinfo_segv_addr()=true\n",
$_siginfo._sifields._sigfault.si_addr
set $sigsegv_Known = 1
end
end
if ($sigsegv_Known)
continue
end
end
end
More information about the hotspot-dev
mailing list