Moving the instruction pointer while debugging Java in Eclipse

JavaEclipseDebugging

Java Problem Overview


Can I move the instruction pointer directly to a line of my choice (within the current method) while debugging a Java program in Eclipse (Galileo)?

It's straightforward to drag the instruction pointer to the desired line within a method in Visual Studio, but I don't see a way to do that in Eclipse (and don't find anything about it in the docs or on google).

Java Solutions


Solution 1 - Java

This is possible...

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/tips/jdt_tips.html

>Drop to frame - When stepping through your code, you might occasionally step too far, or step over a line you meant to step into. > Rather than restarting your debug session, you can use the Drop to > Frame action to quickly go back to the beginning of a method. Select > the stack frame corresponding to the Java method you wish to restart, > and select Drop to Frame from Debug view toolbar or the stack frame's > context menu. The current instruction pointer will be reset to the > first executable statement in the method. This works for non-top stack > frames as well. > > Note that Drop to frame is only available when debugging with a 1.4 or > higher VM, or the J9 VM. There are some situations where a JVM may be > unable to pop the desired frames from the stack. For example, it is > generally impossible to drop to the bottom frame of the stack or to > any frame below a native method.

Solution 2 - Java

This is not possible.

If you simply want to execute some code at the current place you can use the Expressions view and enter your code as an expression. The methods called by the expression evaluation will run in the current debugging context.

Solution 3 - Java

Moving the pointer like in Visual Studio is not possible, however workarounds are:

Going backwards to the beginning of the currently executed method: Select the method from the debug call stack, right click -> "Drop to frame" et voila you're back at the beginning of the method.

Now to reach your desired line select the line by clicking in it and hit ctrl+r or right click the line and select "Run to line".

These techniques are hugely helpful and reduce debugging efforts massively, enjoy!

Solution 4 - Java

A trick I use is to type a space in your class, somewhere safe such as in the comment line; immediately delete it and save the class. This forces the execution point to jump to the beginning of your current method. Not ideal, I admit, but it can sometimes be used as a workaround to achieve what you want.

Although in the default installation of eclipse it is not possible to do directly move the execution point like in Visual Studio, there may exist an eclipse plugin which provides that functionality somewhere. Have a search around.

Solution 5 - Java

I like ankon's answer best, but another option (that will only work for your specific instance -- if that) is to stop at a breakpoint on your if and modify the variable(s) evaluated in the conditional such that it returns false (from the "Variables" view, right click on a variable and click "Change Value...")

Solution 6 - Java

I thought that this was totally possible in older versions of eclipse, I thought I had the memory of doing it, but I guess I just implanted that memory when I worked in Visual Studio. From what I'm reading it might come to the jvm and not eclipse itself, there are pages where it's suggested that the jvm cannot handle that.

In my opinion Eclipse is many many times better than VS, I worked extensively in both and since I discovered Eclipse I was always in pain when I had to work in VS. But not having this feature is definitely hurting right now hehe.

Solution 7 - Java

You can jump directly to any other method call inside of the currently debugged method. Select some method call below your current instruction pointer and use "Step into selection" from the context menu.

Solution 8 - Java

unfortunately not possible to step forward with instruction pointer (program counter), so what you need to do instead is to introduce your own "debugging" variables that you can test on - lets say you want to step around a loop that takes too long, then add a variable and test on its increased value and then encapsulate the loop in an if with that variable. I know this is ugly, but it gets it done - or you could just develop in C++ :-)

Solution 9 - Java

Just right click on desired line and choose run to line.That's it...

Solution 10 - Java

Put the cursor on the line of your choice and either hit ctrl-R ("Run to line") or right-click and select "Run to line" from the context menu.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric J.View Question on Stackoverflow
Solution 1 - JavaJohn S.View Answer on Stackoverflow
Solution 2 - JavaankonView Answer on Stackoverflow
Solution 3 - Javafl0wView Answer on Stackoverflow
Solution 4 - JavaIqbalHamidView Answer on Stackoverflow
Solution 5 - JavavioloncelloView Answer on Stackoverflow
Solution 6 - Javauser1294431View Answer on Stackoverflow
Solution 7 - JavaBananeweizenView Answer on Stackoverflow
Solution 8 - JavaserupView Answer on Stackoverflow
Solution 9 - JavaAjay TakurView Answer on Stackoverflow
Solution 10 - JavaJonathan FeinbergView Answer on Stackoverflow