Konubinix' opinionated web of thoughts

How to Debug a Java Program

Fleeting

jdb - The java debugger

Run java with the debugging options

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 <options>

Then run the debugger attaching to the debugger:

jdb -attach 5005 -sourcepath/home/me/some/root/folder

Beware that there must not be the = sign in between sourcepath and the path. Also, the path points to a folder that leads to the hierarchy of java files as seen in the import directives.

For example, if at some point you can write.

import com.some.java.module;

And this modules resides at the location /home/me/some/where/com/some/java/module.java, then you have to provide -sourcepath/home/me/some/where.

For example, in maven, it might look like ./src/main/java/

Also, you can update the value of the sourcepath dynamically in jdb using the command called use, but emacs-jdb won’t realize that and won’t update accordingly the value of gud-jdb-sourcepath, making gud ignore interactive commands like breakpoints.

g. A VM that is to be debugged with jdb must be started with the following options. These options load in-process debugging libraries and specify the kind of connection to be made.

-agentlib:jdwp=transport=dt_shmem,server=y,suspend=n

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html

then attach jdb to the VM with the following commmand: C:\> jdb -attach jdbconn

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html