Home > database >  gdb debugger quits prematurely on popen(), 'signal SIGTRAP, Trace/breakpoint trap'?
gdb debugger quits prematurely on popen(), 'signal SIGTRAP, Trace/breakpoint trap'?

Time:12-02

The following code works in stand alone (non-debugging) mode. However gdb debugging stops when I tried to step over popen(), meaning a breakpoint at the fgets() can never be reached.

#include <stdio.h>

int main()
{
    char buff[10];
    FILE *f = popen("echo blah", "r");
    // program and debugger exit before this line
    // so that fgets() and printf() were never called
    fgets(buff, 5, f);
    printf("%s\n", buff);
}

GDB reports Program terminated with signal SIGTRAP, Trace/breakpoint trap. I dug into glibc's popen() and this is where it quits,

// internal-signal.h
/* Block all signals, including internal glibc ones.  */
static inline void
__libc_signal_block_all (sigset_t *set)
{
  INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigall_set, set,
             __NSIG_BYTES);
}

Does anyone knows what is going on here? thanks!

CodePudding user response:

Turned out to be a kernel issue, at least when I reverted back from 5.15.x to 5.14.x, the issue went away. I thought kernel update were never meant to break userspace.

  • Related