Sun Studio 12 Update 1: Debugging a Program With dbx

Displaying and Reading a Stack Trace

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 the following example, the program has crashed with a segmentation fault. The cause of the crash is most likely the null argument to strlen() in SPARC input register $i0.


(dbx) run
Running: Cdlib
(process id 6723)

CD Library Statistics:

 Titles:         1

 Total time:     0:00:00
 Average time:   0:00:00

signal SEGV (no mapping at the fault address) in strlen at 0xff2b6c5c
0xff2b6c5c: strlen+0x0080:    ld      [%o1], %o2
Current function is main
(dbx) where
  [1] strlen(0x0, 0x0, 0x11795, 0x7efefeff, 0x81010100, 0xff339323), at 0xff2b6c5c
  [2] _doprnt(0x11799, 0x0, 0x0, 0x0, 0x0, 0xff00), at 0xff2fec18
  [3] printf(0x11784, 0xff336264, 0xff336274, 0xff339b94, 0xff331f98, 0xff00), at 0xff300780
=>[4] main(argc = 1, argv = 0xffbef894), line 133 in "Cdlib.c"
(dbx)

For more examples of stack traces, see Looking at the Call Stack and Tracing Calls.