Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Java Debugger(JDB)

JDB(Java Debugger)
"jdb": A command line tool that allows you to debug a Java application
interactively with in a command line mode.
Syntax:

(1)jdb [options] main_class_name

(2) 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.
Once started, "jdb" offers you command prompt to allow you to run debugging

commands interactively.

Without the "-launch" option, "jdb" will not start the main() method of the specified

class.

"stop in" command sets a breakpoint at the beginning of the specified method. See

the next section for other commonly used debugging commands.

"run" command starts a new JVM process with run your application in debug mode.

"next" command executes only the current statement of the debugged application.

"cont" command resumes the execution to the end or the next breakpoint.
To test the debugger, in the the following simple Java
application, Hello.java:
class Hello {
public static void main(String[] a) {
System.out.println("Hello world!");
}
}
-launch option
1)C:\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

2) main[1] cont
Hello world!

The application has been disconnected


How do you start debugging?
1) C:\javac Hello.java

2) C:\jdb Hello
Initializing jdb ...

3) stop in Hello.main
Deferring breakpoint Hello.main.
It will be set after the class is loaded.
4) 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!");
(5) main[1] next
Hello world!
Step completed: "thread=main", Hello.main(), line=4
bci=8
}
(6) main[1] cont
The application exited

You might also like