public class HelloWorld { public static void main (String args []) { System.out.println("Hello world"); } }The method compiles into this bytecode:
0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) 3: ldc "Hello world" (3) 5: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (4) 8: returnNormally the program is started by executing
% java HelloWorldYou can debug your program with JBCD by invoking jbcd, and passing your normal command line as a command line argument as in
% java jbcd HelloWorldWhen JBCD starts up, it prints the first instruction of the program, and waits for input:
% java jbcd Hello 0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) jbcd> _
step
command to step through bytecode one
statement at a time. The current instruction is printed after each
step. If a method is invoked, the debugger will step into that
method. The next
command that steps over method
invokations has not yet been implemented.
Use the cont
command to continue program execution to
the next breakpoint.
% java jbcd Hello 0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) jbcd> step 3: ldc "Hello world" (3) jbcd> step 5: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (4) jbcd> cont Hello world % _
list
command. This will print the 10 statements
around the current instruction.
% java jbcd Hello 0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) jbcd> list 0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) 3: ldc "Hello world" (3) 5: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (4) 8: return jbcd> _
break
with no arguments.
Breakpoints are cleared with the clear
command. With
no arguments, clear
removes all breakpoints. Clear can
also be given a list of integer arguments, cooresponding to the ids of
breakpoints to remove. Breakpoint ids are printed when the
breakpoints are listed by break
.
% java jbcd Hello 0: getstatic java.lang.System.out Ljava/io/PrintStream; (2) jbcd> break main(java.lang.String[]):5 jbcd> break [0] Breakpoint: Hello.main(java.lang.String[]):5 jbcd> cont 5: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (4) jbcd> clear 0 jbcd> break No breakpoints set jbcd> _