When gdb is used for debugging purposes in Java:
- What's its practical use?
- What are its limitations?
- How is it compared to other debuggers?
I would say gdb is used for debugging Java when the programmer is coming from a different language and is already familiar with gdb. Otherwise, it seems like a strange choice given that there are more popular alternatives for Java: jdb, JSwat, eclipse, netbeans, etc.
Here is a tutorial for debugging Java with gdb.
GDB is 99% of the time is not useful for debugging Java, but it can help you find native memory leaks which the java debuggers can't.
gdb can be useful to take heap dumps fast.
Normally one would dump the heap by using jmap or similar tools. But when using this tools, the JVM performs garbage collection before dumping, which can take hours on a hanging process. With the steps below you can dump fast, restart the process and convert the dump afterwards.
gdb --pid <PID>
gcore /tmp/gdbdump.core
detach
quit
Afterwards you need to convert the core file to a hprof file to analyze it with Java tools:
jmap -dump:format=b,file=/tmp/javadump.hprof /path/tojdk/java /tmp/gdbdump.core
Be aware: