Search code examples
javajdb

java jdb does not display code lines in step output


Trying to learn the jdb from the command line. From tutorials I expect to see the code line output when I step lines, but I am not.

Here is sample code I compiled:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        System.out.println("Hello world! line 2");
        System.out.println("Hello world! line 3");
    }
}
$ ~/jdk-18.0.2.1/bin/jdb.exe Main
Initializing jdb ...
> stop at Main.main
Deferring breakpoint Main.main.
It will be set after the class is loaded.
> run
run Main
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Main.main

Breakpoint hit: "thread=main", Main.main(), line=3 bci=0

main[1] step
> Hell
Step completed: o world!
"thread=main", Main.main(), line=4 bci=8

main[1] step
> Hello world! line 2

Step completed: "thread=main", Main.main(), line=5 bci=16

main[1]

Note, in here, the output is showing, but I expect to see the code lines that are about to be executed, and the line number displayed, like:

3       System.out.println("Hello world!");

I've seen tutorials that have screen shots with this happening, and I am wondering if I have a missing setting or a wrong version of jdb or something.


Solution

  • You can use the command list to show the lines around your current position