Noeud:Finding Out Where You Are - Backtrace, Noeud « Next »:Moving Around the Call Stack - Up+Down, Noeud « Previous »:How to Use a Core Dump, Noeud « Up »:An example debugging session using gdb
gdb
keeps track of where you are in your program and how you got there. The line starting with #0
is the first entry in the call stack
which it keeps for all this information. If you use the command backtrace
(for which you can use the abbreviation bt
or the synonym where
), then it will show you the whole call stack.
(gdb) backtrace #0 strcpy (dest=0x0, src=0xbffffa9d "example") at ../sysdeps/generic/strcpy.c:40 #1 0x80484d5 in main (argc=2, argv=0xbffff964) at ecount2.c:26 #2 0x400382eb in __libc_start_main (main=0x8048490 <main>, argc=2, ubp_av=0xbffff964, init=0x8048308 <_init>, fini=0x804856c <_fini>, rtld_fini=0x4000c130 <_dl_fini>, stack_end=0xbffff95c) at ../sysdeps/generic/libc-start.c:129 (gdb)
Here we see that the call to strcpy()
came from line 26 of main()
. Above that in the call stack (although confusingly gdb
prints the stack out lowest level first...) is the __libc_start_main()
function, which is used by the compiler to do any initialisation etc. that it needs to before calling our main()
function. It is hardly ever worth going any higher than main unless you are debugging compilers themselves...