Using OSX Leaks for C Programs on the Command Line

2020-03-04 07:14发布

问题:

Can anyone give me any simple syntax for running OSX's leaks tool for detecting memory leaks in a compiled C program? I'm on 10.8, so I'm running into serious compatibility issues with valgrind.

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.

Is there a way I can just run leaks on a compiled C program from the command line? 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?

回答1:

Use the iprofiler tool (manpage) by adding this to the start of your command line:

iprofiler -leaks -d $HOME/tmp

(where $HOME/tmp is where you want the results written).

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).

If you are using clang then compile with both -O3 and -g (as clang doesn't support -pg).



标签: c xcode macos