How to native debug Java on macOS?
Chris Plummer
chris.plummer at oracle.com
Tue Sep 10 20:00:49 UTC 2019
On 9/9/19 9:18 AM, Alexander Miloslavskiy wrote:
>> 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
This shouldn't be necessary when using gdb on linux. I've always found
the "handle SIGSEGV" command to be sufficient. However, the downside of
"handle SIGSEGV" is that gdb won't stop if you hit an actually crash. So
your script might be useful in this situation, although it does seem a
bit tenuous and is probably not covering all cases were hotspot might
trap. For example, is it handling compiler uncommon traps?
cheers,
Chris
More information about the hotspot-dev
mailing list