Gdb backtrace for child process

I have an application that creates a child process.

The child process does some work, and somewhere in the middle it gives a segmentation error. I used GDB to debug it, I used:

set follow-fork-mode child 

I also set a breakpoint for the function inside the child. But GDB doesn't stop at my breakpoint.

Also the parent process handles seg-fault, so I had to ctrl-c exit. Then when I use backtrace to print the stack, all I have is

No stack

Why is no breakpoint set and why didn’t I get the stack?

+6
source share
1 answer

Why a breakpoint is not set

A breakpoint is set, but it does not fall because ...

and why didn’t I get the stack?

... you are apparently debugging the wrong process.

With set follow-fork-mode child GDB will follow the first child you created. Did you create more than one?

One way to debug is to install the SIGSEGV handler using signal or sigaction .

In the handler, do the following:

 void handler(int signo) { int i = 1; fprintf(stderr, "pid=%d, got signal=%d\n", getpid(), signo); while (i) { } } 

As soon as you see the message printed in another window:

  gdb /proc/<pid>/exe <pid> (gdb) where 
+7
source

Source: https://habr.com/ru/post/909913/


All Articles