[英]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.