Stack trace
Encyclopedia : S : ST : STA : Stack trace
A stack trace (also called backtrace) is a report of the active stack frames instantiated by the execution of a program.
Stack traces are often generated when a program terminates abnormally. The last few stack frames often indicate where the bug that caused the abnormal termination occurs.
All debuggers can produce stack traces. gdb prints a stack trace with the bt (or where) command.
For example, this intentionally ill-written C program will segfault (i.e., crash) in the function function_2:
#include
int main(void)
int function_1(void)
int function_2(int x)To get an informative stack trace from a debugger, one has to compile the program with debugging information. With gcc, that is done by compiling the program with the -g option. If one then attempts to run the program in gdb, and obtain a backtrace, one would get
#0 0x080483cb in function_2 () #1 0x080483b4 in function_1 () #2 0x08048385 in main () #3 0x4003ddc6 in __libc_start_main () from /lib/libc.so.6This shows that the function __libc_start_main called main, which in turn called function_1 and then function_2, whose stack frame is at the top of the stack, and it is indeed this function which is in error, the statement:
int *y = (int *)x;attempts to create a pointer pointing to a nonsensical memory location at the decimal address 24, which is usually inaccessible by programs running normally.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
