[英]How can I see memory leaks on MacOS Big Sur using CLion?
我不知道如何使用 CLion 在 MacOS Big Sur 上使用 CLion 看到 memory 泄漏,我已经尝试过这些事情:
Valgrind - 与 Big Sur 不兼容
Clang 的 Leak Sanitizer - 根据 CLion 的支持人员的说法,这显然与 MacOS 不兼容
在 CLion 中,我在 CMakeLists.txt 中编写了以下命令:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
然后我在地址消毒剂部分的首选项菜单->消毒剂中写了:
detect_stack_use_after_return=1
根据 CLion 支持页面,他们说 Leak Sanitizer 包含在 Address sanitizer 中。
假设您已经安装了 xcode 命令行开发工具,在 CLion 中打开终端window并尝试以下命令,其中 programname 是您正在构建的程序的名称:
leaks -atExit -- cmake-build-debug/programname
你得到 output 是这样的:
leaks Report Version: 4.0
Process 69522: 214 nodes malloced for 21 KB
Process 69522: 1 leak for 1008 total leaked bytes.
1 (1008 bytes) ROOT LEAK: 0x14c6067f0 [1008]
通常您可以在编译期间使用libasan
( https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer ) 但是在 MacOS 上还有一些额外的步骤:
https://clang.llvm.org/docs/AddressSanitizer.html (在此页面搜索“MacOS”以获得概述):
Memory 检漏
有关 AddressSanitizer 中泄漏检测器的更多信息,请参阅 LeakSanitizer。 Linux 上默认开启泄漏检测,并且可以在 macOS 上使用 ASAN_OPTIONS=detect_leaks=1 启用; 但是,其他平台尚不支持它。
来源: https://clang.llvm.org/docs/AddressSanitizer.html
另请参阅Mac OS:Leaks Sanitizer和https://developer.apple.com/documentation/xcode/diagnosing_memory_thread_and_crash_issues_early
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.