0

I'm using GDB 8.0.1 on Mac OS High Sierra 10.13.3. Basically, doing:

(gdb) r < some_input_file.in

ignores the input file. It acts as if the command ran was simply

(gdb) r

The closest thread I found about this problem was Input redirection from file gdb but no solution was posted.

Any clues? Thanks!

1 Answers1

0

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.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • This bug is marked as fixed, but as far as I can tell, gdb input redirection does not work on gdb on MacOS Catalina as of now. – Klapaucius Klapaucius May 29 '20 at 16:46
  • You have to be sure to use the correct version of gdb. However, I think gdb isn't working on Catalina at all - there's no active macOS gdb maintainer, and there was some change to the system that made gdb stop working. – Tom Tromey Jun 02 '20 at 13:32
  • Oh, I got gdb to work fine on Catalina just from a standard ```brew install``` - it's just that the redirection doesn't work. In order to make it work though you need to code sign the binary, which is a bit of a hassle. I mostly followed these instructions: https://sourceware.org/gdb/wiki/PermissionsDarwin But I would have to agree that using gdb under catalina (and macos in general) might be more hassle than it's worth. – Klapaucius Klapaucius Jun 04 '20 at 18:40