FarragoFennelDebugging

From Eigenpedia

Jump to: navigation, search

How do I debug Fennel when it's called from Java?


Assuming that a FennelStackTrace isn't good enough, it is possible to use gdb to debug Fennel embedded inside of Farrago.

The easy way is to use gdb to attach to the process after it starts. You can get the process ID from the ps command, or from the server startup messages in FarragoTrace.log; search backward from the end for "opening database; process ID = XXX".

Then run gdb, and issue the command

(gdb) att XXX

where XXX is the process ID.

The hard way is described on the rest of this page. If gdb attachment doesn't work for some reason, the method below may. And the method below is the only way to debug startup problems.


Before starting the Java virtual machine, export environment variable FENNEL_JNI_DEBUG=2 in the shell from which you are going to run Java. When the Fennel JNI layer is loaded, you should see a message like "Waiting for debugger; pid=18454". Start gdb and tell it to attach to the process with the given pid. The process should be sleeping with a stack originating from entry point JNI_OnLoad; set whatever breakpoints you want and then issue the gdb command signal SIGHUP to end the call to pause in JniUtil::initDebug. (Don't use the gdb cont command here or the debugger and debuggee will both be frozen until you send the debuggee SIGHUP via some other means such as kill -s SIGHUP pid. )


On older Linux kernels, gdb receives many spurious signals when attached to the Java Virtual Machine (even SIGSEGV!) The only choices are to tell gdb to ignore them (e.g. with the command handle SIGSEGV nostop noprint), or to manually continue past them each time (like if you want to track down a real segfault).


Of historical interest only: why do we use the number 2 instead of 1 for FENNEL_JNI_DEBUG? Well, we used to use 1 and a non-portable mechanism which allowed you to use cont instead of signal. That no longer works on modern kernels, but the code is still there; you can try it if the signal-based mechanism doesn't work for some reason.

Personal tools