1

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.

mpettis
  • 3,222
  • 4
  • 28
  • 35

2 Answers2

1

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

FredvN
  • 504
  • 1
  • 3
  • 14
1

Ran into same issue when debugging android app within AVD. I was not able to list sourcecode even if I defined the correct -sourcepath.

I need to execute JDB from correct directory. If the class belongs to any package, e.g. class MainActivity belongs to package org.gradle.samples, then your project folder contains the following directory:

yourProject/
├── src
│   └── main
│       └── java
│           └── org
│               └── gradle
│                   └── samples
│                       └── MainActivity.java

Then you have to execute jdb from <pathToYourProject>/src/main/java, where JDB -sourcepath is <pathToYourProject>/src/main/java as well.

Hölderlin
  • 424
  • 1
  • 3
  • 16