The where command shows at any point in the execution what is called the stack trace. This stack is the sequence of function that are being executed at a given time. The order in which these functions appear in the stack is reversed with respect to the order in which they were invoked. For example:
(gdb) r Starting program: /home/test/gdb_use Program received signal SIGSEGV, Segmentation fault. 0x08048441 in check (table=0x804a008) at gdb_use.c:29 29 if ((table[y].data + 1) != table[y].next->data) (gdb) where #0 0x08048441 in check (table=0x804a008) at gdb_use.c:29 #1 0x0804849f in main (argc=1, argv=0xfefff604) at gdb_use.c:43 (gdb)
The previous message shows how the program execution has
been stopped in function check
, more precisely on line 29,
itself invoked from function main
on line 43. It should be
noted that functions appear in reversed order in which they where
invoked. First function to be invoked was the main
function.
By default, the debugger is always placed at the top most element in the stack. But sometimes it is required to traverse this stack and place the debugger in one of these functions. The up and down commands allow the debugger to set the current function to any element in the stack trace. This functionality will become more useful when combined with the data visualization capability.
(gdb) where #0 0x08048441 in check (table=0x804a008) at gdb_use.c:29 #1 0x0804849f in main (argc=1, argv=0xfefff604) at gdb_use.c:43 (gdb) up #1 0x0804849f in main (argc=1, argv=0xfefff604) at gdb_use.c:43 43 if (check(buf)) (gdb) down #0 0x08048441 in check (table=0x804a008) at gdb_use.c:29 29 if ((table[y].data + 1) != table[y].next->data) (gdb)