![](/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.