如何将 Valgrind 与介子一起使用?

How to use Valgrind with Meson?

project('testproject', 'cpp')

src = ['a.cpp', 'b.cpp']

executable('test', src)

使用 Meson 构建系统通过 Valgrind 构建我的可执行文件的最简单方法是什么?

valgrind是一个动态分析工具,不需要专门为valgrind重新编译

例如,您可以这样做:

valgrind ls

valgrind 将 运行 并分析 ls 命令。

注意还是建议带上调试信息编译,不然valgrind的报错不太好理解

http://www.valgrind.org/docs/manual/QuickStart.html

中提供了有关如何使用 valgrind 的介绍

为了完整起见,需要注意 valgrind 可以在 meson 命令行中用作包装器,例如

$ meson test --wrap='valgrind --leak-check=full --error-exitcode=1' testname

$ meson test --wrap='valgrind --tool=helgrind -v --error-exitcode=1' testname

可以与其他测试选项结合使用,例如

$ meson test --wrap='valgrind --leak-check=full --error-exitcode=1' testname --repeat=100

查看参考手册this page