开发者

How to know which function is calling system call?

I use strace to trace my app,and find it is blocked at a system call "poll",I want to figure out which function is calling开发者_运维问答 this system call.How?


Did you compile your program with debugging information (the -g flag for gcc)? Fire up your debugger and get a stack trace!

Example program (example.c):

#include <poll.h>

void f2(void)
{
  struct pollfd fd = {0, POLLERR, POLLERR};
  poll(&fd, 1, -1);
}

void f1(void)
{
  f2();
}

int main(int argc, char **argv[])
{
  f1();    
  return 0;
}

Example build & backtrace:

$ CFLAGS=-g make example
cc -g    example.c   -o example
$ gdb example    
(gdb) run
Starting program: example 
Reading symbols for shared libraries +. done
^C
Program received signal SIGINT, Interrupt.
0x00007fff821751a6 in poll ()
(gdb) bt
#0  0x00007fff821751a6 in poll ()
#1  0x0000000100000ea6 in f2 () at example.c:6
#2  0x0000000100000eb1 in f1 () at example.c:11
#3  0x0000000100000ec7 in main (argc=1, argv=0x7fff5fbff750) at example.c:16
(gdb) 


Just type:

gstack pid

to get a stack trace of your program with the specified process id.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜