Making valgrind able to read user input when it needs C ++

I am trying to run my C ++ program with valgrind, however I have some points in the program that require user input from stdin, but when I run valgrind, this will not allow the user to enter anything for the program, is there any way around this ?

Look all around, but did not find the answer.

+4
source share
2 answers

I have not tried, but 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 be used for input?

+2
source

Here is a Linux example where cgi (./myexe) reads from stdin. We put the input in the mystdin file. Thus, valgrind can read input from the terminal, we do -input-fd = 3 and tell the shell to redirect / dev / tty to file descriptor 3. So that we can control gdb, we add the stdin redirection from / dev / tty in the -db parameter -paramater for valgrind. This is probably the worst example. Hope this helps.

 valgrind --input-fd=3 --db-command='gdb -nw %f %p < /dev/tty' --db-attach=yes ./myexe < mystdin 3</dev/tty 
+1
source

Source: https://habr.com/ru/post/984780/


All Articles