如何在整个项目上运行消毒剂
我正在尝试熟悉 ASAN、LSAN 等消毒剂,并从这里获得了很多有用的信息:https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind
我能够对特定文件运行各种清理程序,如网站上所示,如下所示:
clang -g -fsanitize=address -fno-omit-frame-pointer -g ../TestFiles/ASAN_TestFile.c
ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer ./a.out >../Logs/ASAN_C.log 2>&1
这会生成包含发现问题的日志。现在我想扩展它以在使用 cmake 构建项目时运行。这是目前构建它的命令:
cmake -S . -B build
cd build
make
有什么方法可以使用此脚本添加消毒剂,而不必更改 cmakelist.txt 文件?
例如这样的事情:
cmake -S . -B build
cd build
make -fsanitize=address
./a.out >../Logs/ASAN_C.log 2>&1
原因是我希望能够使用不同的消毒剂多次构建项目(因为它们不能一起使用),并在不更改 cmakelist.txt 文件的情况下创建日志(只是希望能够快速测试整个项目的内存问题,而不是对创建的每个文件进行测试)。
I'm trying to get familiar with sanitizers as ASAN, LSAN etc and got a lot of useful information already from here: https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind
I am able to run all sort of sanitizers on specific files, as shown on the site, like this:
clang -g -fsanitize=address -fno-omit-frame-pointer -g ../TestFiles/ASAN_TestFile.c
ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer ./a.out >../Logs/ASAN_C.log 2>&1
which generates a log with found issue. Now I would like to extend this to run upon building the project with cmake. This is the command to build it at the moment:
cmake -S . -B build
cd build
make
Is there any way I can use this script with adding the sanitizers, without having to alter the cmakelist.txt file??
For instance something like this:
cmake -S . -B build
cd build
make -fsanitize=address
./a.out >../Logs/ASAN_C.log 2>&1
The reason is that I want to be able to build the project multiple times with different sanitizers (since they cannot be used together) and have a log created without altering the cmakelist.txt file (just want to be able to quickly test the whole project for memory issues instead of doing it for each file created).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在构建配置期间从命令行中添加其他编译器标志:
如果您的cmakelists.txt适当配置了上面的配置。如果那不起作用,请尝试将标志添加为环境变量:
You can add additional compiler flags from command line during the build configuration:
If your CMakeLists.txt is configured properly above should work. If that does not work then try adding flags as environment variable: