I'm having a hard time trying to debug OpenJDK java on Alpine Linux using gdb - was anyone successful in doing so?
When trying to debug java in gdb, for example, gdb java
and r -version
, it instantly fails with:
Thread 1 "java" recieved signal ?, Unknown signal.
__cp_end () at src/thread/x86_64/syscall_cp.s:29
I searched and searched but couldn't find any reference or solution for OpenJDK debugging on Alpine.
Other threads dealing with the same gdb error, seen on other platforms (macOS Sierra, MinGW), suggest that recieved signal ?, Unknown signal
could result from various reasons, including a gdb bug, uncaught exception, stack overflow, and other application bugs.
Outside gdb, java is working without any problems, and gdb is working fine for debugging a simple C++ program. I'm running Alpine V3.8.
Things I've tried:
- Different gdb versions (
8.0.1-r6
,8.0.1-r3
,7.12.1-r1
). - Different OpenJDK versions (
1.8.0_171
,1.7.0_181
). - Running from different shells (
/bin/ash
,/bin/bash
), with and withoutsudo
. - Disabling stopping on signals in
.gdbinit
:handle SIGSEGV nostop noprint pass
, and same forSIGPIPE
,SIGHUP
,SIGFPE
,SIG34
. - Adding
set startup-with-shell off
to.gdbinit
.
Thanks for any help!
Edit:
Here's the full stack where the unknown signal is thrown, which causes JVMInit to fail:
(gdb) r -version
Starting program: /usr/lib/jvm/java-1.8-openjdk/bin/java -version
process 16214 is executing new program: /usr/lib/jvm/java-1.8-openjdk/bin/java
[New LWP 16219]
Thread 1 "java" received signal ?, Unknown signal.
__cp_end () at src/thread/x86_64/syscall_cp.s:29
29 src/thread/x86_64/syscall_cp.s: No such file or directory.
(gdb) info threads
Id Target Id Frame
* 1 LWP 16214 "java" __cp_end () at src/thread/x86_64/syscall_cp.s:29
2 LWP 16219 "java" __synccall (func=func@entry=0x7ffff7da2662 <do_setrlimit>, ctx=ctx@entry=0x7ffff7ff4720)
at src/thread/synccall.c:143
(gdb) where
#0 __cp_end () at src/thread/x86_64/syscall_cp.s:29
#1 0x00007ffff7dbed2d in __syscall_cp_c (nr=202, u=<optimized out>, v=<optimized out>, w=<optimized out>, x=<optimized out>,
y=<optimized out>, z=0) at src/thread/pthread_cancel.c:35
#2 0x00007ffff7dbe350 in __timedwait_cp (addr=addr@entry=0x7ffff7ff4b20, val=16219, clk=clk@entry=0, at=at@entry=0x0, priv=priv@entry=0)
at src/thread/__timedwait.c:31
#3 0x00007ffff7dbfdc4 in __pthread_timedjoin_np (t=0x7ffff7ff4ae8, res=res@entry=0x7fffffffa348, at=at@entry=0x0)
at src/thread/pthread_join.c:16
#4 0x00007ffff7dbfe02 in __pthread_join (t=<optimized out>, res=res@entry=0x7fffffffa348) at src/thread/pthread_join.c:27
#5 0x00007ffff7b6695e in ContinueInNewThread0 (continuation=continuation@entry=0x7ffff7b61a60 <JavaMain>, stack_size=1048576,
args=args@entry=0x7fffffffa3e0)
at /home/buildozer/aports/community/openjdk8/src/icedtea-3.8.0/openjdk/jdk/src/solaris/bin/java_md_solinux.c:1046
#6 0x00007ffff7b634a4 in ContinueInNewThread (ifn=ifn@entry=0x7fffffffa4f0, threadStackSize=<optimized out>, argc=1,
argv=<optimized out>, mode=mode@entry=841574793, what=what@entry=0x0, ret=0)
at /home/buildozer/aports/community/openjdk8/src/icedtea-3.8.0/openjdk/jdk/src/share/bin/java.c:2024
#7 0x00007ffff7b66a08 in JVMInit (ifn=ifn@entry=0x7fffffffa4f0, threadStackSize=<optimized out>, argc=<optimized out>,
argv=<optimized out>, mode=841574793, mode@entry=0, what=what@entry=0x0, ret=<optimized out>)
at /home/buildozer/aports/community/openjdk8/src/icedtea-3.8.0/openjdk/jdk/src/solaris/bin/java_md_solinux.c:1093
#8 0x00007ffff7b63e30 in JLI_Launch (argc=<optimized out>, argv=<optimized out>, jargc=<optimized out>, jargv=<optimized out>,
appclassc=1, appclassv=0x0, fullversion=0x555555554843 "1.8.0_171-b11", dotversion=0x55555555483f "1.8", pname=0x55555555483a "java",
lname=0x555555554832 "openjdk", javaargs=0 '\000', cpwildcard=1 '\001', javaw=0 '\000', ergo=0)
at /home/buildozer/aports/community/openjdk8/src/icedtea-3.8.0/openjdk/jdk/src/share/bin/java.c:304
#9 0x0000555555554691 in main (argc=<optimized out>, argv=<optimized out>)
at /home/buildozer/aports/community/openjdk8/src/icedtea-3.8.0/openjdk/jdk/src/share/bin/main.c:125
(gdb)
musl source files matching this stack trace:
- 1: http://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_cancel.c
- 2: http://git.musl-libc.org/cgit/musl/tree/src/thread/__timedwait.c
- 3, 4: http://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_join.c
OpenJDK source code:
JVMInit
attempts to create the JavaMain
native thread, by calling ContinueInNewThread
, which calls ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args)
, and there it explodes.