Examining the call stack

The call stack is the hierarchy of function calls in your application's execution at a point in time. While the actual flow varies, typically in your code it begins in main, although what calls main differs from platform to platform. An obvious use for the call stack is to provide context when you click on the Interrupt button; if your program is just off contemplating its navel in a loop somewhere, clicking on Interrupt and taking a look at the call stack can give you a clue as to what's going on.

Remember how I defined the factorial function in terms of itself? You can see this very clearly if you put a breakpoint in the factorial and call it, and then continue through the breakpoint a few times before looking at the call stack. You'll see something akin to the following screenshot:

Working from left to right, the fields in the call stack window are the stack levels (numbering starts from the top of the stack and moves down), the functions being invoked, the files that the function is defined in, and the line numbers of the function currently being executed. So, this stack frame says that we're on line 9 of MathFunctions::factorial in mathfunctions.cpp, called by line 13 of MathFunctions::factorial, which is called by line 13 of MathFunctions::factorial... and so on, until it bottoms out in our main function and the system startup code that the operating system uses to set up the application process before that.

If you right-click on a line of the call stack pane, you can perform the following actions:

That's it; we have learned how to use the debugging tools to examine our application. Next, let's learn how to build our project!