I am trying to run my c++ program with valgrind, however I have some points in the program which require user input from stdin, but when i run with valgrind, it wont let the user input anything for the program, is there a way around this?
Been searching all around but have not found the answer.
I haven't tried it, but I found this in the man pages:
--input-fd=<number> [default: 0, stdin]
Specify the file descriptor to use for reading input from the
user. This is used whenever valgrind needs to prompt the user
for a decision.
What happens if you specify a different fd (say, 3) for valgrind to use for input?
Here's a linux example where a cgi program (./myexe) reads from stdin. We put the input into a file mystdin. So valgrind can read input from the terminal, we do the --input-fd=3 and tell the shell to redirect /dev/tty to file descriptor 3. So that we can control gdb, we add a redirect of stdin from /dev/tty in the --db-command paramater to valgrind. This is probably a worse case example. Hope it helps.
valgrind --input-fd=3 --db-command='gdb -nw %f %p < /dev/tty' --db-attach=yes ./myexe < mystdin 3</dev/tty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With