I want to debug the whole flow of a java program .What is the difference between F5 and F6 in eclipse view in this case.
step into will dig into method calls
step over will just execute the line and go to the next one
Consider the following code with your current instruction pointer at the f(y);
line in main()
:
public class testprog {
static void f (int x) {
System.out.println ("f:num+0 is " + (x+0));
System.out.println ("f:num+1 is " + (x+1));
System.out.println ("f:num+2 is " + (x+2));
}
static void g (int x) {
System.out.println ("g:num+0 is " + (x+0));
}
public static void main(String args[]) {
int y = 7;
-> f(y);
g(9);
}
}
If you were to step into at that point, you will move to the System.out.println ("f:num+0 is " + (x+0));
line in f()
, stepping into the function call.
If you were to step over at that point, you will move to the g(9);
line in main()
, stepping over the function call.
Another useful feature of debuggers is the step out of or step return. With your current instruction pointer on the first line of f()
above (assume you've stepped into from the previous position), a step return will basically run you through the current function until you go back up one level. In other words, it will step through to g(9);
in main()
.
Eclipse (at least Europa, which is the only one I have handy right here) uses F5 for step into
, F6 for step over
and F7 for step return
.
When debugging lines of code, here are the usual scenarios:
- (Step Into) A method is about to be invoked, and you want to debug into the code of that method, so the next step is to go into that method and continue debugging step-by-step.
- (Step Over) A method is about to be invoked, but you're not interested in debugging this particular invocation, so you want the debugger to execute that method completely as one entire step.
- (Step Return) You're done debugging this method step-by-step, and you just want the debugger to run the entire method until it returns as one entire step.
- (Resume) You want the debugger to resume "normal" execution instead of step-by-step
- (Line Breakpoint) You don't care how it got there, but if execution reaches a particular line of code, you want the debugger to temporarily pause execution there so you can decide what to do.
Eclipse has other advanced debugging features, but these are the basic fundamentals.
See also
You can't go through the details of the method by using the step over. If you want to skip the current line, you can use step over, then you only need to press the F6 for only once to move to the next line. And if you think there's someting wrong within the method, use F5 to examine the details.