views:

2301

answers:

7

How can I compile Valgrind on Snow Leopard?

A: 

You can't. It isn't supported yet.

bmargulies
I read some people are compiling it using some patch.
rsanchez
Some additional info. I read some people are compiling it using a patch available here: https://bugs.kde.org/show_bug.cgi?id=205241.What I am requesting is the step-by-step process of applying the patch and compiling it.
rsanchez
+15  A: 

Assuming you've got XCode tools installed and an SVN client, here it goes.

Go to some directory you keep stuff in. Checkout valgrind sources

svn co svn://svn.valgrind.org/valgrind/tags/VALGRIND_3_5_0 valgrind

Download Greg Parker's 10.6 patch

curl http://bugsfiles.kde.org/attachment.cgi?id=36999 > 10.6.patch
mv 10.6.patch ./valgrind

Apply the patch

cd valgrind
patch -p0 < 10.6.patch

Compile valgrind

./autogen.sh
./configure
make

Install it

sudo make install

Run it

valgrind --leak-check=full --show-reachable=yes /tmp/a.out
diciu
+3  A: 

In addition to the (almost) perfect answer of diciu. For compiling a 64 bit version of valgrind (required for 64 bit executables, aka. the standard in OS 10.6). You will need to edit the configure file and set host_cpu="x86_64".

FFox
+2  A: 

diciu's answer worked flawlessly for a 32 bit build, but I couldn't get a 64 bit build working by adapting those instructions.

Found some other working instructions for getting a 64bit build of valgrind though.

(replicated here, slightly adapted, since wget is not installed by default on os x)

svn co -r 11104 svn://svn.valgrind.org/valgrind/trunk valgrind
cd valgrind
curl http://bugsfiles.kde.org/attachment.cgi?id=40091 -o snow-leopard.patch
curl http://bugsfiles.kde.org/attachment.cgi?id=40900 -o arc4random.patch
curl http://bugsfiles.kde.org/attachment.cgi?id=42530 -o sidt.patch 
curl http://bugsfiles.kde.org/attachment.cgi?id=42892 -o signal.patch
patch -p0 < snow-leopard.patch
patch -p0 < arc4random.patch
patch -p1 < signal.patch
cd VEX; patch -p0 < ../sidt.patch ; cd ..
touch darwin10-drd.supp
touch darwin10.supp
./autogen.sh || autoreconf -fvi
./configure --prefix=`pwd`/inst64 --build=amd64-darwin
make -j 8 && make install

Edit: in response to the comments, to have both 32 and 64 bit also do the following commands: (note that I have no need for a 32bit valgrind, so I didn't try this, but it should work)

make clean
 ./configure --prefix=`pwd`/inst32
make -j 8 && make install

Both will be located in inst32/ and inst64/ afterwards.

Pieter
Does just the 64bit Valgrind build work for debugging 32bit binaries? Or you need to compile both versions? If so, could you modify your method so it compiles both versions and keeps both of them installed?
rsanchez
Switched the answer mark to this one, as it contains more up-to-date patches. Thank you!
rsanchez
+2  A: 

using the --enable-only64bit configure flag avoided having to hack host_cpu="x86_64" into the configure script (using the patch diciu posted)

JeffL
A: 

"diciu" solution worked for me.

+1  A: 

FYI, Valgrind 3.6 (released October 21, 2010) officially supports Snow Leopard out-of-the-box.

http://valgrind.org/docs/manual/dist.news.html

Paul Roub