1

I am curious how to execute previous line of code while debugging?

Currently, I see the following buttons: - Step over; - Step into; - Force step into; - Step out;

but no button "Step previous".

mr.M
  • 851
  • 6
  • 23
  • 41
  • 1
    There is no such button :) – Nir Alfasi May 24 '15 at 17:08
  • How then would you accomplish executing prev line? It is really weired .. – mr.M May 24 '15 at 17:12
  • You can select the previous line and choose "evaluate expression", but that won't "rewind" to the previous line. It will just execute it once again. – JB Nizet May 24 '15 at 17:17
  • 1
    You cannot do it. Though it sounds a simple thing to implement it is actually not so. Since most programs are stateful, once you've executed a statement that has a side-effect - executing the same thing again might cause unwanted and unexpected results. – Nir Alfasi May 24 '15 at 17:26
  • You certainly can do it (not always), by dropping a frame, and steppping into that method again. I would say that most of the code will not have any side effect and it is safe to go through a method again, but that is something that cannot be generalized. – Meo May 25 '15 at 10:23

2 Answers2

1

By default, you cannot advance backwards while debugging code. Since code runs are temporal, one should be able to re-run the code that they're debugging to narrow in on what specifically they want to observe in the debugger.

However, if you really want to be able to debug and step backwards, then the Chronon plugin is a viable option. Note that you won't be dropped into a debug context immediately, and you won't be able to access any live evaluation, but this will allow you to debug your code by stepping forwards and backwards.

Makoto
  • 104,088
  • 27
  • 192
  • 230
0

You could Drop Frame - it will return you to a previous method, so you can step on that line again. See When using the Java debugger in Intellij what does "Drop Frame" mean?

Community
  • 1
  • 1
Meo
  • 12,020
  • 7
  • 45
  • 52