2011-03-28 35 views
0

main裏面,是否有任何命令顯示它是如何被調用的?如何追溯main調用gdb的方式?

+0

你正在尋找一種在'main()'中產生回溯的方法,或者你只是想在調試器中看到回溯? – 2011-04-04 07:32:17

回答

0

這可能是你在找什麼,如果我得到正確的問題是:

(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);