简体   繁体   English

为什么 Valgrind 返回可执行文件的退出代码?

[英]Why does Valgrind return executable file's exit code?

I want to run Valgrind in cp Linux command and watch the XML result of Valgrind.我想在 cp Linux 命令中运行 Valgrind 并观察 Valgrind 的 XML 结果。

when I run the below command to get XML output, the exit code is 1. because Valgrind runs the cp command.当我运行以下命令获取 XML output 时,退出代码为 1。因为 Valgrind 运行 cp 命令。

valgrind --xml=yes --leak-check=full --verbose --track-origins=no --xml-file=/home/user/Desktop/test/cp_valgrind.xml --log-file=/home/user/Desktop/test/cp_valgrind.txt --error-exitcode=100 /home/user/Desktop/test/cp

I got the below error:我收到以下错误:

/home/user/Desktop/test/cp: missing file operand
Try '/home/user/Desktop/test/cp --help' for more information.

Why does Valgrind return the executable file's exit code?为什么 Valgrind 返回可执行文件的退出代码? How can I run Valgrind on an executable file without Valgrind runs it?如何在没有 Valgrind 运行的可执行文件上运行 Valgrind?

Valgrind will return the guest return value by default. Valgrind 默认会返回 guest 返回值。

If you specify --error-exitcode then it will return that value if there is an error from the view of the Valgrind tool and the guest returns 0. It will still return the guest return value of the Valgrind tool detects no errors.如果您指定--error-exitcode那么如果从 Valgrind 工具的角度来看有错误并且来宾返回 0,它将返回该值。它仍然会返回 Valgrind 工具未检测到错误的来宾返回值。 It does not translate a guest error code into the value specified by --error-exitcode , or override a non-zero guest error code.它不会将访客错误代码转换为--error-exitcode指定的值,也不会覆盖非零访客错误代码。

In the table below invalid_free is a small testcase that generates a single memcheck error but returns 0.在下表中, invalid_free是一个小型测试用例,它会生成单个 memcheck 错误但返回 0。

No mem error, no guest error没有内存错误,没有访客错误 No mem error, guest error没有内存错误,来宾错误 Mem error, no guest error内存错误,无访客错误
Standalone单机 pwd;密码; echo $?回声$? -> 0 -> 0 cp; CP; echo $?回声$? -> 1 -> 1 invalid_free; invalid_free; echo $?回声$? -> 0 -> 0
Under memcheck在memcheck下 valgrind -q pwd; valgrind -q 密码; echo $?回声$? -> 0 -> 0 valgrind -q cp; valgrind -q cp; echo $?回声$? -> 1 -> 1 valgrind -q invalid_free; valgrind -q invalid_free; echo $?回声$? -> 0 -> 0
Under memcheck with --error-code在带有 --error-code 的 memcheck 下 valgrind -q --error-exitcode=42 pwd; valgrind -q --error-exitcode=42 pwd; echo $?回声$? -> 0 -> 0 valgrind -q --error-exitcode=42 cp; valgrind -q --error-exitcode=42 cp; echo $?回声$? -> 1 -> 1 valgrind -q --error-exitcode=42 invalid_free; valgrind -q --error-exitcode=42 invalid_free; echo $?回声$? -> 42 -> 42

and a 4th column that I can't fit without scrolling和第四列,我不滚动就无法适应

Mem error, guest error内存错误,来宾错误
Standalone单机 invalid_free2; invalid_free2; echo $?回声$? -> 1 -> 1
Under memcheck在memcheck下 valgrind -q invalid_free2; valgrind -q invalid_free2; echo $?回声$? -> 1 -> 1
Under memcheck with --error-code在带有 --error-code 的 memcheck 下 valgrind -q --error-exitcode=42 invalid_free2; valgrind -q --error-exitcode=42 invalid_free2; echo $?回声$? -> 1 -> 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM