参考valgrind-3.12.0下面的README.android
1.1 32位下的编译
cong@msi:/work/valgrind/valgrind-3.12.0$ cat build.sh
-
export NDKROOT=/work/bak/android/android-ndk-r10d/
-
export HWKIND=generic
-
export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
-
export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
-
export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
-
export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
-
export STRIP=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
-
export CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm -DANDROID_HARDWARE_$HWKIND -DVGPV_arm64_linux_android=1"
-
export CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm"
-
export LIBS="-L$NDKROOT/platforms/android-14/arch-arm/usr/lib"
- ./configure --host=armv7-unknown-linux --target=arm-linux-androideabi --prefix=/data/local/Inst --with-tmpdir=/sdcard
cong@msi:/work/valgrind/valgrind-3.12.0$ ./build.sh
-
Maximum build arch: arm
-
Primary build arch: arm
-
Secondary build arch:
-
Build OS: linux
-
Primary build target: ARM_LINUX
-
Secondary build target:
-
Platform variant: android
-
Primary -DVGPV string: -DVGPV_arm_linux_android=1
- Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp bionic.supp
-
cong@msi:/work/valgrind/valgrind-3.12.0$ cat build.sh
-
export NDKROOT=/work/bak/android/android-ndk-r10d/
-
export HWKIND=generic
-
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
-
export RANLIB=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ranlib
-
export STRIP=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip
-
export CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64 -DANDROID_HARDWARE_$HWKIND -DVGPV_arm64_linux_android=1"
-
export CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64"
-
export LIBS="-L$NDKROOT/platforms/android-14/arch-arm/usr/lib"
- ./configure --host=aarch64-unknown-linux --target=aarch64-linux-androideabi --prefix=/system/bin/Inst --with-tmpdir=/sdcard
-
Maximum build arch: arm64
-
Primary build arch: arm64
-
Secondary build arch:
-
Build OS: linux
-
Primary build target: ARM64_LINUX
-
Secondary build target:
-
Platform variant: android
-
Primary -DVGPV string: -DVGPV_arm64_linux_android=1
- Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp bionic.supp
2.1 编译
cong@msi:/work/valgrind/valgrind-3.12.0$ make -j8
cong@msi:/work/valgrind/valgrind-3.12.0$ make -j8 install DESTDIR=`pwd`/Inst
2.2 将valgrind的可执行文件导入手机
cong@msi:/work/valgrind/valgrind-3.12.0$ adb push Inst / -->文件比较多,打包再导入会更好一点
3. valgrind执行脚本并导入手机
3.1 valgrind 的执行脚本
-
cong@msi:/work/valgrind/valgrind-3.12.0$ cat val.sh -->编辑执行脚本
-
#!/system/bin/sh
-
VGPARAMS='--error-limit=no --kernel-variant=android-gpu-adreno510'
-
export TMDIR=/data/data/com.qileyx.ddz.vivo/
-
export VALGRIND_LIB=/system/bin/Inst/lib/valgrind/ -->如果出现memcheck找不到的提示,需要加这个
- exec /system/bin/Inst/bin/valgrind $VGPARAMS $*
cong@msi:/work/valgrind/valgrind-3.12.0$ adb push ./val.sh /system/bin/Inst/ -->push到/system/bin/Inst下
cong@msi:/work/valgrind/valgrind-3.12.0$ adb shell chmod 777 /system/bin/Inst/val.sh -->增加可执行权限
cong@msi:/work/valgrind/valgrind-3.12.0$ adb shell ls -l /system/bin/Inst/val.sh -->查看可执行权限
-rwxrwxrwx root root 138 2017-03-18 10:38 val.sh
4. 在手机上运行apk
export VALGRIND_LIB=/system/bin/Inst/lib/valgrind/
adb shell am force-stop com.example.hellojni -->关闭进程
adb shell setprop wrap.com.example.hellojni "logwrapper /system/bin/Inst/val.sh" -->加入wrapper
adb shell am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni -->启动进程
adb shell am force-stop com.example.hellojava
adb shell setprop wrap.com.example.hellojava "logwrapper /system/bin/Inst/val.sh"
adb shell am start -a android.intent.action.MAIN -n com.example.hellojava/.HelloJava
5. 问题
先在/system/bin/Inst/bin/valgrind 运行没有问题后再写脚本
5.1 运行时报错
I/val.sh (11189): valgrind: failed to start tool 'memcheck' for platform 'arm64-linux': No such file or directory
这需要export VALGRIND_LIB=/system/bin/Inst/lib/valgrind/
5.2 关于版本
cong@msi:/work/valgrind/valgrind-3.12.0$ file top -->这个top文件是从手机里面导出来的
top: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked (uses shared libs), stripped
cong@msi:/work/valgrind/valgrind-3.12.0$ file Inst/data/local/Inst/bin//valgrind
Inst/data/local/Inst/bin//valgrind: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
重新用64位的ndk编译之后的file结果:
cong@msi:/work/valgrind/valgrind-3.12.0$ file Inst/data/local/Inst/bin//valgrind
Inst/data/local/Inst/bin//valgrind: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
6. 最后有一个问题 valgrind 检查native的程序时正常,但是检查apk的程序时失败
Error reading pid form wrapped process, child may have died. --->没有解决这个问题, 如果有大牛知道了,麻烦告诉我一下,谢谢.