I want to debug the whole flow of a (Java) program. I see there are several options for stepping through my program. What is the difference between step into and step over?
Consider the following code with your current instruction pointer (the line that will be executed next, indicated by ->
) at the f(x)
line in g()
, having been called by the g(2)
line in main()
:
public class testprog {
static void f (int x) {
System.out.println ("num is " + (x+0)); // <- STEP INTO
}
static void g (int x) {
-> f(x); //
f(1); // <----------------------------------- STEP OVER
}
public static void main (String args[]) {
g(2);
g(3); // <----------------------------------- STEP OUT OF
}
}
If you were to step into at that point, you will move to the println()
line in f()
, stepping into the function call. You step into any function that you're ready to call.
If you were to step over at that point, you will move to the f(1)
line in g()
, stepping over the function call.
Note that there is no real difference between step-into and step-over if the code you're about to execute is not a function invocation of some sort. For example, both of them would simply execute the statement xyzzy = 42;
and move on to the next statement.
Another useful feature of debuggers is the step out of or step return. In that case, it will basically run you through the current function until you go back up one level. In other words, it will step through f(x)
and f(1)
, then back out to the calling function to end up at g(3)
in main()
.