Question

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?

Was it helpful?

Solution

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) 

OTHER TIPS

Just type:

gstack pid

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top