valgrind --error-exitcode ,负值

valgrind --error-exitcode , negative values

如果 valgrind 报告错误(构建测试脚本),我正在尝试设置一个 自定义错误代码 ,但它似乎不起作用设置负值时预期,这就是我 运行 valgrind:

valgrind --leak-check=full --error-exitcode=-1 -q ./leaks

但是,returns 0(这是 leaks 的 return 值),而不是 -1

echo $?
0

如果设置了正值,它会按预期工作:

valgrind --leak-check=full --error-exitcode=1 -q ./leaks

echo $?
1

Valgrind manual,指定:

--error-exitcode=<number> [default: 0]

Specifies an alternative exit code to return if Valgrind reported any errors in the run. When set to the default value (zero), the return value from Valgrind will always be the return value of the process being simulated. When set to a nonzero value, that value is returned instead, if Valgrind detects any errors. This is useful for using Valgrind as part of an automated test suite, since it makes it easy to detect test cases for which Valgrind has reported errors, just by inspecting return codes.

有人知道为什么会出现这种行为吗?

使用 Valgrind-3.10.0

手册不准确,Valgrind 不能return负值,它在Valgrind's source。它将选项的值分配给 clo_eror_exitcode:

else if VG_INT_CLO (arg, "--error-exitcode", VG_(clo_error_exitcode)) {}

然后检查是否为正,否则忽略该选项。

if (VG_(clo_error_exitcode) > 0
    && VG_(get_n_errs_found)() > 0) {
   VG_(client_exit)( VG_(clo_error_exitcode) );
} else {
   /* otherwise, return the client's exit code, in the normal
      way. */
   VG_(client_exit)( VG_(threads)[tid].os_state.exitcode );
}

即使可以,也没有用 Linux, negative exit codes?