#內存泄露# #valgrind#valgrind-3.15.0 編譯&&交叉編譯

環境準備

valgrind-3.15.0 官網下載地址:http://valgrind.org/
編譯環境:ubuntu16.04 x64
開發平臺:TDA2X

下載好valgrind-3.15.0.tar.bz2文件後進行解壓

tar xvf valgrind-3.15.0.tar.bz2

安裝automake 

apt-get install automake 

運行autogen.sh開始配置

valgrind-3.15.0
./autogen.sh

 

配置

修改配置文件configure,否則配置指定的交叉編譯工具可能以下錯誤會報

checking host system type... arm-unknown-linux-gnu checking for a supported CPU... no (arm) configure: error: Unsupported host architecture. Sorry
 找到armv7修改爲 armv7*|arm*

     armv7*)
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (${host_cpu})" >&5
$as_echo "ok (${host_cpu})" >&6; }
	ARCH_MAX="arm"
	;;
     armv7*|arm*)
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (${host_cpu})" >&5
$as_echo "ok (${host_cpu})" >&6; }
	ARCH_MAX="arm"
	;;

由於我們需要交叉編譯因此需要配置指定的編譯工具

 ./configure --host=arm-linux CC=arm-linux-gnueabihf-gcc CPP=arm-linux-gnueabihf-cpp CXX=arm-linux-gnueabihf-g++ --prefix=/opt/valgrind
  1. CC、CPP、g++指定爲交叉編譯的arm版本編譯器
  2. --prefix:指定valgrind編譯生成的可執行文件的保存路徑,注意該路徑必須和開發板上最好存放valgrind的路徑一致,否則可能會報"valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory"等類似錯誤。然而其實本質上的問題是執行valgrind時,沒有找到valgrind的lib庫!!!我們在lib下面可以看到還有一層目錄valgrind,這時候我們在開發板/etc/profile文件中添加一行
           
    export VALGRIND_LIB=/opt/valgrind-3.15.0/lib/valgrind
    以下爲lib/valgrind看的相關庫文件
cll@cll-linux:/opt/valgrind-3.15.0/lib/valgrind $ pwd
/opt/valgrind-3.15.0/lib/valgrind
cll@cll-linux:/opt/valgrind-3.15.0/lib/valgrind $ ls
32bit-core-valgrind-s1.xml                mips-cp0-valgrind-s1.xml
32bit-core-valgrind-s2.xml                mips-cp0-valgrind-s2.xml
32bit-core.xml                            mips-cp0.xml
32bit-linux-valgrind-s1.xml               mips-cpu-valgrind-s1.xml
32bit-linux-valgrind-s2.xml               mips-cpu-valgrind-s2.xml
32bit-linux.xml                           mips-cpu.xml
32bit-sse-valgrind-s1.xml                 mips-fpu-valgrind-s1.xml
32bit-sse-valgrind-s2.xml                 mips-fpu-valgrind-s2.xml
32bit-sse.xml                             mips-fpu.xml
64bit-avx-valgrind-s1.xml                 mips-linux-valgrind.xml
64bit-avx-valgrind-s2.xml                 mips-linux.xml
64bit-avx.xml                             none-arm-linux
64bit-core-valgrind-s1.xml                power64-core2-valgrind-s1.xml
64bit-core-valgrind-s2.xml                power64-core2-valgrind-s2.xml
64bit-core.xml                            power64-core-valgrind-s1.xml
64bit-linux-valgrind-s1.xml               power64-core-valgrind-s2.xml
64bit-linux-valgrind-s2.xml               power64-core.xml
64bit-linux.xml                           power64-linux-valgrind-s1.xml
64bit-sse-valgrind-s1.xml                 power64-linux-valgrind-s2.xml
64bit-sse-valgrind-s2.xml                 power64-linux.xml
64bit-sse.xml                             power-altivec-valgrind-s1.xml
amd64-avx-coresse-valgrind.xml            power-altivec-valgrind-s2.xml
amd64-avx-coresse.xml                     power-altivec.xml
amd64-avx-linux-valgrind.xml              power-core-valgrind-s1.xml
amd64-avx-linux.xml                       power-core-valgrind-s2.xml
amd64-coresse-valgrind.xml                power-core.xml
amd64-linux-valgrind.xml                  power-fpu-valgrind-s1.xml
arm-core-valgrind-s1.xml                  power-fpu-valgrind-s2.xml
arm-core-valgrind-s2.xml                  power-fpu.xml
arm-core.xml                              power-linux-valgrind-s1.xml
arm-vfpv3-valgrind-s1.xml                 power-linux-valgrind-s2.xml
arm-vfpv3-valgrind-s2.xml                 power-linux.xml
arm-vfpv3.xml                             powerpc-altivec32l-valgrind.xml
arm-with-vfpv3-valgrind.xml               powerpc-altivec32l.xml
arm-with-vfpv3.xml                        powerpc-altivec64l-valgrind.xml
cachegrind-arm-linux                      powerpc-altivec64l.xml
callgrind-arm-linux                       power-vsx-valgrind-s1.xml
default.supp                              power-vsx-valgrind-s2.xml
dhat-arm-linux                            power-vsx.xml
drd-arm-linux                             s390-acr-valgrind-s1.xml
exp-bbv-arm-linux                         s390-acr-valgrind-s2.xml
exp-sgcheck-arm-linux                     s390-acr.xml
getoff-arm-linux                          s390-fpr-valgrind-s1.xml
helgrind-arm-linux                        s390-fpr-valgrind-s2.xml
i386-coresse-valgrind.xml                 s390-fpr.xml
i386-linux-valgrind.xml                   s390-vx-valgrind-s1.xml
lackey-arm-linux                          s390-vx-valgrind-s2.xml
libcoregrind-arm-linux.a                  s390-vx.xml
libmpiwrap-arm-linux.so                   s390x-core64-valgrind-s1.xml
libreplacemalloc_toolpreload-arm-linux.a  s390x-core64-valgrind-s2.xml
libvex-arm-linux.a                        s390x-core64.xml
libvexmultiarch-arm-linux.a               s390x-generic-valgrind.xml
massif-arm-linux                          s390x-generic.xml
memcheck-arm-linux                        s390x-linux64-valgrind-s1.xml
mips64-cp0-valgrind-s1.xml                s390x-linux64-valgrind-s2.xml
mips64-cp0-valgrind-s2.xml                s390x-linux64.xml
mips64-cp0.xml                            s390x-vx-linux-valgrind.xml
mips64-cpu-valgrind-s1.xml                s390x-vx-linux.xml
mips64-cpu-valgrind-s2.xml                vgpreload_core-arm-linux.so
mips64-cpu.xml                            vgpreload_dhat-arm-linux.so
mips64-fpu-valgrind-s1.xml                vgpreload_drd-arm-linux.so
mips64-fpu-valgrind-s2.xml                vgpreload_exp-sgcheck-arm-linux.so
mips64-fpu.xml                            vgpreload_helgrind-arm-linux.so
mips64-linux-valgrind.xml                 vgpreload_massif-arm-linux.so
mips64-linux.xml                          vgpreload_memcheck-arm-linux.so
cll@cll-linux:/opt/valgrind-3.15.0/lib/valgrind $ 

當然我們還可以在PATH="/usr/bin:/usr/sbin:/bin:/sbin:/app/bin:/opt/valgrind-3.15.0/bin",黑色爲一些系統路徑配置(根據你自己profile裏面PATH路徑),添加後面紅色部分就行了,執行下source /etc/profile ,就可以當valgrind命令使用了

 

編譯

sudo make
sudo make install

運行

拷貝編譯的文件到開發版,最好目錄爲編譯目錄以防止找不到庫,當然也可以

export VALGRIND_LIB=/opt/valgrind-3.15.0/lib/valgrind

添加當前valgrind的路徑

export PATH=/opt/valgrind-3.15.0/bin:$PATH

運行....

    valgrind --tool=memcheck --leak-check=full ./xxx(需要監控的程序)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章