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.
To build Valgrind:
mmma -j6 external/valgrind
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
com.google.example_app.
To run the system server with Valgrind:
adb shell setprop wrap.system_server "logwrapper valgrind"
adb shell stop && adb shell start
For debug symbols, push unstripped libraries to /data/local/symbols
:
adb shell mkdir /data/local/symbols
adb push $OUT/symbols /data/local/symbols
To use Valgrind during boot up, edit
out/target/product/XXXX/root/init.rc
by changing
service example /system/bin/foo --arg1 --arg2
to:
>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.