I would like to check my program memory using almost automated tools (I'm not good at gdb yet), and so I ended up using valgrind.
However, I would like to put a pipe as the input of valgrind; i.e. I would like to put the following:
>cat file.h | ./prog
I tried to make a
>valgrind `cat file.h | ./prog`
without success.
I also tried to make a script file where I put the whole command, and then pass it to valgrind, with no more success.
To run Valgrind, pass the executable as an argument (along with any parameters to the program). The flags are, in short: --leak-check=full : "each individual leak will be shown in detail" --show-leak-kinds=all : Show all of "definite, indirect, possible, reachable" leak kinds in the "full" report.
Valgrind doesn't actually execute your code natively - instead it runs it inside a simulator. That's why it's so slow. So, there's no way to make it run faster, and still get the benefit of Valgrind. Your best bet is to set the ulimit so that your program generates a core file when it crashes.
Note that Valgrind provides instructions for starting GDB as well as the command to use in order to connect GDB with Valgrind.
As mentioned in the comments, you should be able to use either of:
cat file.h | valgrind ./prog
valgrind ./prog < file.h
The first one uses a pipe as you specifically requested and could just as easily be the output of any program e.g.
ls -al | valgrind ./prog
ps -axuwww | valgrind ./prog
The latter one is more efficient if you're just trying to grab the contents of a file.
The backtick method you tried is not for what you are doing here. It's for situations where you want the output of one command to be the arguments for another (e.g. ls -al cat namelist
to do a long detailed listing of all files named in in a file called nameless).
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