breakthatbass
breakthatbass

Reputation: 376

MacOS Valgrind alternative?

I'm running MacOS Big Sur and trying to install valgrind for an assignment.

brew install valgrind doesn't currently work and installing from the tar.bz2 distribution doesn't either.

Running ./configure (according to the readme instructions) returns this at the end:

checking for a supported OS... ok (darwin20.1.0)
checking for the kernel version... unsupported (20.1.0)
configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)

Judging from that, looks like valgrind hasn't worked for the last couple of MacOS releases.

Is there an alternative for current MacOS releases or is this a good time for me to make a partition on my hard drive for Linux? Or am I missing something with installation?

Upvotes: 13

Views: 19971

Answers (3)

BernhardWebstudio
BernhardWebstudio

Reputation: 1135

Another possibility would be to use the leaks utility, which is shipped with XCode.

Example useage: leaks --atExit -- {yourProgramWithArgs}

To learn more, use man leaks or leaks --help.

Upvotes: 4

Eric Xu
Eric Xu

Reputation: 335

For anyone else looking for an answer, you could use valgrind-macos, a fork of Valgrind on macOS, as recommended by PhillipMills. XCode also provides tools for leak checking.

However, if you don’t use XCode and don’t like the first option, you could try Address/Leak Sanitizer. The difference is that you’ll have to compile and link with one of the sanitizers, but that only requires an extra flag, i.e., -fsanitize=address. Note that Apple Clang doesn’t support leak checking, so you’ll have to grab llvm off Brew. Also, you need to prepend ASAN_OPTIONS=detect_leaks=1 before your executable.

Upvotes: 3

Paul Floyd
Paul Floyd

Reputation: 6906

As mentioned in the comments, Louis Brunner's github repo is your best bet at the moment. This should give you at least a minimally functional build.

Other than the usual version number changes, one of the big, breaking, changes in Big Sur is the fact that the system libraries are cached (and hidden) by dyld. So right now Valgrind is not able to read libsystem_malloc.dylib in order to determine the address of functions like malloc so that they can be redirected.

If anyone wants to take a stab at it, then my guess is that you will need to follow these instructions, and change initimg-darwin.c so that dyld_cache_value is "avoid".

Upvotes: 7

Related Questions