gdb - 如何使用 gdb 回溯 main 的调用方式?

标签 gdb program-entry-point

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/

相关文章:

c++ - 为什么 gdb 不能附加到由 inetd 调用的服务器应用程序?

linux - 如何从Core Dump中提取EBP和ESP?

java - 当具有访问修饰符 public 的类具有文件名和类名不同的 java 文件时会发生什么

java - 搜索主类的图像?

java - 将 Java applet 项目导入 netbeans 将无法正常工作,即使手动设置,Netbeans 也拒绝识别甚至找不到主类

linux - 为什么 gdb 回溯系统调用地址与系统调用表地址不同

string - assembly GDB 打印字符串

ios - 为什么 UIApplicationMain 函数被命名为类命名风格

Python,多处理库问题

c - 负载很大才出现的bug怎么调试?