交叉编译valgrind

valgrind编译注意事项:

1. --prefix的路径必须和手机上实际运行的目录是一致的,不然运行valgrind会报错:

failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory"

2. 用ndk-r11c,valgrind版本3.12,编译出来在android6.0上跑,结果总是显示有泄露,运行不正确。

 

todo:

1. 需要查看具体内存泄露的代码行号,需要在编译时带上-g选项,同时执行的程序必须是带调试符号的版本。

2. /data/local/Inst/bin/valgrind -v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=memcheck --leak-check=full --show-reachable=yes /data/local/tmp/test_demo

 

交叉编译步骤:

1. 编写valgrind交叉编译脚本build.sh,并执行,然后生成makefile:

export NDKROOT=/Users/xxx/Library/Android/android-ndk-r11c
export ABI_DIR=arm-linux-androideabi-4.9
export ARCH=arm-linux-androideabi
export HWKIND=generic
#export VALGRIND_LIB=/data/local/valgrind/lib/valgrind/
# Set up toolchain paths.
#
# For ARM

export AR=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-ar
export LD=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-ld
export CC=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-gcc
export CXX=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-g++

export RANLIB=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-ranlib
export STRIP=$NDKROOT/toolchains/$ABI_DIR/prebuilt/darwin-x86_64/bin/$ARCH-strip


#export AR=$NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin/armeabi-v7a/
#export LD=$NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-link
#export CC=$NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
#export CXX=$NDKROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++

#export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ranlib
#export STRIP=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip
#

# for ARM
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm" \
   ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard
# note: on android emulator, android-14 platform was also tested and works.
# It is not clear what this platform nr really is.
#CPPFLAGS="--sysroot=$NDKROOT/platforms/android-23/arch-arm64" \
   #CFLAGS="--sysroot=$NDKROOT/platforms/android-23/arch-arm64" \
   #./configure --prefix=/data/local/Inst \
   #--host=aarch64-unknown-linux --target=aarch64-unknown-linux \
   #--with-tmpdir=/sdcard

2. make

你可能感兴趣的:(交叉编译valgrind)