I have been tested a lot of times to install Valgrind on MacOs and I always got problem. Finally I installed Valgrind without any problem.
It is very easy to install and I want to share with you. Because, Valgrind is wonderful application for detecting memory leak and profiling codes. In my opinion, every C++ developer should have Valgrind on their PC, if there using unix based OS.
- root rights (just kidding)
git clone git://sourceware.org/git/valgrind.git
If you get exception something like that:
make: Nothing to be done for `all-am'.
Making all in coregrind
make: *** No rule to make target `/usr/include/mach/mach_vm.defs', needed by `m_mach/mach_vmUser.c'. Stop.
make: *** [all-recursive] Error 1
make: *** [all] Error 2
it means you are not using latest version of XCode and you need to do execute following shell command.
and then execute make command again. That is all.
Let’s do some small examples.
First we can profile codes line by line.
Create new C/C++ application for testing. I did it as symspelltest application.
valgrind --tool=callgrind --simulate-cache=yes ./symspelltest
Valgrind generate log file when execution finished.
I assume, you are already installed homebrew.
brew install qcachegrind --with-graphviz
Now, check call stacks.