Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a pipe as input for valgrind?

Tags:

linux

valgrind

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.

like image 752
evoliptic Avatar asked Apr 07 '15 10:04

evoliptic


People also ask

How do you integrate Valgrind?

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.

How can I make my Valgrind faster?

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.

Can you run GDB with Valgrind?

Note that Valgrind provides instructions for starting GDB as well as the command to use in order to connect GDB with Valgrind.


1 Answers

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).

like image 162
Owen DeLong Avatar answered Nov 02 '22 16:11

Owen DeLong