![](/img/trans.png)
[英]GetCurrentDirectory does not really return the path of the executable file
[英]Why does Valgrind return executable file's exit code?
我想在 cp Linux 命令中运行 Valgrind 并观察 Valgrind 的 XML 结果。
当我运行以下命令获取 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
我收到以下错误:
/home/user/Desktop/test/cp: missing file operand
Try '/home/user/Desktop/test/cp --help' for more information.
为什么 Valgrind 返回可执行文件的退出代码? 如何在没有 Valgrind 运行的可执行文件上运行 Valgrind?
Valgrind 默认会返回 guest 返回值。
如果您指定--error-exitcode
那么如果从 Valgrind 工具的角度来看有错误并且来宾返回 0,它将返回该值。它仍然会返回 Valgrind 工具未检测到错误的来宾返回值。 它不会将访客错误代码转换为--error-exitcode
指定的值,也不会覆盖非零访客错误代码。
在下表中, invalid_free
是一个小型测试用例,它会生成单个 memcheck 错误但返回 0。
没有内存错误,没有访客错误 | 没有内存错误,来宾错误 | 内存错误,无访客错误 | |
---|---|---|---|
单机 | 密码; 回声$? -> 0 | CP; 回声$? -> 1 | invalid_free; 回声$? -> 0 |
在memcheck下 | valgrind -q 密码; 回声$? -> 0 | valgrind -q cp; 回声$? -> 1 | valgrind -q invalid_free; 回声$? -> 0 |
在带有 --error-code 的 memcheck 下 | valgrind -q --error-exitcode=42 pwd; 回声$? -> 0 | valgrind -q --error-exitcode=42 cp; 回声$? -> 1 | valgrind -q --error-exitcode=42 invalid_free; 回声$? -> 42 |
和第四列,我不滚动就无法适应
内存错误,来宾错误 | |
---|---|
单机 | invalid_free2; 回声$? -> 1 |
在memcheck下 | valgrind -q invalid_free2; 回声$? -> 1 |
在带有 --error-code 的 memcheck 下 | valgrind -q --error-exitcode=42 invalid_free2; 回声$? -> 1 |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.