HW6 Java Debugger Guide

 

The Java debugger differs from gdb in a number of ways. The biggest difference is that your program will execute in one window while the debugger executes in another window. Here's a short tutorial to get you started. The following commands help you to set a break point at Driver's static main method and to step through the HashTable's constructor. A short but more complete documentation on the debugger can be found using a link from the course web page. In the window where your program will execute, at the command prompt, type...

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y Driver

Note: In the above command, spaces are important. "Driver" is the name of the class with the static main method. The address 8000 is a number selected by you that is unique to you. You'll need this number so that the two windows will be able to coordinate with each other. If the number that you select is already in use, you'll get the error: "Address already in use". If you see that error, you'll need to try again with another number. If the window appears to "hang", your program has begun but it is suspended waiting for the debugging window to begin. Once you are successful, IN ANOTHER WINDOW (where the debugger will execute) at the command prompt, type...

jdb -attach 8000

where 8000 is the address successfully used in the previous command. Upon success, you should see:

Initializing jdb... VM Started: > No frames on the current call stack main[1]

where the above display is the debugging prompt. You can now set a breakpoint in Driver's main method. At the prompt, enter...

stop in Driver.main

Upon success, you should see:

Deferring breakpoint Driver.main. It will be set after the class is loaded.

You can now begin execution of your program. At the prompt enter...

run

Upon success, you should see:

> Set deferred breakpoint Driver.main Breakpoint hit: thread="main", Driver.main(), line=51, bci=0 51 HashTable.debugOff();

If your breakpoint is not hit, then start over again using a different address. Upon success, you can single "step" or "next" just like in gdb. To display the call stack frame, use "where". Additionally, you can "print" the values of any variables of interest or "list" the code that is executing. You can "cont"inue to execute your program at any time. Notice that your program input and output happens in the original window while the debugger is controlling your program from the second window.