在使用Valgrind工具时,我需要记录Valgrind工具生成的细节信息。我该如何实现?我尝试了以下方法:
valgrind a.out | test
并且
valgrind a.out > test
当程序不需要用户交互(即输入)时,它只提供程序的输出信息而没有valgrind内存错误和泄漏信息。如果程序需要用户输入,即使是那样也无法工作。
我该如何做?
valgrind --log-file="filename"
默认情况下,Valgrind 将其输出写入 stderr。因此,您需要执行以下操作:
```valgrind a.out > log.txt 2>&1
另外,您可以告诉Valgrind将输出写到其他位置; 参见http://valgrind.org/docs/manual/manual-core.html#manual-core.comment(但我从未尝试过这个功能)。
a.out
的输出发送到同一个日志文件。如果你想将valgrind的输出保存到日志文件中而不包括a.out
的输出,你应该使用Lex提供的--log-file
选项。 - edamvalgrind ./struct -v --leak-check=full 2>&1 | nc -N paste.ubuntu.ir 1337
- EsmaeelE如果您只想使用较少的日志记录方式查看日志,则还可以设置选项--log-fd。
例如:
valgrind --log-fd=1 ls | less
--log-file=
中使用,这在 Valgrind 用户手册 中有详细说明。%p
: 打印当前进程 ID
valgrind --log-file="myFile-%p.dat" <application-name>
%n
: 打印当前进程唯一的文件序列号
valgrind --log-file="myFile-%p-%n.dat" <application-name>
%q{ENV}
: 打印环境变量 ENV
的内容
valgrind --log-file="myFile-%q{HOME}.dat" <application-name>
%%
: 打印字符 %
valgrind --log-file="myFile-%%.dat" <application-name>
valgrind a.out &> file
- sidyll