Search code examples
c++java-native-interfacegdbcliongdbserver

Debug jni library from clion using gdbserver


I wonder if it's possible to debug jni library from CLION

My setup:

I have remote server with running java application which internaly calls native library. On the server I started gdbserver instance attaching to existing process:

gdbserver --attach localhost:7777 pid

It successfully connects to the process.

On local machine I create remote debug configuration in CLION specifying target remote agrs:

tcp:host:7777

I also specify symbol file and sysroot. So when I run this configuration I successfully connect to remote server, but then I keep getting programm pausing because of SIGPIPE and SIGSEGV signals, so I never get to my real breakpoint. (I believe those are signals inside jvm).

Switching off Exception Breakpoints didn't help.

Is there a way to debug such a setup?


Solution

  • JVM indeed uses signals under the hood a lot. In order to debug it efficiently you may want to ignore these signals using the handle GDB command. Enter it into the GDB console in CLion:

    (gdb) handle SIGSEGV nostop noprint pass
    

    Here's a good answer to a very close question.