You need to create a script, let's call it start_valgrind.sh
#!/system/bin/sh PACKAGE="com.example.hellojni" # Callgrind tool #VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=callgrind --callgrind-out-file=/sdcard/callgrind.out.%p' # Memcheck tool VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=memcheck --leak-check=full --show-reachable=yes' export TMPDIR=/data/data/$PACKAGE exec /data/local/Inst/bin/valgrind $VGPARAMS $*
which must be copied to the device.
Once you have a script in the start_valgrind.sh file somewhere in the local file system, you can simply use the script below (lets call it bootstrap_valgrind.sh ) to do all the work (copy the start_valgrind.sh script to the phone, start it , launches your application through Valgrind).
#!/usr/bin/env bash PACKAGE="com.example.hellojni" adb push start_valgrind.sh /data/local/ adb shell chmod 777 /data/local/start_valgrind.sh adb root adb shell setprop wrap.$PACKAGE "logwrapper /data/local/start_valgrind.sh" echo "wrap.$PACKAGE: $(adb shell getprop wrap.$PACKAGE)" adb shell am force-stop $PACKAGE adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni adb logcat -c adb logcat exit 0
WARNING. Make sure that the property name specified with setprop ie (wrap.com.yourcompany.yourapp) is less than 31 characters long.
Otherwise, you will receive the error "cannot set the property" because you CANNOT set the property name with a length greater than 31, which is the number of maximum allowed characters in the property name.
Also, the value of the property must be <= 91 characters: https://stackoverflow.com/a/166778/
To create Valgrind for Android (ARM), see my script from here: https://stackoverflow.com/a/464829/
bitek Oct 07 '13 at 9:51 on 2013-10-07 21:51
source share