Short tutorial on GDB and GCJ
Matt Welsh
mdw@cs.berkeley.edu
Sat Apr 1 00:00:00 GMT 2000
I wrote the following short tutorial on using GDB with GCJ; would
someone like to include this on the GCJ web pages somewhere? It's in HTML.
------------
<p>
<b>Java Debugging with <tt>gdb</tt></b>
<p>
It is possible to debug Java programs compiled with GCJ using GDB.
To do this, you need a recent version of GDB 4.18 with support for
Java and Linux threads; an RPM for Red Hat systems is available from the
<a href=" http://www.redhat.com/mirrors.html ">various Red Hat mirror sites</a>.
You need <tt>gdb-4.18-4.i386.rpm</tt>. (Note that not all
varions of GDB 4.18 include support for Java and Linux threads. It
appears as though the GDB 4.18 included with Red Hat 6.1 <em>will work</em>,
while previous versions may not.)
<p>
When debugging GCJ-compiled Java programs, you need to
tell GDB to ignore the <tt>SIGPWR</tt> and <tt>SIGXCPU</tt> signals
(which are used by the garbage collector). This can be done with the
GDB commands:
<blockquote>
<tt>
handle SIGPWR nostop noprint<br>
handle SIGXCPU nostop noprint<br>
</tt>
</blockquote>
Alternately you can place these two lines in the file <tt>.gdbinit</tt>
in the directory where you're running GDB.
<p>
Here is an example of debugging a simple test program (which uses multiple
Java threads) in GDB:
<p>
<blockquote>
<tt>
$ <b>javac TestT.java</b><br>
$ <b>gcj -g -O --main=TestT -o TestT TestT.class</b><br>
$ <b>gdb TestT</b><br>
GNU gdb 4.18<br>
Copyright 1998 Free Software Foundation, Inc.<br>
GDB is free software, covered by the GNU General Public License, and you are<br>
welcome to change it and/or distribute copies of it under certain conditions.<br>
Type "show copying" to see the conditions.<br>
There is absolutely no warranty for GDB. Type "show warranty" for details.<br>
This GDB was configured as "i386-redhat-linux"...<br>
(gdb) <b>handle SIGPWR nostop noprint</b><br>
<pre>
Signal Stop Print Pass to program Description
SIGPWR No No Yes Power fail/restart
</pre>
(gdb) <b>handle SIGXCPU nostop noprint</b><br>
<pre>
Signal Stop Print Pass to program Description
SIGXCPU No No Yes CPU time limit exceeded
</pre>
(gdb) <b>break TestT.main</b><br>
Breakpoint 1 at 0x8049fa2: file TestT.java, line 64.<br>
(gdb) <b>run</b><br>
<pre>
Starting program: /disks/now/grad/mdw/src/ninja/test/mdw/TestT
[New Thread 16843 (manager thread)]
[New Thread 16835 (initial thread)]
[New Thread 16844]
[Switching to Thread 16844]
Breakpoint 1, TestT.main (args=@806cff0) at TestT.java:64
64 TestT a1 = new TestT(1,false);
</pre>
(gdb) <b>where</b><br>
<pre>
(gdb) where
#0 TestT.main (args=@806cff0) at TestT.java:64
#1 0x4011033a in java::lang::FirstThread::run (this=@8064f90)
at /home/cs/mdw/disks/enclave1/libgcj-991104/libjava/java/lang/natFirstThread.cc:52
#2 0x400ccdfa in java.lang.Thread.run_ (this=@8064f90)
at /home/cs/mdw/disks/enclave1/libgcj-991104/libjava/java/lang/Thread.java:119
#3 0x4011554a in java::lang::Thread::run__ (obj=@8064f90)
at /home/cs/mdw/disks/enclave1/libgcj-991104/libjava/java/lang/natThread.cc:286
#4 0x4012524a in really_start (x=@805fef0)
at /home/cs/mdw/disks/enclave1/libgcj-991104/libjava/posix-threads.cc:316
#5 0x401d7ba6 in GC_start_routine (arg=@807ffe0)
at /home/cs/mdw/disks/enclave1/libgcj-991104/boehm-gc/linux_threads.c:533
#6 0x401eece9 in pthread_start_thread (arg=@bf7ffe7c) at manager.c:204
</pre>
</tt>
</blockquote>
<p>
Note that the stack trace includes both Java code and the native methods
in the libgcj runtime library!
<p>
You can examine threads using the <tt>info threads</tt> and
<tt>thread</tt> commands:
<p>
<blockquote>
<tt>
(gdb) <b>info threads</b><br>
<pre>
* 3 Thread 16844 TestT.main (args=@806cff0) at TestT.java:64
2 Thread 16835 (initial thread) 0x4022a1bb in __sigsuspend (set=0xbffff4f4)
at ../sysdeps/unix/sysv/linux/sigsuspend.c:48
1 Thread 16843 (manager thread) 0x402b37d0 in __poll (fds=0x808fef0,
nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:45
</pre>
(gdb) <b>thread 2</b><br>
<pre>
[Switching to thread 2 (Thread 16835 (initial thread))]
#0 0x4022a1bb in __sigsuspend (set=0xbffff4f4)
at ../sysdeps/unix/sysv/linux/sigsuspend.c:48
48 ../sysdeps/unix/sysv/linux/sigsuspend.c: No such file or directory.
Current language: auto; currently c
</pre>
(gdb)
</tt>
</blockquote>
More information about the Java
mailing list