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

相关文章

MobaXterm远程登录工具功能与应用小结

《MobaXterm远程登录工具功能与应用小结》MobaXterm是一款功能强大的远程终端软件,主要支持SSH登录,拥有多种远程协议,实现跨平台访问,它包括多会话管理、本地命令行执行、图形化界面集成和... 目录1. 远程终端软件概述1.1 远程终端软件的定义与用途1.2 远程终端软件的关键特性2. 支持的

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Linux使用nload监控网络流量的方法

《Linux使用nload监控网络流量的方法》Linux中的nload命令是一个用于实时监控网络流量的工具,它提供了传入和传出流量的可视化表示,帮助用户一目了然地了解网络活动,本文给大家介绍了Linu... 目录简介安装示例用法基础用法指定网络接口限制显示特定流量类型指定刷新率设置流量速率的显示单位监控多个

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

Linux流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

Java数字转换工具类NumberUtil的使用

《Java数字转换工具类NumberUtil的使用》NumberUtil是一个功能强大的Java工具类,用于处理数字的各种操作,包括数值运算、格式化、随机数生成和数值判断,下面就来介绍一下Number... 目录一、NumberUtil类概述二、主要功能介绍1. 数值运算2. 格式化3. 数值判断4. 随机