Apr 28, 2018 Valgrind is a programming tool for memory debugging, memory leak detection and profiling. Its installation for macOS High Sierra seems problematic and I wanted to write this post to tell the solution that worked for me. I use Homebrew to install it which is the recommended way and the solution also uses it. The Mojave 10.14.1 update does NOT install properly on unsupported machines, and could result in an unbootable OS. If you want to install the 10.14.1 update (and are not currently running 10.14.1), perform the following steps:. Download the latest version of Mojave Patcher. Download the installer using the Tools menu of Mojave Patcher. Under Valgrind a program will take something like 2-10 times longer than when run uninstrumented. Callgrind is a related program that uses the same x86 interpreter technology to instrument the code to log routine calls and generate a file that can be analyzed to show time. Valgrind is supported on ARM/Linux, but not on ARM for any other platform. It should be possible to make Valgrind work on ARM, but this would be a fairly substantial effort. For my part, I'm not actively working on macOS, and have been working more on FreeBSD. I am now the port maintainer on FreeBSD and also contribute to upstream Valgrind.
I tried to install Valgrind with brew install Valgrind and got :
I tried brew install –HEAD Valgrind.
Instead, after successfully installing the dependencies autoconf, automake and libtool, when it tries to install valgrind, I get a configure error:
My OS is macOS Mojave(10.14), so does it mean that I can’t install a functioning Valgrind with Homebrew presently?
A (rather painful) install from source workaround based on this patch, this post and this answer.
If you get the following error: No rule to make target '/usr/include/mach/mach_vm.defs’
, you will need to run xcode-select --install
. You might need to install Xcode from the app store if you don’t already have it. Once that’s done, you will need to edit the coregrind/Makefile
:
Search for:
After double checking the below folder exists, prefix every line with:
End result should be:
Now run make
again and the includes should be found. But that doesn’t necessarily mean it will compile. I got the following error:
A fix for this is to add the following line:
to the following files:
coregrind/m_syscall.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/vg_preloaded.c
Finally, you need to cross your fingers hoping no other errors show up:
You may use Experimental Version of Valgrind for macOS 10.14.5 Mojave at:
The command to use it is:
It is still experimental and needs some work but for simple projects works already… Enjoy!
addition: I found this one worked for me on my OSX 10.14
A branch that is working to get OSX correct. something to tide us over until we get a real valgrind version fixed.
I am having the same issue. It seems like valgrind is not compatible with the newest macOS(10.14 Mojave). Tried installing it the High Sierra way (https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/) and got the same output you described. The only solution I can offer you right now is either working on virtual machine (https://www.virtualbox.org/) or using Docker (https://www.gungorbudak.com/blog/2018/06/13/memory-leak-testing-with-valgrind-on-macos-using-docker-containers/).
I have just found a working solution to use VALGRIND on my Mac (Mojave 10.14.6). Just run this command :
(From https://github.com/LouisBrunner/valgrind-macos)
Hope it will work for you.
Not a proper solution for macOs, but for the time being, I created a docker image. After installing docker for macOS, this is how to start valgrind:
As of 2019-NOV-30, it is possible to build against OS X 10.14.6 via https://github.com/sowson/valgrind and https://github.com/LouisBrunner/valgrind-macos
However, there are many test failures (see the LouisBrunner link), noise during runs, and SEGVs when running against non-trivial programs: installing is, well, installing. YMMV.
You can follow alex.m’s answer to get valgrind, but if you’r using it on a int main() { return 0; }
program, you’ll get many weird errors, and non-existing allocs / free.
To ‘hide’ these annoying errors, you can follow theses steps (it’s more a workaround than a real fix) (based on this wiki page and some research in Valgrind’s source code):
int main() { return 0; }
program.valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$
.supp
valgrind file: cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp
minimal.supp
content at the end of $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp
fileAnd you are done! Weird and nonexistent errors will be ignored.
If you also want’s to remove the non-existing alloc
s, free
s etc, you can directly edit Valgrind’s source code. Or just use heapusage
for leak-tracking
(works on mojave 10.14.6)
As others have mentioned, Louis Brunner maintains a working version at https://github.com/LouisBrunner/valgrind-macos.
This worked for me for MacOS 10.15.7 Catalina.