Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of GDB 'start' in JDB?

Tags:

java

gdb

jdb

I'm a bit confused by JDB. Being fairly good at using GDB, I'm aware of the various simple commands used to control the execution, i.e. start, run, cont, step, stepi, break, etc. but there are a number of (in my opinion) unusual differences.

If I wish to start an application (as opposed to running it, so I can step it from the start), instinctively, I type jdb MyApp and then start. I get an unrecognized command error. Reading the JDB help gives me no indication at all of a start command or its equivalent. So, I try step - that doesn't work either; I am told that I need to start the Java VM with the run command!

Clearly, it must be possible, because there is a step command explained in the help. So, I figure that maybe I can type run and very quickly press ctrl+c to interrupt it as, in GDB, this stops the execution. Instead, it just quits JDB.

I've tried googling this, to no avail. I hope I'm not being totally blind stupid!

Rant over: how on earth do you just start running a java application in JDB so that you can step it, from the start?

like image 851
Doddy Avatar asked Mar 27 '11 19:03

Doddy


2 Answers

I have just started to use JDB as a debugger. There are good instructions that can be found here. To answer some of your questions:

  1. To start jdb, at the command prompt, type jdb <name of main class>
  2. To start the program, type run
  3. To set a breakpoint, type: stop at <class>:<line no.>
  4. To step, type cont

As I said, I have just started to use jdb just now. There are, I am sure, better ways to do the above and I will post here should I get to know more myself.

HTH.

like image 191
Sriram Avatar answered Sep 28 '22 06:09

Sriram


The problem is the VM hasn't launched, which is why you can't step into the first line. The solution is to start JDB with "-launch" as a command line argument. From there you can type "step" or "cont" to start debugging from the start.

The best bit is it only takes a second and doesn't require installing an IDE :-)

like image 22
Mike B Avatar answered Sep 28 '22 05:09

Mike B