在main
中,是否有任何命令可以显示它是如何调用的?
最佳答案
如果我答对了问题,这可能就是您正在寻找的内容:
(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.
因此,如果您将其设置为 on
(并且 libc
的调试信息可用,参见 this anwser ),您将看到一个堆栈,如下所示那:
(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 ()
与周围libc-start.c
代码如下:
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);
关于gdb - 如何使用 gdb 回溯 main 的调用方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5461731/