How to redirect Valgrind's output to a file?

2019-03-07 21:31发布

While working with Valgrind tool, i need to log the details produced by valgrind tool. How can I accomplish that? I tried something like,

 valgrind a.out | test

and

 valgrind a.out > test

It gave just the program's output and not the valgrind memory error,leak information. Even i am getting like this if the program requires no user interaction (i.e. giving input). If the program need user input even that thing itself won't work.

How can I do this?

3条回答
forever°为你锁心
2楼-- · 2019-03-07 21:54

By default, Valgrind writes its output to stderr. So you need to do something like:

valgrind a.out > log.txt 2>&1

Alternatively, you can tell Valgrind to write somewhere else; see http://valgrind.org/docs/manual/manual-core.html#manual-core.comment (but I've never tried this).

查看更多
神经病院院长
3楼-- · 2019-03-07 21:57

You can also set the options --log-fd if you just want to read your logs with a less. For example :

valgrind --log-fd=1 ls | less
查看更多
一纸荒年 Trace。
4楼-- · 2019-03-07 21:58
valgrind --log-file="filename"
查看更多
登录 后发表回答