Apr 7, 2012


If the compiler returns errors related to your code, you can use the Java debugger to debug your code. The most common way to start jdb on local classes is using the following syntax:

    jdb classname [parameters]

To run the debugger, you are substituting the command for Java with jdb. This starts the Java interpreter with the class to be debugged and any specified parameters, and stops before executing the class's first process.

If you need to run jdb with Java interpreter already running, you can connect to the interpreter using the -host and -password options. In order to be able to retrieve the password from the Java interpreter session, it must have been invoked using the -debug option. When you start Java using the -debug option, it provides a password with which the jdb can be started.

You can feed the Java debugger several command-line parameters that change its behavior. These parameters can be listed using jdb's help parameter. Below Table lists all of these commands.

catch classID
Breaks for the specified exception.
Lists currently known classes.
clear classID:line
Clears a breakpoint.
Continues execution from breakpoint.
down [n frames]
Moves down a thread's stack.
dump ID [ID..]
Prints all object information.
exit (or quit)
Exits debugger.
help (or ?)
Lists commands.
ignore classID
Ignores the specified exception.
list [line number]
Prints source code.
load classname
Loads class.
Prints all local variables in current stack frame.
Reports memory usage.
Lists methods in a class.
print ID [ID..]
Prints an object or field.
resume [threadID..]
Resumes threads. Default is all.
run class [args]
Starts execution of a loaded class.
Executes current line.
stop in classID.method
Sets a breakpoint in a method.
stop at classID:line
Sets a breakpoint at a line.
suspend [threadID..]
Suspends threads. Default is all.
threads threadgroup
Lists threads.
thread threadID
Sets default thread.
Lists threadgroups.
threadgroup name
Sets current threadgroup.
up [n frames]
Moves up a thread's stack.
use [path]
Displays or changes source path.
where [threadID] or all
Dumps a thread's stack.
Repeats last command.

Below Table lists the command-line options for jdb that are used when accessing a running interpreter.

-host <hostname>
Sets the name of the host machine on which the interpreter session to attach to is running.
-password <password>
Logs in to the active interpreter session. This is the password printed by the Java interpreter. The password prints when invoked by the -debug option.


Post a Comment