As far back as the late ’90s, broken command line redirection was a known and assumed limitation. My suspicion is that it remains that way, since the mingw32
port of gdb
still gleefully passes on verbatim all run
arguments (including redirects) to the debugee.
Several possible workarounds:
- if you have the option to alter the command line interface, then implement
bbadour
‘s suggestion - otherwise, if you can easily suspend the process before the point you want to debug at, invoke the debugee (with redirection) from a shell and attach to it while it is already running
-
otherwise, if you have symbols for the debugee (
gcc -g
) or you know the address ofmain()
(gcc -Wl,-Map,mapfile
) and can set a breakpoint there, proceed in the following manner (tested withmingw gdb 6.8.0
):# gdb debugee.exe (gdb) b main (gdb) run non-redirect-arguments-if-any (gdb) p dup2(open("/tmp/input.txt", 0), 0) (gdb) c