Linux下安装Valgrind工具

2024-03-25 17:08
文章标签 工具 linux 安装 valgrind

本文主要是介绍Linux下安装Valgrind工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Linux下安装Valgrind工具

valgrind是一款很优秀的内存泄漏检测工具。
下面介绍如何在Linux下安装Valgrind。
首先下载安装包到/root目录下(或者其他目录);
[root@localhost ~]# ll
total 7200
-rw-------. 1 root root    2692 Apr 10 13:52 anaconda-ks.cfg
-rw-r--r--. 1 root root   39935 Apr 10 13:52 install.log
-rw-r--r--. 1 root root    9154 Apr 10 13:51 install.log.syslog
-rw-r--r--. 1 root root  303586 Apr 11 22:50 lua-5.3.4.tar.gz
-rw-r--r--. 1 root root 6998648 Apr 11 19:34 ntp-4.2.8p10.tar.gz
drwxr-xr-x. 2 root root    4096 Apr 12 18:57 sort
[root@localhost ~]# which valgrind
/usr/bin/which: no valgrind in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ll /root/
total 19692
-rw-------. 1 root root     2692 Apr 10 13:52 anaconda-ks.cfg
-rw-r--r--. 1 root root    39935 Apr 10 13:52 install.log
-rw-r--r--. 1 root root     9154 Apr 10 13:51 install.log.syslog
-rw-r--r--. 1 root root   303586 Apr 11 22:50 lua-5.3.4.tar.gz
-rw-r--r--. 1 root root  6998648 Apr 11 19:34 ntp-4.2.8p10.tar.gz
drwxr-xr-x. 2 root root     4096 Apr 12 18:57 sort
-rw-r--r--. 1 root root 12788556 Apr 14 17:56 valgrind-3.12.0.tar.bz2
[root@localhost src]# tar jxf /root/valgrind-3.12.0.tar.bz2 
[root@localhost src]# ll
total 12
drwxr-xr-x.  4 1026 1000 4096 Apr 11 23:02 lua-5.3.4
drwxrwsr-x. 23  427 6011 4096 Mar 21 07:47 ntp-4.2.8p10
drwxrwxr-x. 24 1000 1000 4096 Oct 21 04:03 valgrind-3.12.0
[root@localhost src]# cd valgrind-3.12.0/
[root@localhost valgrind-3.12.0]# ll
total 1996
-rw-rw-r--.  1 1000 1000  44566 Oct 21 03:42 aclocal.m4
-rw-rw-r--.  1 1000 1000   3267 Oct 21 03:37 AUTHORS
-rwxrwxr-x.  1 1000 1000    191 Oct 21 03:37 autogen.sh
drwxrwxr-x.  3 1000 1000   4096 Oct 21 04:01 auxprogs


将源码解压缩到/usr/local/src下。

阅读下valgrind中的README文件,可以看到如下信息:

Building and installing it
~~~~~~~~~~~~~~~~~~~~~~~~~~
To install from the Subversion repository :

  0. Check out the code from SVN, following the instructions at
     http://www.valgrind.org/downloads/repository.html.

  1. cd into the source directory.

  2. Run ./autogen.sh to setup the environment (you need the standard
     autoconf tools to do so). 

  3. Continue with the following instructions...

To install from a tar.bz2 distribution:

  4. Run ./configure, with some options if you wish.  The only interesting
     one is the usual --prefix=/where/you/want/it/installed.

  5. Run "make". 

  6. Run "make install", possibly as root if the destination permissions
     require that.

  7. See if it works.  Try "valgrind ls -l".  Either this works, or it
     bombs out with some complaint.  In that case, please let us know
     (see www.valgrind.org).

Important!  Do not move the valgrind installation into a place
different from that specified by --prefix at build time.  This will
cause things to break in subtle ways, mostly when Valgrind handles
fork/exec calls.

和通常的安装步骤一样:configure;make;make install
过程如下:

[root@localhost valgrind-3.12.0]# ./configure --prefix=/usr/local/valgrind
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
……
config.status: executing depfiles commands

         Maximum build arch: x86
         Primary build arch: x86
       Secondary build arch: 
                   Build OS: linux
       Primary build target: X86_LINUX
     Secondary build target: 
           Platform variant: vanilla
      Primary -DVGPV string: -DVGPV_x86_linux_vanilla=1
         Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp 

[root@localhost valgrind-3.12.0]# make
echo "# This is a generated file, composed of the following suppression rules:" > default.supp
echo "# " exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp  >> default.supp
cat exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
make  all-recursive
make[1]: Entering directory `/usr/local/src/valgrind-3.12.0'
Making all in include
make[2]: Entering directory `/usr/local/src/valgrind-3.12.0/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/src/valgrind-3.12.0/include'
Making all in VEX
……
make[1]: Leaving directory `/usr/local/src/valgrind-3.12.0'
[root@localhost valgrind-3.12.0]# make install
make  install-recursive
make[1]: Entering directory `/usr/local/src/valgrind-3.12.0'
Making install in include
make[2]: Entering directory `/usr/local/src/valgrind-3.12.0/include'
make[3]: Entering directory `/usr/local/src/valgrind-3.12.0/include'
make[3]: Nothing to be done for `install-exec-am'.
……
make[1]: Leaving directory `/usr/local/src/valgrind-3.12.0'
[root@localhost valgrind-3.12.0]# cd ..
[root@localhost src]# cd ..
[root@localhost local]# ll
total 40
drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 2 root root 4096 Sep 23  2011 include
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 10 13:42 share
drwxr-xr-x. 5 root root 4096 Apr 14 17:57 src
drwxr-xr-x. 6 root root 4096 Apr 14 18:04 valgrind
[root@localhost local]# which valgrind
/usr/bin/which: no valgrind in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)


make install后发现还是没有(没有找到)valgrind可执行文件。
其实这个时候已经有了,只是没有找到罢了。
我们可以将valgrind做一个软连接到/usr/local/bin下:
[root@localhost local]# cd valgrind/
[root@localhost valgrind]# ll
total 16
drwxr-xr-x. 2 root root 4096 Apr 14 18:04 bin
drwxr-xr-x. 3 root root 4096 Apr 14 18:04 include
drwxr-xr-x. 4 root root 4096 Apr 14 18:04 lib
drwxr-xr-x. 4 root root 4096 Apr 14 18:04 share
[root@localhost valgrind]# cd bin/
[root@localhost bin]# ll
total 392
-rwxr-xr-x. 1 root root 41112 Apr 14 18:04 callgrind_annotate
-rwxr-xr-x. 1 root root 12016 Apr 14 18:04 callgrind_control
-rwxr-xr-x. 1 root root 32170 Apr 14 18:04 cg_annotate
-rwxr-xr-x. 1 root root 10418 Apr 14 18:04 cg_diff
-rwxr-xr-x. 1 root root 49307 Apr 14 18:04 cg_merge
-rwxr-xr-x. 1 root root 24398 Apr 14 18:04 ms_print
-rwxr-xr-x. 1 root root 39093 Apr 14 18:04 valgrind
-rwxr-xr-x. 1 root root 65697 Apr 14 18:04 valgrind-di-server
-rwxr-xr-x. 1 root root 21037 Apr 14 18:04 valgrind-listener
-rwxr-xr-x. 1 root root 85247 Apr 14 18:04 vgdb
[root@localhost bin]# which valgrind
/usr/bin/which: no valgrind in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost bin]# cd /usr/local/bin/
[root@localhost bin]# ln -s /usr/local/valgrind/bin/valgrind valgrind
[root@localhost bin]# which valgrind
/usr/local/bin/valgrind

测试下:
[root@localhost bin]# valgrind ls -l
==16148== Memcheck, a memory error detector
==16148== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==16148== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==16148== Command: ls -l
==16148== 
total 0
lrwxrwxrwx. 1 root root 32 Apr 14 18:06 valgrind -> /usr/local/valgrind/bin/valgrind
==16148== 
==16148== HEAP SUMMARY:
==16148==     in use at exit: 13,069 bytes in 11 blocks
==16148==   total heap usage: 206 allocs, 195 frees, 62,575 bytes allocated
==16148== 
==16148== LEAK SUMMARY:
==16148==    definitely lost: 0 bytes in 0 blocks
==16148==    indirectly lost: 0 bytes in 0 blocks
==16148==      possibly lost: 0 bytes in 0 blocks
==16148==    still reachable: 13,069 bytes in 11 blocks
==16148==         suppressed: 0 bytes in 0 blocks
==16148== Rerun with --leak-check=full to see details of leaked memory
==16148== 
==16148== For counts of detected and suppressed errors, rerun with: -v
==16148== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 from 10)

OK,安装完成。
回想刚刚的安装步骤:
1.解压源代码到/usr/local/src下;
2.configure --prefix=/usr/local/valgrind;
3.make && make install;
4.ln做一个软连接到/usr/local/bin中;
大功告成。

这篇关于Linux下安装Valgrind工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845663

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

Centos7安装Mongodb4

1、下载源码包 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz 2、解压 放到 /usr/local/ 目录下 tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgzmv mongodb-linux-x86_64-rhel70-4.2.1/

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

Centos7安装JDK1.8保姆版

工欲善其事,必先利其器。这句话同样适用于学习Java编程。在开始Java的学习旅程之前,我们必须首先配置好适合的开发环境。 通过事先准备好这些工具和配置,我们可以避免在学习过程中遇到因环境问题导致的代码异常或错误。一个稳定、高效的开发环境能够让我们更加专注于代码的学习和编写,提升学习效率,减少不必要的困扰和挫折感。因此,在学习Java之初,投入一些时间和精力来配置好开发环境是非常值得的。这将为我

高效录音转文字:2024年四大工具精选!

在快节奏的工作生活中,能够快速将录音转换成文字是一项非常实用的能力。特别是在需要记录会议纪要、讲座内容或者是采访素材的时候,一款优秀的在线录音转文字工具能派上大用场。以下推荐几个好用的录音转文字工具! 365在线转文字 直达链接:https://www.pdf365.cn/ 365在线转文字是一款提供在线录音转文字服务的工具,它以其高效、便捷的特点受到用户的青睐。用户无需下载安装任何软件,只

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

安装nodejs环境

本文介绍了如何通过nvm(NodeVersionManager)安装和管理Node.js及npm的不同版本,包括下载安装脚本、检查版本并安装特定版本的方法。 1、安装nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash 2、查看nvm版本 nvm --version 3、安装