Starting a Debugging Session with 'jdb'

This section provides a tutorial example on how to a debugging session with 'jdb' and run a Java application with debugging commands.

To test the debugger, I wrote the following simple Java application, Hello.java:

class Hello {
   public static void main(String[] a) {
      System.out.println("Hello world!"); 	
   }
}

Here is what I did in a command window to run "jdb" to launch and debug Hello.java:

C:\herong>\progra~1\java\jdk1.8.0\bin\javac Hello.java

C:\herong>\progra~1\java\jdk1.8.0\bin\jdb Hello
Initializing jdb ...

> stop in Hello.main
Deferring breakpoint Hello.main.
It will be set after the class is loaded.

> run
run Hello
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Hello.main

Breakpoint hit: "thread=main", Hello.main(), line=3 bci=0
3          System.out.println("Hello world!");

main[1] next
Hello world!
>
Step completed: "thread=main", Hello.main(), line=4 bci=8
4       }

main[1] cont
>
The application exited

Notice that:

If you want to launch the target application immediately, you can use the "-launch" option:

C:\herong>jdb -launch Hello
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack

main[1] cont
> Hello world!

The application has been disconnected

As we expected, "jdb -launch" command launches the target application immediately, and stops at the beginning of the main() method.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

'jdb' - The Java Debugger

 'jdb' - Java Debugger Command and Options

Starting a Debugging Session with 'jdb'

 Debugging Applications with Separate 'jdb' Sessions

 Debugging Java Applications Remotely

 Listing Debugging Commands with 'help' Command

 PrimeNumberSeeker.java - Multi-Thread Sample Program

 Starting Debugging Session on a Multi-Thread Application

 Stepping through Statements of a Child Thread

 Checking Variable Values in a Debugging Session

 Debugging the Main Thread of a Multi-Thread Application

 Switching Execution Threads in a Debugging Session

 Suspending Main Thread to Debug Child Thread

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version