It seems that input redirection in gdb does not work in Cygwin e.g
(gdb) run < input.txt
Is there other way to redirect input in gdb of Cygwin??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately this is not possible when running gdb in cygwin. The bug exists for a quote long time, but apparently it’s a hard one to fix – and probably the gdb devs prefer spending time on features/issues relevant to more common environments (such as Linux).
There are various possible workarounds; I’d prefer the first one since it’s the cleanest and also useful while not debugging / running on cygwin:
-f whateverwithwhateverbeing the filename to read from. If the argument is not present or set to-, read from stdin. The-f -option is optional of course but for arguments accepting filenames it’s a common standard (as long as it makes sense) to handle-as “use stdin/out”.Use the gdb hack mentioned here to remap stdin to a manually opened file inside the application:
This sets a breakpoint on the
mainfunction, then executes the program which will break right after enteringmain. Thendup2is used to replace the stdin fd (0) with a file descriptor of the input file.