您的位置:首页 > 其它

如何查看一个函数的调用流程

2014-08-21 14:08 169 查看
如果函数的调用比较深,跳来跳去的看源码好像很麻烦,其实可以用gdb的查看栈信息来实现,这个是在陶辉的nginx module开发里面学来的。

比如要看nginx是如何进入ngx_XXX_handler方法的,栈信息如下所示:

#0 ngx_XXX_handler (r=0x6d5650)
at nginx_XXX_module/ngx_XXX_module.c:646
#1 0x0000000000429e77 in ngx_http_core_content_phase (r=0x6d5650, ph=0x6e17d8)

at src/http/ngx_http_core_module.c:1262

#2 0x00000000004292d0 in ngx_http_core_run_phases (r=0x6d5650)

at src/http/ngx_http_core_module.c:800

#3 0x0000000000429284 in ngx_http_handler (r=0x6d5650)

at src/http/ngx_http_core_module.c:783

#4 0x000000000043165c in ngx_http_process_request (r=0x6d5650)

at src/http/ngx_http_request.c:1615

#5 0x0000000000430845 in ngx_http_process_request_headers (rev=0x6d60d0)

at src/http/ngx_http_request.c:1064

#6 0x00000000004303a0 in ngx_http_process_request_line (rev=0x6e3730)

at src/http/ngx_http_request.c:869

#7 0x000000000042fa8a in ngx_http_init_request (rev=0x6e3730)

at src/http/ngx_http_request.c:510

#8 0x0000000000422d6f in ngx_epoll_process_events (cycle=0x6cb1d0, timer=Variable "timer" is not available.

)

at src/event/modules/ngx_epoll_module.c:518

#9 0x00000000004181cb in ngx_process_events_and_timers (cycle=0x6cb1d0)

at src/event/ngx_event.c:245

#10 0x0000000000420351 in ngx_worker_process_cycle (cycle=0x6cb1d0, data=Variable "data" is not available.

)

at src/os/unix/ngx_process_cycle.c:791

#11 0x000000000041e19b in ngx_spawn_process (cycle=0x6cb1d0,

proc=0x420271 <ngx_worker_process_cycle>, data=0x0, name=0x5171a4 "worker process",

respawn=-3) at src/os/unix/ngx_process.c:194

#12 0x000000000041f8df in ngx_start_worker_processes (cycle=0x6cb1d0, n=1, type=-3)

at src/os/unix/ngx_process_cycle.c:355

#13 0x000000000041f24d in ngx_master_process_cycle (cycle=0x6cb1d0)

at src/os/unix/ngx_process_cycle.c:136

#14 0x0000000000403dea in main (argc=1, argv=Variable "argv" is not available.

) at src/core/nginx.c:396

这样函数是怎么执行调用的,一目了然。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: