Note to self post for when the next time I need it, or: how to build and run your application under valgrind on Android (tested on 4.4).
Preqres: Patience, Android NDK, rooted device, linux host (VM, or whatever).
Make sure you are running `dalvik` as your runtime. `art` might be new and flashy, but it does not play well with valgrind in my experience.
Get valgrind sources from valgrind.org or do
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
Unpack it if you downloaded the source tarball, obviously.
in the svn checkout (skip it if you downloaded the tarball)
or where ever you have your Android NDK setup.
Configuring and building, replace `arm-linux-androideabi-4.6` with your toolchain and `linux-x86` with your platform.
export HWKIND=generic export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi export AR=$TOOLCHAIN-ar export LD=$TOOLCHAIN-ld export CC=$TOOLCHAIN-gcc CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \ CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/android-14/arch-arm" \ ./configure --prefix=/data/local/Inst \ --host=armv7-unknown-linux --target=armv7-unknown-linux \ --with-tmpdir=/sdcard make make -j4 install DESTDIR=`pwd`/Inst
Installing on your device:
If you have an engineering build or install adbd insecure, just do:
adb root adb remount
and then jump to the next step!
Otherwise, just remount /system read-write:
adb shell mount | grep system #/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,relatime,data=ordered 0 0 su mount -o rw,remount /dev/block/platform/msm_sdcc.1/by-name/system /system
Putting it on your device
adb shell "mkdir /data/local/Inst" ## could be optimised... probably adb push Inst / adb shell "chmod 777 /data/local/Inst" adb shell "/data/local/Inst/bin/valgrind --version"
If you built your own Android image to get symbols for everything, put them in place as well:
adb shell mkdir -p /sdcard/symbols/system adb push ~/android_src/out/target/product/mako/symbols/system /sdcard/symbols/system/
Get these two shell scripts and optionally the suppression file for valgrind. Make sure your apps package name is less than 26 chars long, because setprop fails to set properties longer than 31 chars (26 + ‘wrap.’).
chmod +x run_valgrind.sh ./run_valgrind.sh
Done! Now just watch
adb logcat and marvel at the wonders of valgrind. :)