how to cross compile valgrind on android platform

本文介绍如何进行Valgrind的交叉编译,并利用Valgrind检查应用程序文件和可执行文件中的内存泄漏问题。文中详细描述了设置环境变量、编译Valgrind的步骤以及使用Valgrind进行内存泄漏检测的方法。

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.youkuaiyun.com/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.youkuaiyun.com/gonghuixue/philips_tv_apps/tree/master/valgrind.tar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值