16

In Visual Studio, it was possible during debugging sessions to jump to the line selected by the cursor and execute that line. After jumping to that line, you can continue debugging from the line that you've jumped to. Does this feature exist on the Java/Eclipse world?

For example:

foo1();

foo2();

foo3();

return true;

In Visual Studio it is possible to break on foo1(), place the cursor on foo3(), execute foo3() without executing foo2. Furthermore, when the debugger is stopped on "return true", I can place the cursor on foo1, and execute foo1 again. Furthermore, I can continue to execute arbitrary lines of code through these actions.

Community
  • 1
  • 1
MedicineMan
  • 15,008
  • 32
  • 101
  • 146
  • 3
    This feature does not appear to exist. http://stackoverflow.com/questions/4864917/is-it-possible-to-go-back-in-java-eclipse-debugger-like-dragging-the-arrow-in – MedicineMan Jan 16 '12 at 23:45
  • Interesting. What happens if you tell it to jump ahead to a line and the skipped lines declared variables that are used by the line you jumped to? – Laurence Gonsalves Jan 16 '12 at 23:50
  • 1
    if it is a value class, the the variable will be in scope but will have the default value. If reference type, it will be initialized to null. – MedicineMan Jan 17 '12 at 00:03
  • Which makes perfect sense from a .NET Runtime perspective, since the managed stack space is reserved from the start of the method. (Those variables are declared from the beginning of the method, they're all just set to `default(T)`). -- The JVM does the same thing, so there's no reason why it shouldn't be able to do this. -- Seems due to a lack in the tools. -- I suppose Eclipse is free, and is worth every penny. ;-) – BrainSlugs83 Oct 11 '14 at 10:08
  • 1
    2015 and still no improvement in Eclipse debugging. What a pity... – Thomas Weller Nov 03 '15 at 13:55
  • Possible duplicate of [How can I set the current line of execution in the eclipse java debugger](http://stackoverflow.com/questions/191306/how-can-i-set-the-current-line-of-execution-in-the-eclipse-java-debugger) – Ciro Santilli OurBigBook.com Mar 08 '17 at 13:36
  • I also missws this feature too. IntelliJ IDEA has it now. https://blog.jetbrains.com/idea/2020/08/jump-to-any-line-while-debugging/ – Anderson Vasconcelos Pires Sep 22 '20 at 17:05

3 Answers3

6

Click on the line you want to run to and press Ctrl+R and it will run to that line instead of putting in tons of break points. Also you can use F8 to run to your next break point or F6 to run to the next line.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
travega
  • 8,284
  • 16
  • 63
  • 91
  • 8
    This is not an answer. `Ctrl+R` is the shortcut for "Run to line", which will also execute foo2() and thus contradicts OP's requirement which is "execute foo3() without executing foo2" – Thomas Weller Nov 03 '15 at 13:52
0

You can jump backwards, to the top of the function, using Eclipse's "drop to frame" feature. Right-click the function at top of the stack.

You can't skip foo2(), but you could possibly edit variables to undo whatever effects it has had.

Noumenon
  • 5,099
  • 4
  • 53
  • 73
-1

Yes. Put a breakpoint on the line, hit F8, wait for the program to execute until this line, and press F6 to go to the next line, or F5 to step into the current line.

EDIT:

Once the thread is paused in the debugger, you may also select some runnable code, right-click, and choose "Display" (Ctll-Shift-D) or "Execute" (Ctrl-U). You may also use the Display view to type any statement, select it, and execute or display it.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • 7
    This is a useful response because it documents some interesting features of the Eclipse IDE. However, it does not behave as the Visual Studio IDE. At this time, the answer to this question is "No, this feature does not appear to exist". – MedicineMan Jan 16 '12 at 23:50
  • I don't really see how it differs from what Visual Studio does. Could you be more explicit? Have you tried it in Eclipse? You put a breakpoint on `foo1()` and `return true`, while paused on foo1, you select `foo3()` and click Ctrl-U, you press F8 to go until return true, then you select `foo1()` and hit Ctrl-U. – JB Nizet Jan 16 '12 at 23:52
  • 1
    Yes I have tried this as you describe. Eclipse is not as user friendly if variables are defined as part of the lines to be executed. Consider: int startHere = 0; MyClass me = new MyClass(); foo(me); foo2(me); if you break on the first line, and execute the third line, Eclipse complains that me is undefined. Furthermore, the arrow has not moved to line three, it is still pointing to line 1. Although you have managed to execute line 3, execution has not jumped to line 3 and although you can continue to highlight lines and execute that follow, the experience is clunky. – MedicineMan Jan 17 '12 at 00:10
  • OK, so you just need to go to line 4, and hit Ctrl-R to execute all the lines until the fourth one. I wouldn't say that it's clunky. Just a small bit different than what you're used to. The point of Ctrl-U is to execute an arbitrary line of code, without following the program's flow of instructions. Of course if a variable is undefined, the instruction can't be executed. – JB Nizet Jan 17 '12 at 00:16
  • 3
    I dont want to execute line 2. also see the attached link which confirms my suspicions. http://stackoverflow.com/questions/4864917/is-it-possible-to-go-back-in-java-eclipse-debugger-like-dragging-the-arrow-in – MedicineMan Jan 17 '12 at 00:19
  • 1
    Ah, OK. Now I understand. You may delete line 2 while debugging, and then step to line 3, though. Bit it indeed require to modify the source. – JB Nizet Jan 17 '12 at 00:23
  • IMHO this answer is not really useful. I know how to set break points and step through code. But per the question, I want to know how to jump to a line (such as jumping over foo2 in the question, or jumping back to foo1 and executing it again, etc.) -- I'm pretty annoyed at the sate of FOSS software dev. tools right now. Seems Visual Studio is still light years ahead of everything. :-/ – BrainSlugs83 Oct 11 '14 at 09:56
  • 1
    @JBNizet you can't always modify the code, and even then the answer isn't super helpful -- how do you step backwards in this case? :-| – BrainSlugs83 Oct 11 '14 at 09:58