I want to force the current execution line to a specific line in the same function, possibly skipping intermediate lines. All my old school debuggers had this feature, but I can't find it in eclipse. Is there a way to do it without changing code?
-
Looking for feature similar to visual studio's "set next statement", but for java/eclipse: msdn.microsoft.com/en-us/library/09yze4a9.aspx– jm.Apr 26, 2011 at 19:50
-
2there is bug (or may be) feature request for that in Eclipse bugs bugs.eclipse.org/bugs/show_bug.cgi?id=287795– AmitdOct 26, 2012 at 18:04
-
As +PhiLho points out, if the line you want to execute is ahead, by all means "Run to line". However if you are already past the line then you can "Drop frame" to be taken to the start of the function call. Then you "Run to line" as before.– RobinoJan 18, 2016 at 16:02
5 Answers
The first two answers seem to miss the topic, unless it is me not understanding the question.
My understanding, a feature I searched myself, is that you want to skip a number of lines (when stepping in code) and set the program counter (to take assembly vocabulary) to the given line. It might be interesting to skip some costly object creation, see some error situations, etc. I used to do that in Visual Studio (C or C++ code).
I haven't found that in Eclipse, nor in NetBean. It might be a limitation of JVM, or an enforcement of some policy...
The Run to line command execute, of course, all lines between the current execution position and the designated one.
I too have long sought this feature, and "Run to line" is not the same thing.
This may well be a limitation of the JVM. Java does not implement goto, though it does have jump statements, like break and continue. Those are at the block level however. If this is a JVM limitation, my guess is that it is more likely due to the security architecture. Tight control of the program counter is debilitating for interlopers, like viruses -- and sadly debuggers.
-
1yep that is what the Eclipse team were saying..i linked a eclipse link showing the conversation..– AmitdOct 26, 2012 at 18:10
I think that is not possible in Java. The only feature that allows you to "step back" is using "drop to frame", which takes you back to the first instruction of the current frame. At least I haven't seen any debugger with this specific functionality, but I haven't been able to find on the net why is it so...
I know the debugger in Visual C allows to change to pointer. I will keep on searching, maybe at least we will know why is like this, but it seems to be some kind of design limitation.
Feature request saying it is not possible
In https://bugs.eclipse.org/bugs/show_bug.cgi?id=287795 (credits to Amitd) Darin Wright says it is a limitation of the underlying Java debugger:
Currently, this is not possible with the Java debugger as the native debug interface does not provide the ability to move/set the program counter arbitrarily.
C / C++
CDT supports it however (tested on Neon, Ubuntu 14.04). Right click on the line you want to go to, and select either:
- "Move to line": jump to line and break there
- "Resume at line": jump to line and continue execution from there
This also serves as further evidence that there is an underlying Java limitation, as Java tends to be more feature rich in Eclipse, and those menu entries are not present in Java next to "Run to line" (which does not skip execution of lines).
This test program prints 0 if you jump the line i = 1
:
#include <stdio.h>
int main(void) {
int i;
i = 0; /* Break here. */
i = 1;
printf("%d\n", i); /* Jump to here. */
}
"Run to line" appears to need the program to be running and in a paused state to use. The other option is to set a breakpoint for that line when running in debug-mode.
- Double-click far-left vertical bar in the source pane on the same line to add a breakpoint; or,
- Select the line and go to Run > Toggle Breakpoint.
At least, this is in Eclipse 3.3.2.
-
2-1 Run to line has nothing to do with altering the execution of the program. Dec 11, 2011 at 18:23