1

I use jdb for my Java development. For my application I have two classes: WordUniverseTest and WordUniverse, and the main method is contained in WordUniverseTest. When I execute WordUniverseTest inside of jdb, I construct a WordUniverse object called obj inside of the main method.

But I do not know how to have jdb leave the WordUniverseTest class and step inside WordUniverse while obj is being constructed. How do I do this?

HolyKnowing
  • 121
  • 3
  • 15

2 Answers2

3

You can put a regular breakpoint there stop at and then when you are actually on the line (call list to verify), you can call step into.

As long as all your classes are known to jdb, it is going to work, I tested it.

Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
  • 1
    I tried this and got `Step completed: "thread=main", jdk.internal.loader.BuiltinClassLoader.loadClass(), line=581 bci=1` but the `jdb` didn't take me to the constructor. – HolyKnowing Jan 20 '19 at 19:58
  • When you call a `list` afterwards, you should see, that you are in the constructor. What do you see instead? – Gergely Bacso Jan 20 '19 at 20:00
2

I found the answer, and although Gergely Bacso didn't give the full answer, he did lead me to find the full answer.

jdb uses a different procedure for stepping into methods versus stepping into constructors. To step into a method, you have to do what Gergely Basco said, which is set a breakpoint at where the method is called and then step into. But for stepping into a constructor you must say stop in ClassName.<init> (with brackets). Saying that command will take you inside of the constructor.

HolyKnowing
  • 121
  • 3
  • 15