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

  jdb.exe

===

Steps: Overview:

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

 2. -Run the program

      jdb.exe

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

 4. -E.g.

      run [myApplicationFilename].java

      e.g.

       run HelloWorldApplication.java

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

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

 > run HelloWorld.java

   Set uncaught java.lang.Throwable

   Set deferred uncaught java.lang.Throwable

   VM Started:

   Exception occurred: java.lang.ClassNotFoundException
                       (uncaught)"thread=main",
                       java.net.URLClassLoader$1.run(), line=199 bci=72

   main[1]

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

 5. -For a list of commands, type

      help

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

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

 jdb.exe

 Initializing jdb ...

 > help

 ** command list **

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

 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
                              object

 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
                              element

 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
                              exception

 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 
stops

 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 
reentered

 redefine  
                           -- 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 | del.icio.us | Furl | reddit | Facebook | Yahoo! | Send to Phone

mobile-utopia.com | Feedback