What is the difference between Step Into and Step Over in a debugger

Method of Communicating with a Debugger

(Or, how I explain my road trip to my grandmother)

Step Into: "When the next statement to execute reaches a method call, dont execute the method as a whole, but rather, execute the first line of that method and stop"

Step Over: "When the next statement to execute reaches a method call, execute the method as a whole and stop"

Step Out: "Finish off executing the callee's code and stop when execution returns to the caller"

Continue: "Execute up until the next breakpoint"

Here is a great example to practically demonstrate the concepts above:

enter image description here


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

  • Free video tutorial: Eclipse and Java: Using the Debugger
  • IBM/DeveloperWorks/Debugging with the Eclipse Platform
  • IBM/DeveloperWorks/Learn the essentials of debugging

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.

If you were to step over at that point, you will move to the f(1) line in g(), stepping over the function call.

Another useful feature of debuggers is the step out of or step return. In that case, 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 f(x) and f(1), then back out to the calling function to end up at g(3) in main().


step into will dig into method calls
step over will just execute the line and go to the next one

Tags:

Debugging