Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
来源:互联网 发布:电脑编程语言有哪些 编辑:程序博客网 时间:2024/05/20 06:55
原创: http://blog.csdn.net/share_happy_1984/article/details/10141229
编译环境:Ubuntu x86_64(Linux root 2.6.32-45-generic #101-Ubuntu SMP Mon Dec 3 15:39:38 UTC 2012 x86_64 GNU/Linux)
运行环境:Android 4.0.4 (Linux kernel 3.0.21 OMAP4460)
一、下载NDK9和valgrind 3.8.1。
二、按照valgrind 3.8.1中的README.android进行编译,步骤如下:
1. 指定NDK根目录
export NDKROOT=/path/to/android-ndk-r9
2. 指定通用的安卓设备
export HWKIND=generic
3. 指定交叉工具链路径
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
4. 到valgrind目录下配置valgrind
cd /path/to/valgrind
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND"
CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"
./configure --prefix=/data/local/valgrind --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard
CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"
./configure --prefix=/data/local/valgrind --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard
注:配置这步经常报错,前面的路径等设置需要细心啊。
5. 编译并安装到指定路径
make -j2
make -j2 install DESTDIR=`pwd`/Inst
make -j2 install DESTDIR=`pwd`/Inst
注:-j2表示利用双核提升编译速度,对速度不在乎的可以去掉。
三、安卓上运行
1. 拷贝Inst到安卓系统/data/local/valgrind中。
注:假如路径不是编译配置时的路径,这时需要重新设置一下,否则会报错。“valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory”
export VALGRIND_LIB=/data/local/valgrind/lib/valgrind/
2. 安卓4.0.4下(OMAP4460)执行Memcheck效果
127|shell@android:/data/local # /data/local/valgrind/bin/valgrind ls
==3509== Memcheck, a memory error detector
==3509== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==3509== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==3509== Command: ls
==3509==
--3509-- WARNING: Serious error when reading debug info
--3509-- When reading debug info from /data/local/valgrind/lib/valgrind/vgpreload_core-arm-linux.so:
--3509-- Can't make sense of .data section mapping
test
tmp
==3509==
==3509== HEAP SUMMARY:
==3509== in use at exit: 4,096 bytes in 1 blocks
==3509== total heap usage: 5 allocs, 4 frees, 8,337 bytes allocated
==3509==
==3509== LEAK SUMMARY:
==3509== definitely lost: 0 bytes in 0 blocks
==3509== indirectly lost: 0 bytes in 0 blocks
==3509== possibly lost: 0 bytes in 0 blocks
==3509== still reachable: 4,096 bytes in 1 blocks
==3509== suppressed: 0 bytes in 0 blocks
==3509== Rerun with --leak-check=full to see details of leaked memory
==3509==
==3509== For counts of detected and suppressed errors, rerun with: -v
==3509== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
shell@android:/data/local #
==3509== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==3509== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==3509== Command: ls
==3509==
--3509-- WARNING: Serious error when reading debug info
--3509-- When reading debug info from /data/local/valgrind/lib/valgrind/vgpreload_core-arm-linux.so:
--3509-- Can't make sense of .data section mapping
test
tmp
==3509==
==3509== HEAP SUMMARY:
==3509== in use at exit: 4,096 bytes in 1 blocks
==3509== total heap usage: 5 allocs, 4 frees, 8,337 bytes allocated
==3509==
==3509== LEAK SUMMARY:
==3509== definitely lost: 0 bytes in 0 blocks
==3509== indirectly lost: 0 bytes in 0 blocks
==3509== possibly lost: 0 bytes in 0 blocks
==3509== still reachable: 4,096 bytes in 1 blocks
==3509== suppressed: 0 bytes in 0 blocks
==3509== Rerun with --leak-check=full to see details of leaked memory
==3509==
==3509== For counts of detected and suppressed errors, rerun with: -v
==3509== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
shell@android:/data/local #
3. 安卓4.0.4下(OMAP4460)执行callgrind步骤
/data/local/valgrind/bin/valgrind --tool=callgrind ./test
执行完成后在目录下生成"callgrind.out.XXX"(XXX是进程ID号)是分析文件,可以直接利用:/data/local/valgrind/bin/callgrind_annotate callgrind.out.XXX 打印结果;
也可以在Ubuntu上使用:gprof2dot.py -f callgrind callgrind.out.XXX |dot -Tpng -o report.png 来生成图形化结果(需下载gprof2dot.py脚本,详见参考资料3)。
注:
1、使用callgrind时,./test程序运行时间短(<2s),运算量小的可以正常执行callgrind;而当test程序运行时间较长(>6S),运算量较大时,会导致安卓系统不稳定,无法正确执行下去,估计valgrind对安卓的兼容性较差吧。
参考资料:
1. http://blog.csdn.net/21cnbao/article/details/7399863 宋宝华 使用valgrind检测Android native程序的内存
2. http://blog.csdn.net/gxh9314/article/details/8447559 mips 交叉编译valgrind
3. http://blog.csdn.net/yanghao23/article/details/7514587 linux下利用valgrind工具进行内存泄露检测和性能分析
转自:
http://stackoverflow.com/questions/16450650/android-valgrind-build-fails
的编译valgrind的脚本
#!/usr/bin/env bashVALGRIND_VERSION="3.8.1"VALGRIND_EXTENSION=".tar.bz2"VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"wget -v -nc "http://valgrind.org/downloads/${VALGRIND_TARBALL}"## Extract files from any archive# Usage: extract <archive_name># # As an alternative install unp https://aur.archlinux.org/packages/unp/# (A perl script for unpacking a wide variety of archive formats)#function extract(){ if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via >extract<" ;; esac else echo "'$1' is not a valid file" fi}if [[ ! -d $VALGRIND_DIRECTORY ]]; then extract $VALGRIND_TARBALLficd $VALGRIND_DIRECTORYif [[ ! -z "$ANDROID_NDK_HOME" ]]; then export ANDROID_NDK_HOME='$HOME/Software/Android/android-ndk-r9' export PATH=$PATH:$ANDROID_NDK_HOMEfiif [[ ! -z "$ANDROID_SDK_HOME" ]]; then export ANDROID_SDK_HOME='$HOME/Software/Android/adt-bundle-linux-x86_64-20130917/sdk' export PATH=$PATH:$ANDROID_SDK_HOME/platforms-tools:$ANDROID_SDK_HOME/toolsfiexport NDK=$ANDROID_NDK_HOMEexport NDKROOT=$ANDROID_NDK_HOMEexport HWKIND=nexus_sexport AR=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-arexport LD=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ldexport CC=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gccmake cleanCPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-arm -DANDROID_HARDWARE_$HWKIND" \ CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-arm" \ ./configure --prefix=/data/local/Inst \ --host=armv7-unknown-linux \ --target=armv7-unknown-linux \ --with-tmpdir=/sdcard make -j4make -j4 install DESTDIR=`pwd`/Instadb rootadb remountadb shell "mkdir /data/local/Inst"adb push Inst /adb shell "ls -l /data/local/Inst"adb shell "/data/local/Inst/bin/valgrind --version"adb shell "export PATH=$PATH:/data/local/Inst/bin/"exit 0
export NDK_HOME=$HOME/Downloads/android-ndk-r8eexport HWKIND=genericexport TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabiexport AR=$TOOLCHAIN-arexport LD=$TOOLCHAIN-ldexport CC=$TOOLCHAIN-gccCPPFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \ CFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm" \ ./configure --prefix=/data/local/Inst \ --host=armv7-unknown-linux --target=armv7-unknown-linux \ --with-tmpdir=/sdcardmake
The problem I had was that the configure script was ignoring the environment variables. To configure the make file I instead did this:
sudo ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard0 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" CC=$CC LD=$LD AR=$AR
This ensures the variables are set properly and works with Linux Mint 13. It does not work on OSX Mountain Lion however. I'd advise anyone using OSX without access to a linux installation to try using linux on a virtual machine.
0 0
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
- Ubuntu上交叉编译valgrind for Android 4.4的过程与注意事项
- macosx 交叉编译 valgrind For Android
- ubuntu 交叉编译过程
- valgrind安装与使用 交叉编译
- valgrind for android 编译安装
- Ubuntu上编译Android过程
- Ubuntu上编译Android过程
- 在 x86 上面交叉编译 gstreamer for arm(zz)与MIPS平台上的编译(原)
- 应用 Valgrind 发现 Linux 程序的内存问题及交叉编译for arm
- mips 交叉编译valgrind
- arm交叉编译Valgrind
- valgrind 3.9交叉编译
- ARM 交叉编译 Valgrind
- 交叉编译valgrind
- path copy host
- Linux下同步模式、异步模式、阻塞调用、非阻塞调用总结 .
- C/C++学习应读的书
- Windows Server 2012下安装.NET Framework 3.5
- 滴水石穿,奇迹是一点点实现的
- Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项
- 第三代移动通信技术
- CSliderCtrl逆向调整&CTooltips响应--向左累加或向上累加
- Android开发环境搭建流程
- struts2复习
- SP考试复习题——短信技术多选题
- bind出现Address already in use解决方法
- RMAN备份的概念
- OpengGL GLSL Computational Invariance