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

相关文章

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

Linux samba共享慢的原因及解决方案

《Linuxsamba共享慢的原因及解决方案》:本文主要介绍Linuxsamba共享慢的原因及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux samba共享慢原因及解决问题表现原因解决办法总结Linandroidux samba共享慢原因及解决

MySQL Workbench 安装教程(保姆级)

《MySQLWorkbench安装教程(保姆级)》MySQLWorkbench是一款强大的数据库设计和管理工具,本文主要介绍了MySQLWorkbench安装教程,文中通过图文介绍的非常详细,对大... 目录前言:详细步骤:一、检查安装的数据库版本二、在官网下载对应的mysql Workbench版本,要是

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

使用Java实现通用树形结构构建工具类

《使用Java实现通用树形结构构建工具类》这篇文章主要为大家详细介绍了如何使用Java实现通用树形结构构建工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录完整代码一、设计思想与核心功能二、核心实现原理1. 数据结构准备阶段2. 循环依赖检测算法3. 树形结构构建4. 搜索子

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark