23

Is there a way to jump to a line of code in Eclipse for Java? It would be useful for re-running a function to debug. Something like Visual Studio's "Set Next Statement" or the draggable yellow arrow?

Yellow arrow in Visual Studio

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
RunHolt
  • 1,892
  • 2
  • 19
  • 26
  • 1
    Here is a similar question http://stackoverflow.com/questions/4864917/is-it-possible-to-go-back-in-java-eclipse-debugger-like-dragging-the-arrow-in – Uriel Frankel Apr 05 '12 at 17:44

5 Answers5

14

When in the debugger select a place in the stack, right click, and select "Drop to Frame". This will unwind the call stack. You can do this on the current method (top of the call stack) to unwind to the top of the method. This doesn't work all the time for various reasons but you can do it pretty often.

BenjaminLinus
  • 2,100
  • 23
  • 24
  • 2
    If you want to go back only one line of code, I understand you'd have to drop to the previous frame in stack and then re-running everything until you reach that line of code – BornToCode Jul 08 '14 at 16:26
5

This feature does not exist even conceptually in the JVM Tools Interface, much less in the Java Debug Wire Protocol that IDEs tend to interface with. Implementing it in an IDE would require creating (and mantaining) a custom build of Hotspot/JRockit/etc itself.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
2

I also have not found it, and don't think it is supported. It's availability in Visual Studio (for C++ development) really spoiled me. It is very useful on occasion.

john
  • 21
  • 1
0

I'm unaware of any means to do so in Eclipse - and all obvious checks turn up nothing. I suspect there's an issue with how java works, as it's been available an awfully long time in Visual Studio and for Eclipse to have not matched it means it must not be a heavy task but an epic one.

Ry-
  • 218,210
  • 55
  • 464
  • 476
JSandusky
  • 21
  • 2
0

I have found one rather silly way to rerun a method without going back to the previous frame.

e.g. you are in this function:

'public int compareTo(EVAL evalOther) {
    int jRet = compareId(this.id, evalOther.id);
    if (jRet == 0) {
      jRet = compareXYZ(this.XYZ, evalOther.XYZ);
    }
return jRet;
}'

let us say, after executing the first line, i.e. int jRet = compareId(this.id, evalOther.id);

I want to rerun this line, I just make a minor change to it which will force a quick recompile of the same method . So it starts from the first line of the method again.

e.g. I change the line

'int jRet = compareEVALClass(this, evalOther);'

to

'int jRet = 0 + compareEVALClass(this, evalOther);'

Press Ctrl-S (or whatever your shortcut key is to Save file)

And then the function recompile and will restart from the first line again.

Agreed, this is not as great as Visual Studio's "Set next statement"

M G
  • 47
  • 1