You are probably running into an interaction between gdb and macOS SIP ("System Integrity Protection").
gdb implements run
redirections by passing the command line to the shell; then it waits for the shell to invoke your program before starting to "really debug". The shell is actually still controlled by gdb using ptrace
-- gdb uses this to observe the eventual exec and to ensure that your process is also traced.
However, SIP prevents certain programs from being traced, and in particular programs in /usr/bin
, like most shells. This causes run
to stop working entirely, because the shell can't be started.
So, to make gdb continue to work, users often set startup-with-shell off
. Perhaps whatever gdb build you are using does this by default (or maybe, like me, you put this in your .gdbinit
and forgot about it). This setting lets run
work -- but at the cost of disabling redirections.
There's a gdb bug for this which you can follow.