Debugging JNI using JDB
Hi!
I was wondering if someone could tell me how to debug an application that is using JNI using JDB. Is it possible to enter the parts written in C and set breakpoints there? Would really appreciate if someone could describe how to debug an application that probably has something wrong in the JNI parts. I don't just want to see what native code parts that is entered, I also want to be able to set breakpoints in the native code (C code).
I have this application that works fine when executing it on the Windows (Intel) and the RedHat Linux (Intel) platform using j2sdk1.4.0. But when I run it on a Solaris 8 (Sparc) computer using j2sdk1.4.0, it crashes the whole JVM. The application is using JNI to communicate with the C-program part. I think the Sparc/Solaris machine is a 32-bits computer but it might be a 64-bits computer. Does that make a difference?
I get the following stack trace when running the application.
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 10 occurred at PC=0xFA023164
Function=Java_Bitmap_setDebug+0x1C
Library=/usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
Current Java thread:
at Bitmap.setDebug(Native Method)
at DisplayPanel.loadFile(DisplayPanel.java:396)
at MicPlot.loadFile(MicPlot.java:1452)
at MicPlot.loadFile(MicPlot.java:1441)
at MicPlot.miOpen_Action(MicPlot.java:1267)
at MicPlot$SymAction.actionPerformed(MicPlot.java:1184)
at java.awt.MenuItem.processActionEvent(MenuItem.java:588)
at java.awt.MenuItem.processEvent(MenuItem.java:548)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Dynamic libraries:
0x10000 /opt/java/jdk1.4/bin/java
0xff360000 /usr/lib/libthread.so.1
0xff3a0000 /usr/lib/libdl.so.1
0xff280000 /usr/lib/libc.so.1
0xff270000 /usr/platform/SUNW,Ultra-4/lib/libc_psr.so.1
0xfe000000 /opt/java/j2sdk1.4.1/jre/lib/sparc/client/libjvm.so
0xff220000 /usr/lib/libCrun.so.1
0xff200000 /usr/lib/libsocket.so.1
0xff100000 /usr/lib/libnsl.so.1
0xff1d0000 /usr/lib/libm.so.1
0xff250000 /usr/lib/libw.so.1
0xff0e0000 /usr/lib/libmp.so.2
0xff0b0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/native_threads/libhpi.so
0xff080000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libverify.so
0xff030000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libjava.so
0xfe7e0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libzip.so
0xfe4e0000 /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.2
0xedd00000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libawt.so
0xfc480000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libmlib_image.so
0xfc410000 /opt/java/j2sdk1.4.1/jre/lib/sparc/motif21/libmawt.so
0xeda80000 /usr/dt/lib/libXm.so.4
0xfa090000 /usr/openwin/lib/libXt.so.4
0xfa3d0000 /usr/openwin/lib/libXext.so.0
0xfc7e0000 /usr/openwin/lib/libXtst.so.1
0xed980000 /usr/openwin/lib/libX11.so.4
0xfa2a0000 /usr/openwin/lib/libdps.so.5
0xfa3b0000 /usr/openwin/lib/libSM.so.6
0xfa1d0000 /usr/openwin/lib/libICE.so.6
0xed880000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libfontmanager.so
0xfa390000 /usr/openwin/lib/locale/common/xlibi18n.so.2
0xfa1b0000 /usr/openwin/lib/locale/iso8859-1/xomEuro.so.2
0xfa190000 /usr/lib//liblayout.so
0xfa050000 /usr/openwin/lib/locale/common/ximlocal.so.2
0xfa010000 /usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
Local Time = Thu Oct 3 13:32:47 2002
Elapsed Time = 35
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.1-beta-b14 mixed mode)
#
# An error report file has been saved as hs_err_pid27692.log.
# Please refer to the file for further information.
#
Abort
I have tried everything that I can come up with. The thing is that if I change to use jdk1.1.8 as JVM on Solaris, that is the JVM that is delivered with the Sparc/Solaris machine, the application works fine but not when I am using jdk1.3 or jdk1.4 that I have installed myself.
From the stack trace above it is obvious that the error must be in the setDebug method in native code, and that is also the first native code that is executed.
So I have this Bitmap class that contains all the native calls and it is defined shortly as follow:
-
public class Bitmap {
static {
System.loadLibrary("BitmapImpl");
}
.
.
native void setDebug(int debuglevel, int statistics);
}
--
There are many more native methods defined in Bitmap, but I only show the setDebug method because that is the first one that is executed and also the one that immediately fails.
My setDebug C function is defined as follow in BitmapImpl.c
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <fcntl.h>
#include <jni.h>
#include <math.h>
#include <errno.h>
#include "Bitmap.h"
#include "data.h"
jint debug = 0;
jint statistics = 1;
.
.
.
JNIEXPORT void JNICALL Java_Bitmap_setDebug
(JNIEnv *jenv, jobject jo, jint d, jint s)
{
debug = d;
statistics = s;
}
.
.
.
My libBitmapImpl.so file is compiled using the following Makefile and using GNU gcc:
JAVAPATH=$(JAVAINCLUDEPATH)
LMACRO=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DSOLARIS
CSOURCE=BitmapImpl.c
all:
gcc -O3 -G $(LMACRO) -I$(JAVAPATH) -I$(JAVAPATH)/solaris \
$(CSOURCE) -o libBitmapImpl.so
So I would really appreciate if someone could give me some pointers to why it fails using jdk1.3 and jdk1.4 on the Sparc/Solaris machine. Why does it work perfectly with jdk1.1.8 that comes with the machine? I don't know if it is a 32 or a 64-bit machine, but does that matter? It works perfectly well with the jdk1.1.8 that is originally installed. The application fails on its first native call so something has to be seriously wrong. I have no compilation errors. Could it be that Solaris is using different native threads and that that has changed between jdk1.1.8 and jdk1.3/jdk1.4?
Thanks in advance!
Best regards
Lars

