valgrind在android 10上检查内存泄露

代码下载

git clone git://sourceware.org/git/valgrind.git

[github上的不行,缺少VEX目录]

编译

创建变异脚本build.sh:
    #!/usr/bin/env bash

    export NDKROOT=/home/hui/tools/android-ndk/android-ndk-r14b
    export AR=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
    export LD=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
    export CC=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc

    bash ./autogen.sh

    CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64" \
       CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64" \
       ./configure --prefix=/data/local/Inst \
       --host=aarch64-unknown-linux --target=aarch64-unknown-linux \
       --with-tmpdir=/sdcard

    make -j4
    make -j4 install DESTDIR=`pwd`/Inst
生成的目录push到手机上:
$ cd Inst/data/local
$ adb push Inst/ /data/local/

创建valgrind.sh文件:

run valgrind sh:

    #!/system/bin/sh

    PACKAGE="com.android.camera"

    # 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 sleep 200 $VGPARAMS $
push start_valgrind.sh到手机上:
$ adb push start_valgrind.sh /data/local/Inst/
$ adb shell chmod 777 /data/local/start_valgrind.sh
in adb shell:
$ setprop wrap.com.android.camera "logwrapper /data/local/start_valgrind.sh"
$ am start -a android.intent.action.MAIN -n com.android.camera/.Camera

检查设置成功:
adb shell getprop wrap.com.android.camera
logwrapper /data/local/Inst/start_valgrind.sh

可以运行,但是会崩溃,可能和android的版本有关,老版本android都是支持了valgrind的。

你可能感兴趣的:(valgrind在android 10上检查内存泄露)