Valgrind 标志,调试与发布编译
Valgrind flags, debug vs release compilation
在 Jenkins 实例上,我需要 Valgrind 检查 C++ 编译的二进制文件中是否存在特定问题。但是,我只需要一个是/否的答案,而不是堆栈跟踪。如果它们有任何问题,我将在错误代码上启动 valgrind,并在我的个人计算机上激活调试标志。在 Linux 运行 机器(针对 gcc)上使用 CMake 管理构建。
如果我在 Jenkins 实例上使用 -DCMAKE_BUILD_TYPE=Release
编译我的代码,Valgrind 是否会在二进制文件中检测到与 -DCMAKE_BUILD_TYPE=Debug
相同的问题?
Valgrind 通过在运行时检测和替换部分代码来工作,例如将调用重定向到内存分配函数。为此,它不依赖于调试信息,但它可能会被优化的代码混淆:
If you are planning to use Memcheck: On rare occasions, compiler
optimisations (at -O2 and above, and sometimes -O1) have been observed
to generate code which fools Memcheck into wrongly reporting
uninitialised value errors, or missing uninitialised value errors. We
have looked in detail into fixing this, and unfortunately the result
is that doing so would give a further significant slowdown in what is
already a slow tool. So the best solution is to turn off optimisation
altogether.
(from the Valgrind manual)
由于 Release
构建类型使用优化,因此不适合您的情况。
在 Jenkins 实例上,我需要 Valgrind 检查 C++ 编译的二进制文件中是否存在特定问题。但是,我只需要一个是/否的答案,而不是堆栈跟踪。如果它们有任何问题,我将在错误代码上启动 valgrind,并在我的个人计算机上激活调试标志。在 Linux 运行 机器(针对 gcc)上使用 CMake 管理构建。
如果我在 Jenkins 实例上使用 -DCMAKE_BUILD_TYPE=Release
编译我的代码,Valgrind 是否会在二进制文件中检测到与 -DCMAKE_BUILD_TYPE=Debug
相同的问题?
Valgrind 通过在运行时检测和替换部分代码来工作,例如将调用重定向到内存分配函数。为此,它不依赖于调试信息,但它可能会被优化的代码混淆:
If you are planning to use Memcheck: On rare occasions, compiler optimisations (at -O2 and above, and sometimes -O1) have been observed to generate code which fools Memcheck into wrongly reporting uninitialised value errors, or missing uninitialised value errors. We have looked in detail into fixing this, and unfortunately the result is that doing so would give a further significant slowdown in what is already a slow tool. So the best solution is to turn off optimisation altogether. (from the Valgrind manual)
由于 Release
构建类型使用优化,因此不适合您的情况。