Pages

jdb - The Java Debugger

In this article we are going to elaborate the jdb command tool which
is a part of JAVA commands (comes with jdk package). This article is the
continuation of this previous article.

As we know the standard format of commands in java, the jdb command also have the format(in command prompt). jdb [options] [class] [arguments]
JDB helps to find and fix bugs of JAVA code. Mainly it is a command line debugger of java code. So, if we find any error when compiling , we can use this tool to get the problem and solve that. We can start jdb in many ways.
-Start jdb to a new JVM with main class of the application needed debugging. In this way, jdb invokes a new JVM
with any specific parameters(we select), loads the specified class, and stops
the VM before executing that class's first instruction.

-Start jdb with a already running JVM(attaching). The JVM must have started in a debug supporting mode( Loads in process debug libraries and connection type to connect). Example of debug-able JVM start commandjava -agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n MyClass
Now, attaching jdb to the VM jdb -attach jdbconn

-We can directly attach JDB with current VM and start debugging
session. In this way we have to run every command step by step. To start
jdb session, just typejdb
It will initiate jdb.

JDB options : These are command line options. -sourcepath [directories separated by ";"] : Directories to search source files-launch: Launch VM immediately-tclient : Runs the application in client Hotspot(tm) Performance Engine -tserver : Run the application in server Hotspot(tm) Performance Engine
-listconnectors :List the connectors available in this VM-connect [connector-name]:[name1]=[value1].. : Connect to target VM using named connector with listed argument values-attach [address] : Attach to a running VM at the specified address using connector.-listen [address] : Wait for a running VM to connect at the specified address using connector-listenany : Wait for a running VM to connect at any available address using connector
-dbgtrace [flags] : print info for debugging jdb-J[option] : Pass option to the Java virtual machine by jdb.

-v -verbose[:class|gc|jni] : Turn on verbose mode-D[name]=[value] : Sets a system property-classpath[directories separated by ";"] : list directories in which to look for classes-X[option] :Non-standard target VM option. See java commands for more details.

JDB command line commands : (Inside a JDB Session)

connectors : list available connectors and transports in this VMrun [class [args]]: Start execution of application's main class

stop in [class id].[method] [(argument_type,...)]: Sets a break point in a methodstop at [class id]:[line] : Sets a breakpoint at a lineclear : list breakpointsclear [class id].[method][(argument_type,...)] : Clears a break point in a methodclear [class id]:[line] : Clears a break point at a line