Is there a way to jump to a line of code in Eclipse for Java?
It would be useful for re-running a function to debug.
Something like Visual Studio's "Set Next Statement" or the draggable yellow arrow?
When in the debugger select a place in the stack, right click, and select "Drop to Frame". This will unwind the call stack. You can do this on the current method (top of the call stack) to unwind to the top of the method. This doesn't work all the time for various reasons but you can do it pretty often.
This feature does not exist even conceptually in the JVM Tools Interface, much less in the Java Debug Wire Protocol that IDEs tend to interface with. Implementing it in an IDE would require creating (and mantaining) a custom build of Hotspot/JRockit/etc itself.
I also have not found it, and don't think it is supported. It's availability in Visual Studio (for C++ development) really spoiled me. It is very useful on occasion.
I'm unaware of any means to do so in Eclipse - and all obvious checks turn up nothing. I suspect there's an issue with how java works, as it's been available an awfully long time in Visual Studio and for Eclipse to have not matched it means it must not be a heavy task but an epic one.
I have found one rather silly way to rerun a method without going back to the previous frame.
e.g. you are in this function:
'public int compareTo(EVAL evalOther) {
int jRet = compareId(this.id, evalOther.id);
if (jRet == 0) {
jRet = compareXYZ(this.XYZ, evalOther.XYZ);
}
return jRet;
}'
let us say, after executing the first line, i.e.
int jRet = compareId(this.id, evalOther.id);
I want to rerun this line, I just make a minor change to it which will force a quick recompile of the same method . So it starts from the first line of the method again.
e.g. I change the line
'int jRet = compareEVALClass(this, evalOther);'
to
'int jRet = 0 + compareEVALClass(this, evalOther);'
Press Ctrl-S (or whatever your shortcut key is to Save file)
And then the function recompile and will restart from the first line again.
Agreed, this is not as great as Visual Studio's "Set next statement"
Related
I am using Android Studio IDE (v1.5.1) and its Gradle debugger to step thru my Java application. I can single-step, step-over, step-out, break, set breakpoints etc., but I cannot find a way to manually set the next instruction/statement to be executed or alter the execution flow.
An example of this feature is Visual Studio's "Set next statement" under the DEBUG menu. Another example is MSDOS's g =address where you can specify the next instruction to be executed.
Does the Android Studio Debugger provide a means to change or specify the execution point of the target application?
While this is not possible, I usually workaround in the case of simple blocks of code that I might want (or not) to jump.
First you catch the block in a if statement:
int foo = bar.toFoo();
...
boolean doThis = Boolean.TRUE;
(B) if (doThis) {
...
// stuff that I might want to jump
...
}
Here (B) is a breakpoint. Now when it is reached, I just click Evaluate expression and, if needed, evaluate doThis = false;.
One might argue that a decent compiler should get rid of doThis, but it actually works in Android Studio 1.5, probably thanks to Boolean.TRUE instead of true.
If willing to, Evaluate expression will also let you execute full blocks of code while stuck at the breakpoint.
I have a tool that will list failed tests, and I would like a way to open a fully qualified class and goto a method in Eclipse with a single string I can copy from the results. It can use any pattern whatsoever (I can change the test results layout), but could be something like this example:
com.my.package.StringUtilTest:testValueOf
I shall use it for re-running tests, but could work with any methods. It could go to the first option when there are overloads (won't matter for me). It could also list all options and allow me to paste the string and enter to go to the first option (being the only one in my case), or selecting the correct one from the very narrowed down options, just like Ctrl + O will do (note Ctrl + O will work on current file only though). It could even accept (or require!) the parameter types, won't matter. Anything like that would be a huge thanks. Some place where I can paste a single string on (in any way that it may have to be) to open a specific method.
I've been looking for a while, could be built-in or configured shortcut, macro, plugin, et cetera, but could neither find nor wrap my head around doing something (not expert on eclipsetalities)... I tried searching for a lot different stuff, but as you can see my problem can be solved with a vast pletora of things (none of which I can find anywhere though).
Eclipse jdt doesn't have it yet, but I believe an open method dialog similar to the open type dialog is in the works.. Please create a bug at bugs.eclipse.org if one doesn't exist describing what you would want in such a dialog.
If I write code sequentially, then after I enter some method call and opening parenthesis, I get a hint after delay:
if I discard it or return to the place later, I see no any hint:
How to invoke it without retyping the code?
Ctrl+P will give you a pop-up with the method parameters. Usefully, the parameter corresponding to your cursor position will be highlighted and will change as you move back and forth through the parameters.
Intellij provides a lot of assistance. See here for a summary of what's available.
I faced the same condition in the earlier days.
No need to retype the complete code but just retype the comma(,) intellij is intelligent enough to guess the next variable value and suggest you better. I used this many times so far and made me to save my time in all instances.
Hope i was useful.
On Mac the shortcut is ⌘ (Command) + P.
It works fine.
So I coded up a simple test program for an algorithm in Eclipse 3.7.2. When I went to go run it, I was met with some gray bar that appeared on the top portion of the console. It reads: <terminated> test[Java Application]C:\Program Files\Java\jre6\bin\javaw.exe. Anyone know what's causing this?
Your program is executing properly. The problem is in the logic of your program which is never allowing it to reach the print statement.
When you do
if(s==original)
return;
This statement s==original always returns true in your case since this operator will compare the two objects.
You need to rethink your logic here and google about what == operator does in Java.
Also, on another note, instead of using an array String[] s = {"a","b","c"}, why dont you use a string String s = "abc";
You Need to go to Control Panel > Windows Firewall and select Restore defaults but if you don't want to lose other settings, you could try Advanced Settings and find eclipse in there.
Eclipse is awesome for writing java programs but today I find that it's awesome to trick new coders like me. #_#
I write a snippet as following,
public static void main(String[] args) {
for(int i=0;i<3;i++){
System.out.println("i = " + i);
}
}
then I add a breakpoint at the line of "System.out.print....", click "Debug" button, eclipse goes to the "Debug" perspective and the line of breakpoint is highlighted, then I move the cursor over variable "i", its value is "0" as expected.
And then, I select the "i++" and click "Inspect"(or press "Ctrl+Shift+I") once, I move the cursor over variable "i", its value changed to "1". I repeat "Inspect" again, the value of i changed to "2"......(its value will add by 1 every time I clicked the "Inspect")!!
Why does this happend!? I ONLY want to watch the value of "i" for debug propuse, DO NOT want to really change its value until I step into next statement. I think that "Inspect", as well as "Display" are only for viewing the variable/expression, they should not impact the value, but in this case, it doesn't work as I expect to.
Could anyone tell me what went wrong?
My eclipse version info:
Version: Indigo Service Release 2
Build id: 20120216-1857
If you inspect an expression, eclipse has to execute that expression so you can get the value. Therefore, if you inspect i++, eclipse adds one to i.
Think about it this way: If instead of i++, you inspected myFunction(i), would you expect eclipse to execute the function "myFunction" to get the value? It's the same with i++.
If you are concerned about displaying/showing values while debugging and do you want to be sure not affecting the value, you should select the variable or expression and use the "Watch" option.
This will track the variable/expression value without executing, just updating the new value each time this is run. I think is the most secure way.
As Pablo mentioned, it has to evaluate the code in order to tell you what value it returns. You could instead put a watch on "i+1" and that would give you the value you want without the side effect you don't want.
Basically, you need to be aware of any side effects of anything you launch, whether from the "main" code or from the debugging tools. As Erhannis mentioned, this is very useful at times for modifying values while debugging your code. (For example, you can verify that a tweak/fix is indeed helpful before actually tweaking your code.)
You were expecting "an isolate area" but this would be extremely hard to do, especially in an object-oriented context where many objects are linked to many other objects. Running the whole thing in parallel might sometimes work, but you'd lose the tweaking ability above. And in any context, you'd run into tons of problems with fighting over resources; e.g. both copies trying to read/write a particular file such as a log file. Also, the two execution paths could diverge, leading to incorrect/misleading watch values.
So, preventing such side effects is not really a feasible option here and would rarely be useful anyway. Just expect that the watches can both reflect and affect the code execution.