0

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?

2 Answers 2

3

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) 
Sign up to request clarification or add additional context in comments.

Comments

1

Just type:

gstack pid

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.