参考:
- https://www.cnblogs.com/yucloud/p/armbuild_valgrind3.html
- https://blog.csdn.net/Reasonss/article/details/111218224
源码下载地址
valgrind3.23.0 https://valgrind.org/downloads/current.html
安装依赖
sudo apt-get install libc6-dbg
sudo apt-get install automake
编译
#!/bin/sh
echo "设置环境变量"
export SRCROOT=${PWD}/..
export CC_PATH=${SRCROOT}/cross_compiler/arm-fsl-linux-gnueabi
export CROSS_COMPILE=${CC_PATH}/bin/arm-none-linux-gnueabi-
export CC=${CROSS_COMPILE}gcc
export CXX=${CROSS_COMPILE}g++
export CPP=${CROSS_COMPILE}cpp
export LD=${CROSS_COMPILE}ld
export AR=${CROSS_COMPILE}ar
./autogen.sh
./configure --prefix=${SRCROOT}/target-valgrind --host=arm-linux-gnueabi CFLAGS="-fPIC" CXXFLAGS="-fPIC" --enable-only32bit --enable-inner --enable-lto --enable-tls
echo "开始编译"
make -j4
echo "开始编译安装"
make -j4 install
# 若需要精简 参考精简部分 再进行打包
tar -czvf ../target-valgrind.tar.gz ../target-valgrind Inst/
echo "build and tar successful at: ../target-valgrind.tar.gz"
精简
rm -r /usr/local/valgrind/shared
rm -r /usr/local/valgrind/include
精简/usr/local/valgrind/lib/valgrind目录,精简后如下.
32bit-core-valgrind-s1.xml 32bit-sse.xml arm-with-vfpv3.xml
32bit-core-valgrind-s2.xml arm-core-valgrind-s1.xml default.supp
32bit-core.xml arm-core-valgrind-s2.xml getoff-arm-linux
32bit-linux-valgrind-s1.xml arm-core.xml memcheck-arm-linux
32bit-linux-valgrind-s2.xml arm-vfpv3-valgrind-s1.xml vgpreload_core-arm-linux.so
32bit-linux.xml arm-vfpv3-valgrind-s2.xml vgpreload_memcheck-arm-linux.so
32bit-sse-valgrind-s1.xml arm-vfpv3.xml
32bit-sse-valgrind-s2.xml arm-with-vfpv3-valgrind.xml
上传至开发板
/opt/
运行脚本
run_valgrind3.sh
#!/bin/sh
# tar -zxvf target-valgrind.tar.gz
# ld 库上传至开发板 /opt
# chmod +x /opt/ld-*.so
export VALGRIND_LIB=/opt/target-valgrind/libexec/valgrind && /opt/target-valgrind/bin/valgrind --tool=memcheck --leak-check=full /opt/ld-2.11.1.so $@
运行示例
./run_valgrind3.sh your_exec your_args0 your_args1
附录
附上$@的含义
$* 所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。
$@ 所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。
错误解决
memcheck 报错
报错信息:valgrind: failed to start tool 'memcheck' for platform 'arm64-linux': No such file or directory
这个需要声明运行库的变量
export VALGRIND_LIB=/opt/target-valgrind/libexec/valgrind
cannot be set up 报错
这个问题是程序本身没有包含所有调试信息的原因。
要么程序完全加入调试信息(包括动静态库),要不程序编译的时候加gcc参数-g调试信息,并且也把带调试信息的libc放入板子。
在x86主机的arm交叉编译工具链路径搜索
find . -name "*ld*.so"
./arm-fsl-linux-gnueabi/multi-libs/armv5te/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv7-a/thumb/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv7-a/vfpv3/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv7-a/neon/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv7-a/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv6/lib/ld-2.11.1.so
./arm-fsl-linux-gnueabi/multi-libs/armv6/vfp/lib/ld-2.11.1.so
./imports/Qt/labs/folderlistmodel/libqmlfolderlistmodelplugin.so
./plugins/qmltooling/libqmldbg_inspector.so
./plugins/qmltooling/libqmldbg_tcp.so
file ./arm-fsl-linux-gnueabi/multi-libs/lib/ld-*
./arm-fsl-linux-gnueabi/multi-libs/lib/ld-2.11.1.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, not stripped
./arm-fsl-linux-gnueabi/multi-libs/lib/ld-linux.so.3: symbolic link to ld-2.11.1.so
然后把它放到板子上即可
chmod +x ./opt/ld-2.11.1.so
标签:xml,ld,交叉,valgrind,Valgrind,编译,so,linux,arm
From: https://www.cnblogs.com/wang-lp/p/18262635