Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.00

Checking Variable Values in a Debugging Session

This section provides a tutorial example on how to check values of local variables in a debugging session.

3. Checking local variables:

Thread-0[1] next
7, 3, 0
>
37             if (isPrime) {

Thread-0[1] print isPrime
 isPrime = true

Thread-0[1] next
8, 3, 0
>
38                count++;

Thread-0[1] next
9, 3, 0
>
39                primes[count-1] = current;

Thread-0[1] print count
 count = 1

Thread-0[1] next
> 10, 3, 1
42                sleep(delay);

Thread-0[1] list
38                count++;
39                primes[count-1] = current;
40             }
41             try {
42 =>             sleep(delay);
43             } catch (InterruptedException e) {
44                System.out.println("Runner interrupted.");
45             }
46          }
47       }

Thread-0[1] print primes[0]
 primes[0] = 3

What I have done here:

  • I used "next" again. The sub thread jumped over the calculation loop between line 33 and 36. This is correct, since "current" has "3", a prime number, no need to do any calculation.
  • Then I used "next" and "print" several times. I saw prime number 3 was correctly recorded in the "primes" array.

Sections in This Chapter

'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

PrimeNumberSeeker.java - Multi-Thread Sample Program

Starting Debugging Session on a Multi-Thread Application

Stepping through Statements of the 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

Dr. Herong Yang, updated in 2008
Checking Variable Values in a Debugging Session