Java Debugging from Command Line

19/08/06 Permalink

Original Location

Apr 22nd, 2006 09:12
Knud van Eeden,

--- Knud van Eeden --- 22 April 2006 - 04:11 pm ----------------------

Java: Debug: How to debug on the command line? [jdb.exe]


To debug, run e.g. the program



Steps: Overview:

 1. -Possibly download and install the Sun Java JDK
     (because this installs also the program jdb.exe)

 2. -Run the program


 3. -This will open a command line where you can type debug commands

 4. -E.g.

      run [myApplicationFilename].java



      1. -That will show a screen output similar to the following:

--- cut here: begin --------------------------------------------------

 > run

   Set uncaught java.lang.Throwable

   Set deferred uncaught java.lang.Throwable

   VM Started:

   Exception occurred: java.lang.ClassNotFoundException
             $, line=199 bci=72


--- cut here: end ----------------------------------------------------

 5. -For a list of commands, type


     1. -That will show a screen output similar to the following:

--- cut here: begin --------------------------------------------------


 Initializing jdb ...

 > help

 ** command list **

 run [class [args]]        -- start execution of application's main

 threads [threadgroup]     -- list threads

 thread         -- set default thread

 suspend [thread id(s)]    -- suspend threads (default: all)

 resume [thread id(s)]     -- resume threads (default: all)

 where [ | all] -- dump a thread's stack

 wherei [ | all]-- dump a thread's stack, with pc info

 up [n frames]             -- move up a thread's stack

 down [n frames]           -- move down a thread's stack

 kill     -- kill a thread with the given exception

 interrupt      -- interrupt a thread

 print               -- print value of expression

 dump                -- print all object information

 eval                -- evaluate expression (same as print)

 set  =      -- assign new value to field/variable/array

 locals                    -- print all local variables in current
                              stack frame

 classes                   -- list currently known classes

 class           -- show details of named class

 methods         -- list a class's methods

 fields          -- list a class's fields

 threadgroups              -- list threadgroups

 threadgroup         -- set current threadgroup

 stop in .[(argument_type,...)]
                           -- set a breakpoint in a method

 stop at : -- set a breakpoint at a line

 clear .[(argument_type,...)]
                           -- clear a breakpoint in a method

 clear :   -- clear a breakpoint at a line

 clear                     -- list breakpoints

 catch [uncaught|caught|all] |
                           -- break when specified exception occurs

 ignore [uncaught|caught|all] |
                           -- cancel 'catch' for the specified

 watch [access|all] .
                           -- watch access/modifications to a field

 unwatch [access|all] .
                           -- discontinue watching access/modifications
                              to a field

 trace methods [thread]    -- trace method entry and exit

 untrace methods [thread]  -- stop tracing method entry and exit

 step                      -- execute current line

 step up                   -- execute until the current method returns
                              to its caller

 stepi                     -- execute current instruction

 next                      -- step one line (step OVER calls)

 cont                      -- continue execution from breakpoint

 list [line number|method] -- print source code

 use (or sourcepath) [source file path]
                           -- display or change the source path

 exclude [, ... | "none"]
                           -- do not report step or method events for
                              specified classes

 classpath                 -- print classpath info from target VM

 monitor          -- execute command each time the program 

 monitor                   -- list monitors

 unmonitor       -- delete a monitor

 read            -- read and execute a command file

 lock                -- print lock info for an object

 threadlocks [thread id]   -- print lock info for a thread

 pop                       -- pop the stack through and including the
                              current frame

 reenter                   -- same as pop, but current frame is 

                           -- redefine the code for a class

 disablegc           -- prevent garbage collection of an object

 enablegc            -- permit garbage collection of an object

 !!                        -- repeat last command

               -- repeat command n times

 help (or ?)               -- list commands

 version                   -- print version information

 exit (or quit)            -- exit debugger

 : a full class name with package qualifiers

 : a class name with a leading or trailing wildcard 

 : thread number as reported in the 'threads' command

 : a Java(tm) Programming Language expression.

 Most common syntax is supported.

 Startup commands can be placed in either "jdb.ini" or ".jdbrc"

 in user.home or user.dir

Share It: Digg | | Furl | reddit | Facebook | Yahoo! | Send to Phone | Feedback