Java Debugging with gdb

It is possible to debug Java programs compiled with GCJ using GDB.
To do this, you need a recent version of GDB. A CVS snapshot version of GDB
is recommended: GDB 5.0 and earlier are not able to demangle the symbol names
generated by GCC 3.x's new C++/Java ABI. Alternatively, it should also be
possible to rebuild GDB 5.0 with an updated libiberty directory. GDB 5.1 will
include support for the new ABI.

When debugging GCJ-compiled Java programs, you may need to
tell GDB to ignore the SIGPWR and SIGXCPU signals
(which are used by the garbage collector). This can be done with the
GDB commands:

handle SIGPWR nostop noprint
handle SIGXCPU nostop noprint

Alternately you can place these two lines in the file .gdbinit
in $HOME or the directory where you're running GDB.

Remember that some optimizations performed by the compiler can make debugging
results unpredictable. When debugging libgcj itself, it is often useful to
build a non-optimized library by using `make GCJFLAGS="-g"'.

Here is an example of debugging a simple test program (which uses multiple
Java threads) in GDB:

$ javac TestT.java
$ gcj -g --main=TestT -o TestT TestT.class
$ gdb TestT
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) handle SIGPWR nostop noprint

Signal Stop Print Pass to program Description
SIGPWR No No Yes Power fail/restart

(gdb) handle SIGXCPU nostop noprint

Signal Stop Print Pass to program Description
SIGXCPU No No Yes CPU time limit exceeded

For questions related to the use of GCC,
please consult these web pages and the
GCC manuals. If that fails,
the gcc-help@gcc.gnu.org
mailing list might help.
Comments on these web pages and the development of GCC are welcome on our
developer list at gcc@gcc.gnu.org.
All of our lists
have public archives.

Copyright (C)
Free Software Foundation, Inc.
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.