在 Mac OS X Mountain Lion 和 Mavericks 上是否有任何替代 valgrind 来检测 C/C++ 应用程序的内存泄漏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19719762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:05:36  来源:igfitidea点击:

Are there any alternatives to valgrind on Mac OS X Mountain Lion and Mavericks to detect memory leaks for C/C++ applications?

c++cosx-mountain-lionvalgrindosx-mavericks

提问by hago

I used to use valgrindto detect memory leaks for my C/C++ applications on Mac OS X 10.6 (Snow Leopard) and 10.7 (Lion), but I find it's not supported on recent releases like 10.8 (Mountain Lion) and 10.9 (Mavericks) when I upgraded my OS. Is there something else like valgrindthat can be installed on Mac OS X 10.9?

我曾经valgrind在 Mac OS X 10.6 (Snow Leopard) 和 10.7 (Lion) 上检测 C/C++ 应用程序的内存泄漏,但我发现最近的版本不支持它,例如 10.8 (Mountain Lion) 和 10.9 (Mavericks)我升级了我的操作系统。valgrind在 Mac OS X 10.9 上还有其他类似的东西可以安装吗?

回答by Jonathan Leffler

On 2013-11-01, the valgrindteam announced Valgrind 3.9.0:

2013-11-01,valgrind团队发布了 Valgrind 3.9.0:

We are pleased to announce a new release of Valgrind, version 3.9.0, available from http://www.valgrind.org.

3.9.0 is a feature release with many improvements and the usual collection of bug fixes. This release adds support for MIPS64/Linux, Intel AVX2 instructions and POWER8 instructions. DFP support has been added for S390. Initial support for hardware transactional memory has been added for Intel and POWER platforms. Support for Mac OS X 10.8 (Mountain Lion) has been improved. Accuracy of Memcheck on vectorized code has been improved.

我们很高兴地宣布 Valgrind 的新版本 3.9.0,可从http://www.valgrind.org 获得

3.9.0 是一个功能版本,具有许多改进和常见的错误修复集合。此版本增加了对 MIPS64/Linux、Intel AVX2 指令和 POWER8 指令的支持。已为 S390 添加了 DFP 支持。已为 Intel 和 POWER 平台添加了对硬件事务内存的初始支持。改进了对 Mac OS X 10.8 (Mountain Lion) 的支持。Memcheck 在矢量化代码上的准确性已得到改进。

It remains to be seen whether the improved Mountain Lion support means it works OK for Mavericks. It does mention that the support is only for 64-bit code.

改进的 Mountain Lion 支持是否意味着它适用于小牛队还有待观察。它确实提到仅支持 64 位代码。

[...time passeth...downloads happen...hopes are raised...configuration is attempted...hopes are dashed...]

[...时间过去...下载发生...希望提高...配置尝试...希望破灭...]

Urgh!

呃!

...
checking build system type... x86_64-apple-darwin13.0.0
checking host system type... x86_64-apple-darwin13.0.0
checking for a supported CPU... ok (x86_64)
checking for a 64-bit only build... no
checking for a 32-bit only build... no
checking for a supported OS... ok (darwin13.0.0)
checking for the kernel version... unsupported (13.0.0)
configure: error: Valgrind works on Darwin 10.x and 11.x (Mac OS X 10.6/7)

Mountain Lion is based on Darwin 12.x; Mavericks is based on Darwin 13.x. I'm not sure about the messaging in the error messages, but out of the box, Valgrind 3.9.0 does not compile on OS X Mavericks.

Mountain Lion 基于 Darwin 12.x;Mavericks 基于 Darwin 13.x。我不确定错误消息中的消息传递,但开箱即用,Valgrind 3.9.0 无法在 OS X Mavericks 上编译。

回答by chutsu

Just so you know, you may not have to wait for long to see Valgrind working on Mac 10.9 a.k.a Maverick. As there has been some success according to this bug report.

正如您所知,您可能无需等待很长时间即可看到 Valgrind 在 Mac 10.9 aka Maverick 上运行。因为根据这个错误报告已经取得了一些成功。

It is my opinion that there are currently (as of 15th November 2013) no Valgrind alternatives for the Mac. There are some to keep an eye on though, namely Clangwhich has both AddressSanitizer(works on current macs) and MemorySanitizer(macs not supported yet).

我认为目前(截至 2013 年 11 月 15 日)没有适用于 Mac 的 Valgrind 替代品。不过有一些需要注意,即Clang,它同时具有AddressSanitizer(适用于当前macs)和MemorySanitizerMacs尚不支持)。

There are suggestions to use Xcode's Instruments, but I did not find it useful at all.

有使用 Xcode 的 Instruments 的建议,但我觉得它根本没有用。

回答by user1118321

In addition to the Instruments that @Charlie_Burns mentions above, there's also the static analyzer that can tell you about some of these things just by analyzing your code. In your Xcode project, just select "Analyze" from the "Product" menu. It invokes the clangstatic analyzer. I think you can use clangdirectly from the command line if you want, too, though I've not done that.

除了@Charlie_Burns 上面提到的 Instruments 之外,还有静态分析器可以通过分析您的代码来告诉您其中一些事情。在您的 Xcode 项目中,只需从“产品”菜单中选择“分析”。它调用clang静态分析器。我认为clang如果你愿意,你也可以直接从命令行使用,虽然我没有这样做。

On the command line you also have access to the leakscommand and the dtracecommand.

在命令行上,您还可以访问leaks命令和dtrace命令。