Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making valgrind able to read user input when c++ needs it

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.

like image 684
Daniel Avatar asked Feb 11 '11 20:02

Daniel


2 Answers

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?

like image 101
Fred Larson Avatar answered Sep 22 '22 23:09

Fred Larson


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
like image 27
James Avatar answered Sep 21 '22 23:09

James