|C H A P T E R 7|
Using the Call Stack
This chapter discusses how dbx uses the call stack, and how to use the where, hide, unhide, and pop commands when working with the call stack.
The call stack represents all currently active routines--routines that have been called but have not yet returned to their respective caller. A stack frame is a section to the call stack allocated for use by a single function.
Because the call stack grows from higher memory (larger addresses) to lower memory, up means going toward the caller's frame (and eventually main()) and down means going toward the frame of the called function (and eventually the current function). The frame for the routine executing when the program stopped at a breakpoint, after a single-step, or when a fault occurs and produces a core file, is in lower memory. A caller routine, such as main(), is located in higher memory.
This chapter is organized into the following sections:
Use the where command to find your current location on the stack.
When debugging an application that is a mixture of Java code and C JNI (Java Native Interface) code or C++ JNI code, the syntax of the where command is:
The where command is also useful for learning about the state of a program that has crashed and produced a core file. When this occurs, you can load the core file into dbx (see Debugging a Core File)
For more information on the where command, see where Command.
Moving up or down the stack is referred to as "walking the stack." When you visit a function by moving up or down the stack, dbx displays the current function and the source line. The location from which you start, home, is the point where the program stopped executing. From home, you can move up or down the stack using the up, down, or frame commands.
The dbx commands up and down both accept a number argument that instructs dbx to move a number of frames up or down the stack from the current frame. If number is not specified, the default is 1. The -h option includes all hidden frames in the count.
You can examine the local variables in functions other than the current one.
To move up the call stack (toward main) number levels:
If you do not specify number, the default is one level. For more information, see up Command.
To move down the call stack (toward the current stopping point) number levels:
If you do not specify number, the default is one level. For more information, see down Command.
The frame command is similar to the up and down commands. It lets you go directly to the frame as given by numbers displayed by the where command.
The frame command without an argument displays the current frame number. With number, the command lets you go directly to the frame indicated by the number. By including a + (plus sign) or - (minus sign), the command lets you move an increment of one level up (+) or down (-). If you include a plus or minus sign with a number, you can move up or down the specified number of levels. The -h option includes any hidden frames in the count.
You can also move to a specific frame using the pop command (see Popping the Call Stack).
You can remove the stopped in function from the call stack, making the calling function the new stopped in function.
Unlike moving up or down the call stack, popping the stack changes the execution of your program. When the stopped in function is removed from the stack, it returns your program to its previous state, except for changes to global or static variables, external files, shared members, and similar global states.
The pop command removes one or more frames from the call stack. For example, to pop five frames from the stack, type:
You can also pop to a specific frame. To pop to frame 5, type:
For more information, see pop Command.
Use the hide command to list the stack frame filters currently in effect.
To hide or delete all stack frames matching a regular expression, type:
The regular_expression matches either the function name, or the name of the loadobject, and uses sh or ksh syntax for file matching.
Use unhide to delete all stack frame filters.
Because the hide command lists the filters with numbers, you can also use the unhide command with the filter number.
A stack trace shows where in the program flow execution stopped and how execution reached this point. It provides the most concise description of your program's state.
To display a stack trace, use the where command.
For functions that were compiled with the -g option, the names and types of the arguments are known so accurate values are displayed. For functions without debugging information hexadecimal numbers are displayed for the arguments. These numbers are not necessarily meaningful. When a function call is made through function pointer 0, the function value is shown as a low hexadecimal number instead of a symbolic name.
You can stop in a function that was not compiled with the -g option. When you stop in such a function dbx searches down the stack for the first frame whose function is compiled with the -g option and sets the current scope (see Program Scope) to it. This is denoted by the arrow symbol (=>).
In the following example, main() was compiled with the -g option, so the symbolic names as well as the values of the arguments are displayed The library functions called by main() were not compiled with -g, so the symbolic names of the functions are displayed but the hexadecimal contents of the SPARC input registers $i0 through $i5 are shown for the arguments:
In this example, the program has crashed with a segmentation fault. Again only main() has been compiled with the -g option, so the arguments to the library functions are displayed as hexadecimal without symbolic names. The cause of the crash is most likely the null arguments to strlen() in SPARC input registers $i0 and $i1
For more examples of stack traces, see Looking at the Call Stack and Tracing Calls.