Debugging Applications with Separate 'jdb' Sessions

This section provides a tutorial example on how to run a Java application and the 'jdb' debugger separately in shared memory mode.

If you ask "Can I launch the debugger ('jdb') and the target application separately?", the answer is "Yes, you can.". Since Java 5 (JDK 1.5), both "jdb" and "java" have been enhanced to use the latest JPDA (Java Platform Debugger Architecture) technology to give you the following options:

                     Debugger                 Target
Option                    jdb                   java

     1   Shared memory client   Shared memory server
     2   Shared memory server   Shared memory client
     3          Socket client          Socket server   
     4          Socket server          Socket client   

The shared memory options requires that the debugger and the target application to be on the same machine. Of course, the socket options allow you to run them remotely.

Let's try option #1 first. Open a command window on a windows system and run:

C:\herong>java -agentlib:jdwp=transport=dt_shmem,address=MyHello,server=y,
   suspend=y Hello

Listening for transport dt_shmem at address: MyHello

The target application is launched in "shared memory server" mode. Its execution is suspended. Now open another command window and run:

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

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

main[1] cont
> Set deferred breakpoint Hello.main

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

main[1] list
1    public class Hello {
2       public static void main(String[] a) {
3 =>       System.out.println("Hello world!");
4       }
5    }

main[1] cont
The application exited

As you can see, the debugger successfully connected to the target application.

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


 PDF Printing Version