Using Valgrind

The Valgrind tool suite includes Memcheck (for detecting memory-related errors in C and C++), Cachegrind (a cache profiler), Massif (a heap profiler), and several other tools.

Note: While you can use Valgrind for Android debugging, most Android platform developers use AddressSanitizer instead.

Building Valgrind

To build Valgrind:

mmma -j6 external/valgrind

Using on an application

To use Valgrind on an application:

adb shell setprop wrap.app_name "logwrapper valgrind"
adb shell am start -a android.intent.action.MAIN -n app_name/.MainActivity
app_name must be a fully-qualified name such as

Using on the system server

To run the system server with Valgrind:

adb shell setprop wrap.system_server "logwrapper valgrind"
adb shell stop && adb shell start

Getting debug symbols

For debug symbols, push unstripped libraries to /data/local/symbols:

adb shell mkdir /data/local/symbols
adb push $OUT/symbols /data/local/symbols

Using during boot up

To use Valgrind during boot up, edit out/target/product/XXXX/root/init.rc by changing

service example /system/bin/foo --arg1 --arg2


>service example /system/bin/logwrapper /system/bin/valgrind /system/bin/foo --arg1 --arg2

To see the effects, create a boot.img and reflash the device.