Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.00

'jdb' - Java Debugger Command and Options

This section describes the Java debugging tool 'jdb' and its commonly used command options.

"jdb": A command line tool that allows you to debug a Java application interactively with in a command line mode. "javac" is distributed as part of the Sun JDK package. It has the following syntax:

jdb [options] main_class_name
jdb [options] -attach <address> 

where "options" is a list of options, "main_class_name" is a the name of the main class of a Java application, and "address" is the debugging connection address of a running Java application.

As you can see from the syntax, there are two ways of running "jdb":

1. Running "jdb" to launch a Java application and start a debug session on that application.

2. Running "jdb" to connect to a separately launched Java application and start a debug session on that application.

Commonly used options are:

  • "-help" - Displays a short help text.
  • "-verbose" - Generates verbose output to standard output.
  • "-classpath classpath" - Specifies a list of path names where the launcher will search for compiled type definitions.
  • "-Dproperty=value" - Defines a new system property, which can be accessed by the application.
  • "-launch" - Launches the debugged application immediately upon startup of jdb. This option removes the need for using the run command. The target application is launched and then stopped just before the initial application class is loaded. At that point you can set any necessary breakpoints and use the cont to continue execution.

Note that in order to use all debugging commands, the target application must be compiled with "-g" option, which will generate all debugging information, including source file, line number, and local variables, into the class file.

Sections in This Chapter

'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 the 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

Dr. Herong Yang, updated in 2008
'jdb' - Java Debugger Command and Options