compiling an app that depends on a

Tom Tromey tromey@redhat.com
Wed Sep 26 15:45:00 GMT 2001


>>>>> "Jef" == wavelet bot <waveletbot@yahoo.com> writes:

Jef> Also, some the classes in the jar file include native methods.
Jef> These methods are implemented in a shared library called
Jef> libjusb.so.

Presumably using JNI...

Jef> So, I would like to compile the jusb library code and my
Jef> application code so that everything is executing natively, and
Jef> then use gdb to get some useful debug information.

This is a good plan.  However, be aware that sometimes gdb has
problems debugging gcj-compiled code :-(.  This used to be better, but
it has been a bit broken for a while and nobody has worked on it.

So while it might work ok, it may not be a great experience.  It's
hard to predict.  Also, while debugging JNI code in the gdb/gcj
environment is the easiest way I know of, due to limitations in gdb it
isn't always easy.

Jef> Thanks very much.  Oh yea, I should mention that I do have access
Jef> to all the source code for the jusb library.

Build all your Java code with `-g'.  Something like:

    gcj -c -g -fjni -o foo/bar.o foo/bar.java

... once for each file.  `-c' means "make a .o file", `-g' means
"debug", and "-fjni" means "I'm using JNI to implement native
functions in this file".

Now link it all together:

    gcj -g -o myprogram --main=class.with.main <all the .o files>

`class.with.main' is the name of the class holding your main() method,
just like you would supply it to the java program.

Unfortunately the next steps are difficult unless you've used gdb a
lot.  Also I'm doing this from memory.

Run gdb on your program
Put a breakpoint on main
Run your program
Once it hits the main breakpoint (which will be in some file you have
    never seen before -- ignore that), put a breakpoint on
    java::lang::Runtime::_load and continue
Once you hit the next breakpoint, use the `finish' command
Now you should be able to put a breakpoint on your JNI function.

Note that gdb, in my experience, is highly likely to crash if you
re-run your program once the breakpoints are set.  So you'll probably
end up typing in this sequence a lot.

I keep thinking there must be an easier way to do this, but as far as
I can tell there isn't.  No wonder I hate debugging!

Tom



More information about the Java mailing list