简体   繁体   English

在命令行上对 C 程序使用 OSX Leaks?

[英]Using OSX Leaks for C Programs on the Command Line?

Can anyone give me any simple syntax for running OSX's leaks tool for detecting memory leaks in a compiled C program?任何人都可以给我任何简单的语法来运行 OSX 的leaks工具来检测已编译 C 程序中的内存泄漏吗? I'm on 10.8, so I'm running into serious compatibility issues with valgrind .我在 10.8 上,所以我valgrindvalgrind严重兼容性问题。

Most of the stuff I've read about XCode's Leaks/Instruments involves being in an XCode environment -- not something I want to do for my C programs.我读过的关于 XCode 的泄漏/工具的大部分内容都涉及在 XCode 环境中——这不是我想为我的 C 程序做的事情。

Is there a way I can just run leaks on a compiled C program from the command line?有没有办法可以从命令行在编译的 C 程序上运行泄漏? If not, are there any other reliable alternatives I can use while waiting for an updated version of valgrind, or do I have to set up a VM with a Linux distro?如果没有,在等待 valgrind 的更新版本时,我是否可以使用其他可靠的替代方案,或者我是否必须使用 Linux 发行版设置 VM?

Use the iprofiler tool ( manpage ) by adding this to the start of your command line:通过将以下内容添加到命令行的开头来使用iprofiler工具(手册):

iprofiler -leaks -d $HOME/tmp

(where $HOME/tmp is where you want the results written). (其中$HOME/tmp是您希望写入结果的位置)。

You can then open up the resulting .dtps bundle using Instruments to check for leaks (or any of the other 4 checks that iprofiler performs).然后,您可以使用Instruments打开生成的.dtps包以检查泄漏(或iprofiler执行的其他 4 个检查中的任何一个)。

If you are using clang then compile with both -O3 and -g (as clang doesn't support -pg ).如果您使用clang,则同时使用-O3-g进行编译(因为clang不支持-pg )。

This seems to work (macOS Catlina 10.15.6):这似乎有效(macOS Catlina 10.15.6):

cd /usr/local/lib
ln -s $(xcode-select -p)/usr/lib/libLeaksAtExit.dylib
leaks --atExit -- ./a.out

Best to remove the symlink when done.完成后最好删除符号链接。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM