Using the Call Stack Window
The Call Stack window displays the nested method calls currently on the stack. You can access the Call Stack Window from the Debug menu by selecting Windows and choosing Call Stack.
Whenever a method is called, an entry is added to the call stack. When this method calls another method, another entry is added to the stack. When a method is completed, its entry is removed from the call stack. The current method is always displayed at the top of the call stack, and the method from where it was called is displayed directly below.
The Call Stack Window is only enabled and up to date when the program is in break mode. As you step through the program, the window is automatically updated to reflect changes.
Message Delegation and Runtime Class Methods
Calling a method can be referred to as “sending a message.” If an object cannot resolve a message, it can choose to delegate to its parent object. When a message is delegated, it’s also displayed in the call stack, allowing you to inspect how a message was delegated. This is handled by the runtime, and although you can see the entry on the call stack, there’s no corresponding source code available.
Methods implemented in runtime classes cannot be stepped into, and there’s no corresponding source code, but they may, of course, in turn call other methods. Thus, methods implemented in the runtime are also displayed in the call stack so that you can inspect how nested calls were invoked.
The above conditions are not always apparent by viewing source code and single stepping through a program. However, when single stepping is used in conjunction with the call stack, you will be able to see exactly what your program is doing.
Switching Call Stack Frame and Method Context
To switch to another call stack frame, click the specified entry in the Call Stack Window. Clicking a Call Stack entry takes you to the source code for the current line in that call stack frame, and the Local Variables Window is updated with the local variables for that method context.
By switching Call Stack frames, you can easily follow the code and see how each method calls the next, and inspect local variables for each method call context. It quickly allows you to go back and forth in the Call Stack and inspect the various conditions of each call stack frame and the code that invoked the next call. This, in combination with inspecting variables and stepping through code, are probably the most important features of debugging.