内存泄露调试——valgrind

内存泄露调试

最近遇到内存泄露的问题,所以找了很多测试的方法和工具。其中比较好用的是valgrind,很适合在linuxarm上使用。

valgrind

参考

http://www.cnblogs.com/oloroso/p/5085202.html   

http://blog.csdn.net/lizhangping/article/details/51833997 

下载:

ftp://sourceware.org/pub/valgrind/valgrind-3.13.0.tar.bz2

解压:

注意解压在linux目录下,非window或共享目录下。

tar -xvf valgrind-3.13.0.tar.bz2 valgrind-3.13.0/

 

交叉编译:

./configure --host=arm-hisiv200-linux CC=arm-hisiv200-linux-gcc CPP=arm-hisiv200-linux-cpp  CXX=arm-hisiv200-linux-g++ --prefix=/nfsroot/valgrind

注意:--prefix=/nfsroot/Valgrind指定的目录要与开发板上放置的目录一致,不然运行valgrind时可能会出现“valgrind: failed to start tool 'memcheck' for platform 'arm-Linux': No such file or directory”错误。并且确保目录有足够大的空间。

出错:

checking for a supported CPU... no (arm)

configure: error: Unsupported host architecture. Sorry

》》》修改configure文件中的:

case "${host_cpu}" in
 armv7*|arm)

 

继续执行上面的configure,成功后再执行:

# sudo make

#sudo make install

出错:

记得之前编译过的话要make clean


运行make

有可能出错 “命令没找到”

/bin/sh ,ubuntu 使用的是bash,可以软连接sh  bash

有可能出错 “操作不支持”

可以用sudo(但是我用sudo make会错,用make不会错)

运行make install

有可能出错  权限不够。

因为这个命令需要创建文件,所以要给 su 权限

有可能出错(交叉编译工具)“命令没找到”

是环境变量的问题,sudo make install 会有问题。 所以要直接 su -s

然后设置 管理员  的环境变量,也就是交叉编译工具的地址

export PATH=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin:$PATH

成功后,在相应的文件夹里找到。

 

在开发板上配置运行:

可以nfs 到  arm 上的 /nfsroot/valgrind

也可以软链接到 /sbin 上就可以全局命令使用

ln -sf /nfsroot/valgrind/bin/valgrind   /sbin

运行:

注意这里程序不能带参数

valgrind --tool=memcheck --leak-check=full ./sample_save_av

它会显示有多少块没有释放,大致在哪个地方,可以进行程序的更改了。

出错:

在开发板运行有这个错误,还不知道是什么原因。

==2354== Memcheck, a memory error detector
==2354== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2354== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2354== Command: ./sample_save_av
==2354==
==2354== error 22 Invalid argument
==2354== error VG_(am_shared_mmap_file_float_valgrind) /tmp/vgdb-pipe-shared-mem-vgdb-2354-by-root-on-???


猜你喜欢

转载自blog.csdn.net/qq_23282479/article/details/76650907