Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2159574
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: Android平台

2017-03-21 09:35:43

1. 编译方法 
参考valgrind-3.12.0下面的README.android
1.1 32位下的编译
cong@msi:/work/valgrind/valgrind-3.12.0$ cat build.sh
  1. export NDKROOT=/work/bak/android/android-ndk-r10d/
  2. export HWKIND=generic
  3. export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
  4. export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
  5. export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
  6. export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
  7. export STRIP=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
  8. export CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm -DANDROID_HARDWARE_$HWKIND -DVGPV_arm64_linux_android=1"
  9. export CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm"
  10. export LIBS="-L$NDKROOT/platforms/android-14/arch-arm/usr/lib"
  11. ./configure --host=armv7-unknown-linux --target=arm-linux-androideabi --prefix=/data/local/Inst --with-tmpdir=/sdcard
1.2 执行脚本build.sh
cong@msi:/work/valgrind/valgrind-3.12.0$ ./build.sh
  1. Maximum build arch: arm
  2.          Primary build arch: arm
  3.        Secondary build arch:
  4.                    Build OS: linux
  5.        Primary build target: ARM_LINUX
  6.      Secondary build target:
  7.            Platform variant: android
  8.       Primary -DVGPV string: -DVGPV_arm_linux_android=1
  9.          Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp bionic.supp
1.3 64位下的编译
  1. cong@msi:/work/valgrind/valgrind-3.12.0$ cat build.sh
  2. export NDKROOT=/work/bak/android/android-ndk-r10d/
  3. export HWKIND=generic
  4. export AR=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
  5. export LD=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
  6. export CC=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc
  7. export RANLIB=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ranlib
  8. export STRIP=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip
  9. export CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64 -DANDROID_HARDWARE_$HWKIND -DVGPV_arm64_linux_android=1"
  10. export CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64"
  11. export LIBS="-L$NDKROOT/platforms/android-14/arch-arm/usr/lib"
  12. ./configure --host=aarch64-unknown-linux --target=aarch64-linux-androideabi --prefix=/system/bin/Inst --with-tmpdir=/sdcard
1.4 执行脚本build.sh
  1. Maximum build arch: arm64
  2.          Primary build arch: arm64
  3.        Secondary build arch:
  4.                    Build OS: linux
  5.        Primary build target: ARM64_LINUX
  6.      Secondary build target:
  7.            Platform variant: android
  8.       Primary -DVGPV string: -DVGPV_arm64_linux_android=1
  9.          Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp bionic.supp
2. 编译及安装
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 的执行脚本
  1. cong@msi:/work/valgrind/valgrind-3.12.0$ cat val.sh -->编辑执行脚本
  2. #!/system/bin/sh
  3. VGPARAMS='--error-limit=no --kernel-variant=android-gpu-adreno510'
  4. export TMDIR=/data/data/com.qileyx.ddz.vivo/
  5. export VALGRIND_LIB=/system/bin/Inst/lib/valgrind/      -->如果出现memcheck找不到的提示,需要加这个
  6. exec /system/bin/Inst/bin/valgrind $VGPARAMS $*
3.2 脚本的导入
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. --->没有解决这个问题, 如果有大牛知道了,麻烦告诉我一下,谢谢.



阅读(4584) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~