交叉编译Valgrind
1.Valgrind
1.1 下载valgrind
官网 http://valgrind.org/downloads/ 下载源码包
tar xvf valgrind-3.15.0.tar.bz2
cd valgrind-3.15.0
apt-get install automake
./autogen.sh
1.2 修改configure文件
armv7*) 改成 armv7*|arm)
1.3 编译
sudo ./configure --host=arm-linux-gnueabihf --prefix=/usr/local/valgrind CC=arm-linux-gnueabihf-gcc CPP=arm-linux-gnueabihf-cpp CXX=arm-linux-gnueabihf-g++
make -j14 //根据自己的CPU核心数来选,不然编译有点久
make install
–prefix=/usr/local/valgrind指定的目录要与开发板上放置的目录一致,不然运行valgrind时可能会出现“valgrind: failed to start tool ‘memcheck’ for platform ‘arm-linux’: No such file or directory”错误。
1.4 裁剪
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
1.5 拷贝valgrind到开发板
直接把/usr/local/valgrind拷贝到网关
把工具添加到/etc/profile
#valgrind
export PATH=/usr/local/valgrind/bin:$PATH
1.6 报错说 ld-linux.so.3 不是debug版本
valgrind ls -l
==1298== Memcheck, a memory error detector
==1298== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==1298== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==1298== Command: ls -l
==1298==
valgrind: Fatal error at startup: a function redirection
valgrind: which is mandatory for this platform-tool combination
valgrind: cannot be set up. Details of the redirection are:
valgrind:
valgrind: A must-be-redirected function
valgrind: whose name matches the pattern: memcpy
valgrind: in an object with soname matching: ld-linux.so.3
valgrind: was not found whilst processing
valgrind: symbols from the object with soname: ld-linux.so.3
valgrind:
正常能被debug的库长这样子,valgrind就是靠监听系统malloc的库的debug信息分析内存泄露的,所以一定要debug版本
网上找了一大圈,都是
- 查看网关glibc版本
- 下载对应版本 glibc-2.19.tar.bz2
- 编译configure
- 安装
- 替换 ld-2.19.so \ libc-2.19.so 这两个文件
我编译了,替换以后虽然当时可以用,但重启后文件系统崩了!!!
Freeing init memory: 312K
/sbin/init: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
[] (unwind_backtrace+0x0/0x138) from [] (dump_stack+0x20/0x24)
[] (dump_stack+0x20/0x24) from [] (panic+0x78/0x194)
[] (panic+0x78/0x194) from [] (complete_and_exit+0x0/0x2c)
[] (complete_and_exit+0x0/0x2c) from [] (do_group_exit+0x5c/0xb4)
[] (do_group_exit+0x5c/0xb4) from [] (__wake_up_parent+0x0/0x30)
[] (__wake_up_parent+0x0/0x30) from [] (ret_fast_syscall+0x0/0x30)
最后想了一下,文件系统的库,不就是从交叉编译工具里面来的嘛,
最后从交叉编译工具里面找到了两个库,换进去完事了
cp ~/mint/am3352-arm-linux-gcc/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/
参考https://blog.csdn.net/qq_34743935/article/details/105682653
参考https://www.valgrind.org/downloads/