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.

asked Jan 16, 2012 at 23:25
7
  • 3
    This feature does not appear to exist. stackoverflow.com/questions/4864917/… Commented Jan 16, 2012 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? Commented Jan 16, 2012 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. Commented Jan 17, 2012 at 0: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. ;-) Commented Oct 11, 2014 at 10:08
  • 1
    2015 and still no improvement in Eclipse debugging. What a pity... Commented Nov 3, 2015 at 13:55

3 Answers 3

7

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
694k94 gold badges1.3k silver badges1.3k bronze badges
answered Jan 16, 2012 at 23:34
Sign up to request clarification or add additional context in comments.

1 Comment

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"
1

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.

answered Nov 27, 2019 at 0:15

1 Comment

I come from the C world (programming with Eclipse) and it is possible to do what @MedicineMan is saying. Now I am working with Eclipse but in Java, this feature seems to be missing. I think it has to do with the compiler's capability. Since that feature is not available this is the next best thing.
-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.

answered Jan 16, 2012 at 23:30

8 Comments

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".
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.
I dont want to execute line 2. also see the attached link which confirms my suspicions. stackoverflow.com/questions/4864917/…
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.
@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? :-|
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.