0

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!

QnA
  • 1,035
  • 10
  • 25
  • Try https://stackoverflow.com/questions/46627758/visual-studio-code-debugging-child-process-not-working – Alan Birtles Nov 28 '21 at 06:52
  • Thanks! I think your link is very much related to the issue I have. On paper, *I think* what I need is , `-gdb-set detach-on-fork on`, and `-gdb-set follow-fork-mode parent`, which should be the default gdb settings already. Nonetheless, I tried explicitly setting all four combinations of `on/off` with `parent/child`, yet none worked so far... – QnA Nov 28 '21 at 14:54

1 Answers1

0

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.

QnA
  • 1,035
  • 10
  • 25