Tuesday, December 18, 2012

How to use JDB on Linux

JDB is quite a powerful debugging tool for Java programs, especially for multi-threading Java programs.

JDB can be found in the JDK package.

You can also learn how to use JDB by reading the manual of JDB (using command "man jdb").

Here I only show the useful parts that I found:
(1) you can run your Java program as usual with the additional option "-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
(2) now you can start JDB using command "jdb -attach 8000"
(3) in JDB, you can first use "suspend" to suspend your JAVA program, and then use "threads" to see the thread list of the JAVA program; if you want to see what code is each thread running, you can use "where 0x22" (0x22 is the thread id which is from the thread list); after finishing debugging, you can use "resume" to resume your JAVA program.
(4) if you want to exit JDB and let your JAVA program go on running, you can simply press Control-C

No comments: