How to step over method call in Eclipse Debugger? - eclipse

In Eclise debugger, the default step options are:
F5: Step into method
F6: Step over line
F7: Step out of method
Often I do have code like this:
obj.getMember().doStuff();
Or maybe even worse (please don't question the code design, just making this up):
obj.getInstance().createSomething().getMember().doStuff();
Usually I want to inspect doStuff() only, but F6 will not step over individual method calls, but it will step over the entire line. So I end up hitting F5 and F7 until I reach doStuff().
My question is: Is there any option to step over method calls (= do F5 and F7 in one shortcut)? Would be cool, if I had to tap X, X, X, F5 only to reach doStuff().
// Edit for clarification: I'm looking for a keyboard-only solution. I know there are several ways I can reach my method (e.g. breakpoints), but I'm asking for a combined shortcut for F5 + F7, so to say.

You have to select the method you want to step into and then with the right click of the mouse you will find the option Step into Selection :
Select the Step Into Selection command to step into the currently
selected statement in the active editor.
You must have program execution suspended for this command to be available.
As you can see from the image above you can just press OPTION and F5 on a mac once selected the method to step into ...
Shortcut :ALT + F5

You could also place a breakpoint into doStuff() and, when you reach obj.getInstance().createSomething().getMember().doStuff(); just resume execution (keybinding: F8:
All the intermediate frames will be executed and the debugger will pause directly in doStuff() again. This of course means that you cannot decide from run to run like you can do with aleroot's Step into Selection suggestion.

Alright, something completely different, since I think I understand the core of your question a bit better now.
There's no predefined skip-over-this-method command afaik, so you can build one yourself. This touches some advanced topics so I'll only post some pointers here:
Create an Eclipse plugin.
In that plugin, declare a command with a keybinding like Alt+F8 and implement the command's default handler
In the handler of your command, invoke the built-in commands which are bound to the Step into and Step out actions. You can find their IDs by looking into the Eclipse source or trying the Plugin-Spy feature.
Package up your plugin and start your Eclipse with it included.
This way you'll reuse the predefined functionality and automate your F5 plus F7 mashing into a single command with relatively small effort.

Related

eclipse rcp keybindings don't work

I am trying to make eclipse keybindings work.
I tried to make the rename command work.
I looked at some tutorials and experimented. I enabled command and key binding trace in console (http://eclipsesource.com/blogs/2009/07/08/tip-tracing-keybindings-in-rcp/).
I have created a custom command:
com.mycompany.myproduct.command.rename
This is what I got so far:
1) I tried to follow this tutorial,http://www.vogella.com/tutorials/EclipseCommandsKeybindings/article.html, but I came to the conclusion that this is for e3. This is because you need to add commands plugin that recognize only old e3 handlers. No xmi is involved
2) I tried to use xmi binding contexts. I had my command registered in the top level commands tree and connected to a handler in the top level handlers tree.
In the binding tables section I have a bindingTable that works in Dialog and Windows context. I added a key binding. The sequence is "F2" and it is connected to my custom command.
When I hit F2 I get the following message in trace:
COMMANDS >>> execute >>> starting: id=org.eclipse.ui.edit.rename; event=ExecutionEvent(Command(org.eclipse.ui.edit.rename,Rename,
Rename the selected item,
Category(org.eclipse.ui.category.file,File,null,true),
org.eclipse.ui.internal.MakeHandlersGo#1285594,
,,true),{},Event {type=1 Tree {} time=1480412218 data=null x=0 y=0 width=0 height=0 detail=0},org.eclipse.e4.ui.workbench.modeling.ExpressionContext#177fc1a)
In short the default eclipse IDE rename command is fired (my key binding does nothing), and nothing happens on my application.
However, if I change the sequece to "M1+1" and hit ctrl + 1, a little pop up comes up that lets me choose between "quick fix" (eclipse IDE command) and my rename. If I choose rename the handler fires.
Now, how do I disable eclipse IDE default keybindings. The instructions of the tutorial in step 1 definitely don't do it.
Thanks!
You can try to force E4 to read your key binding as an user one, adding the "type:user" tag to the KeyBinding itself :
I swear sometimes it seems like the application just likes to see us suffer. I had the same issue you had; a while ago my key binding was working just fine and today I notice it doesn't work anymore. Thanks for this post I found 2 solutions:
"type:user" from the above comment
remove org.eclipse.ui from the run configurations; it seems this was added when I pressed add required plugins after adding some plugin myself

Step to cursor/line eclipse debugger

Is there a possibility to step to any following line while debugging in eclipse?
It will help debug situations when I have a breakpoint at method beginning, I check something there, and below there is a for loop that i want to step through fast to see all changes it made at once.
Currently in the above scenario I put a breakpoint below the for-loop, hit F8, remove the breakpoint after execution stops which is pretty cumbersome.
Is there a better method of doing above?
Put break point at start of function.
Check XYZ. Come up to for loop.
Put your cursor after for loop.
Press CTRL + R.
HURRAY!!!!! I skiped for loop in debug.

debug the last sentence of a program

I have used Eclipse and VS. When I insert a breakpoint and debug the program, it will stop before the breakpoint.
But what if I want to debug the effect of the last sentence of the program? Inserting a meaningless sentence(say print 'pause' in Python) is OK but seems awkward. Is there any alternatives?
In Visual Studio you can put break point on closing bracket in main (or any) method of Program (or any) class (default naming, may vary), then debugger stops just before closing application.
Is there any reason not to use a breakpoint on the last statement, like you said, then manually proceed one step? Depending on the debugger, this can also be automated. In GDB, one can use commands N, where N is the breakpoint number, to set a list of (debugger) commands to be executed immediately after a breakpoint is hit.

shortcut to run concrete test

I can run the whole Junit test using:
Shift + Alt + X, T
But how I can run a single test? Using the mouse I click on concrete method and Run As -> Junit test
anyone know shortcut for this case ?
Thanks
Shift + Alt + X, T runs one test method if the caret is on the method name.
I find the "Shift-Alt-X" gives me trouble sometimes, sometimes what I think is the last executed command is not always and sometimes I end up running something I did not mean to. Also when doing TDD you rerun the tests so often and sometimes want to rerun the test from one project for a while, then you are on to the next project and want to start running its tests. Or you might be focusing on a specific area and only want to run a single unit test few a while. In this case I find I would like to simply rerun my last tests often and I find "Shift-Alt-X" to be a bit cumbersome.
So what I do is "Windows" > "Preferences" then click "General" > "Keys". Sort the table by "Command" and scroll down until you find "Rerun JUnit Test - Failures First" and "Rerun JUnit Test". Click on one of those and set the "Binding" field to whatever keyboard shortcut you want to use. Personally I set "Rerun JUnit Test" to CTRL+F5 so that its similar to refreshing a browser (plus this give me the quick and easy save/rerun combo of hitting CTRL+S, then CTRL+F5).
If you run the single test method as you described it will be the last entry in the "Run history". To run the test again you can simply click on the run button in the toolbar or press 'Ctrl-F11'.
F11 run test and activate window console.
Ctrl + F11 run test and activate window JUnit.
Years later, for me, what works is ALT+R+T+Enter which would run the last ran test whether it's a specific method or class. CTL-F11 for me only runs the last junit class even if the last run was a specific method of that junit class.
Shortcut: Ctrl+Alt+Shift+R - runs just one unit-test method. Set the caret to the method.

How can I set the current line of execution in the eclipse java debugger?

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?
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.
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.