Stack Trace

A stack trace (also called backtrace) is a dump of the active stack frames left in memory by the execution of a program. Stack traces are often generated when a program aborts abnormally. The last or penultimate stack frames often indicate where the bug that generated the abnormal abort occurs. All debuggers can produce stack traces. gdb prints a stack trace with the bt (or where) command.

Example

This intentionally ill-written C program will segfault (ie., crash) in the function function_2:
  int  main(void)  {     int x;     printf("This program will demonstrate gdb\n");     x=function_1();     printf("%d", x);      return 0;  }    int  function_1(void)  {     int x = function_2(24);     return x;  }    int  function_2(int x)  {     int *y = (int *)x;     return *y;  } 
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.6 
This 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 normally inaccessible by programs running normally.

 

<< PreviousWord BrowserNext >>
kremerata baltica
oscar henrquez
deux montagnes regional county municipality, quebec
drummond regional county municipality, quebec
francheville regional county municipality, quebec
joliette regional county municipality, quebec
albert sacco
kamouraska regional county municipality, quebec
rita and runt
uk elections, 2003
municipalities of the canton of aargau
municipalities of the canton of berne
salizhan sharipov
belo
durrington walls
la cte de beaupr regional county municipality, quebec
postnik yakovlev
anatoly solovyev
la cte de gasp regional county municipality, quebec
lac saint jean est regional county municipality, quebec
gennady strekalov
giomar guevara
treaty of vereeniging
municipalities of the canton of fribourg
la haute cte nord regional county municipality, quebec
edgar ramos
arroyo seco raceway
la haute yamaska regional county municipality, quebec
dilson torres
la jacques cartier regional county municipality, quebec
denman ross
lajemmerais regional county municipality, quebec
juan castillo
municipalities of the canton of graubnden
danilo len
emperor bing of song china
municipalities of the canton of ticino
ramn garca
la matapdia regional county municipality, quebec
l'amiante regional county municipality, quebec
la mitis regional county municipality, quebec
la nouvelle beauce regional county municipality, quebec
thornborough henges
la rgion sherbrookoise regional county municipality, quebec