您的位置:首页 > 移动开发 > Android开发

how to cross compile valgrind on android platform

2017-02-08 17:33 435 查看
The article is mainly introduce how to crossing compile valgrind and using valgrind to check memory leak for app file and executable file

References:

http://www.itdadao.com/articles/c15a376180p0.html

http://blog.csdn.net/roland_sun/article/details/46049485

https://gist.github.com/mnemonicflow/131eb830a4d74911bf5a

https://sergiolima.wordpress.com/2015/07/07/vallgrind-and-android-working-together/

https://wiki.linaro.org/Platform/Android/UseValgrindOnAndroid

1: valgrind tool introduce

http://valgrind.org, and we can get lots of valgrind infomation from the website

2: set env val according to your arm-linux-gcc

Before compile valgrind file, we can reference the README.android, which is mainly introduce how to compile valgrind step by step.

2.1: download valgrind

valgrind-3.12.0.tar.bz

2.2: download android ndk

2.3: set val

export NDKROOT=/home/huixue.gong/tools/arm-linux/android-ndk-r6
export  HWKIND=generic

export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar

export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld

export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc


The following cmd must be execute in one line, and there is no “/n”, or there will be make error.

CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-arm" CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-arm" ./configure --prefix=/data/local/valgrind --host=armv7-unknown-linux --target=armv7-unknown-linux  --with-tmpdir=/sdcard


make -j4
make -j4 install DESTDIR='pwd'/valgrind


2.4: copy the output folder valgrind to your platform.

cp valgrind /data/local/

3: using valgrind to check memory-leak check

before check memory-leak, you can use the following start_vgl.sh, and set export VALGRIND_LIB=/data/local/valgrind/lib/valgrind.

if [ "$APP" ]; then
echo "check $APP memory leak"
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/$APP
exec /data/local/valgrind/bin/valgrind $VGPARAMS $*

#       am force-stop app
#       setprop wrap.app "logwrapper /data/logcal/valgrind/start_vgl.sh"
else
echo "APP is null, check BIN file"

# check bin memory leak
if [ "$BIN" ]; then
echo "check $BIN memory leak"
BIN_CHECK='--tool=memcheck --leak-check=yes --show-reachable=yes'
exec /data/local/valgrind/bin/valgrind $BIN_CHECK $BIN /data/local/valgrind/bin_leak.txt 2>&1
echo "store the output file to app_leak.txt"
else
echo "BIN is null, please input bin file"
fi
fi


for check app, export $APP=”org.droidtv.helloworld”

for check exe, exprot $BIN=”helloworld”

And then run the start_vgl.sh

3.1: check app memory leak

stop your checking app: am force-stop app

setprop wrap.app “logwrapper /data/logcal/valgrind/start_vgl.sh”

kill the app process pid, and then it will generate memory-leak info to /sdcard/valgrind.log.%p.

if [ "$APP" ]; then
echo "check $APP memory leak"
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/$APP
exec /data/local/valgrind/bin/valgrind $VGPARAMS $*
else
echo "APP is null, check BIN file"
fi


3.2: check executable file

if [ "$BIN" ]; then
echo "check $BIN memory leak"
BIN_CHECK='--tool=memcheck --leak-check=yes --show-reachable=yes'
exec /data/local/valgrind/bin/valgrind $BIN_CHECK $BIN /data/local/valgrind/bin_leak.txt 2>&1
echo "store the output file to app_leak.txt"
else
echo "BIN is null, please input bin file"
fi


maybe you can download the valgrind tool for checking memory-leak, but i am not sure it can run on your platform.

https://code.csdn.net/gonghuixue/philips_tv_apps/tree/master/valgrind.tar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: