Step Over, Step In, and Step Out.
I want a better understanding of what to expect when pressing these buttons in a debugger.
There are a lot of language & tool specific debugger entries, but I couldn't find a generic explanation of the feature.
Step Over, Step In, and Step Out.
I want a better understanding of what to expect when pressing these buttons in a debugger.
There are a lot of language & tool specific debugger entries, but I couldn't find a generic explanation of the feature.
Simply put, this is how you advance ("step") through your code via the debugger, one line at a time. Here's an example of using Visual Studio debugger.
Suppose you have the following code:
public static void Main(string[] args)
{
int x = 4;
M(x);
}
private static void M(int x)
{
Console.WriteLine(x);
}
Suppose you put a breakpoint on the M(x)
line. When the debugger stops ("breaks"), you now have 3 options:
1. Step Over (F10)
If you press F10, you will step over the line M(x)
. The debugger will execute this method, but you will not go into it. On the console output, you will see 4
.
2. Step Into (F11)
If you press F11, the debugger will take you inside the M() method, allowing you to single-step (with F10 or F11) inside the M() method. If you keep pressing F11, you will enter additional methods (provided you have their source code available)
3. Step Out (Shift-F11)
Instead of single-stepping one line at a time, you can press Shift-F11 to step out of the current method, and return to the calling method. In this case, if you press Shift-F11 while inside the M()
method, you will be taken back to the calling Main()
method.
I hope this makes it clearer.
P.S. This is not Visual Studio specific, but a general concept of debugging. With the debugger, you always single-step over instructions, be that lines of code or assembly instructions. Step over/in/out are concepts you will find in every debugger, and they all mean the same thing.
There are additional things some debuggers allow you to do, such as Run to selected line. Here's more info about Visual Studio debugging capabilities: http://msdn.microsoft.com/en-us/library/y740d9d3.aspx
This will be IDE specific, so your question is targeted as being too broad.
But in general, this is what these terms mean.
When debugging code, if the current line is the call to a function, let's call it M(y).
If you Step In, then the debugger will start stepping into the function M(y).
If you chose Step Over, then the function M(y) will be executed and the debugger will stop at the next line after the call of the function M(y).
Step Out only works if you are already inside of M(y). Let's say you are in the middle of M(y) and you realize the bug is not there, and you'd like to continue on the first line of code after the call to M(y). That's when you pick Step Out.
Again, this will vary from IDE to IDE, but on my experience (more than 11 IDEs) this is the standard behaviour.