开发者

How to backtrace how main's called with gdb?

Inside the main,is there any command to show how's it inv开发者_JAVA技巧oked?


This might be what you're looking for, if I get the question right:

(gdb) help set backtrace past-main 
Set whether backtraces should continue past "main".
Normally the caller of "main" is not of interest, so GDB will terminate
the backtrace at "main".  Set this variable if you need to see the rest
of the stack trace.

so if you set it to on (and the debug info for the libc are available, cf. this anwser), you'll see a stack looking like that:

(gdb) where
#0  main () at ./functionPtr.c:8
#1  0x0000003c47e2139d in __libc_start_main (main=0x40052b <main>, argc=1, ubp_av=0x7fffffffde28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,     stack_end=0x7fffffffde18) at libc-start.c:226
#2  0x0000000000400449 in _start ()

with the surrounding libc-start.c code looking like that:

struct pthread *self = THREAD_SELF;

/* Store old info.  */
unwind_buf.priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
unwind_buf.priv.data.cleanup = THREAD_GETMEM (self, cleanup);

/* Store the new cleanup handler info.  */
THREAD_SETMEM (self, cleanup_jmp_buf, &unwind_buf);

/* Run the program.  */
result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜