Valgrind 3.11.0 Compile and install
The Valgrind is a software development tool for memory debugging, memory leak detection, and performance analysis.
Valgrind complies with the GNU General Public License Terms and is a free software.
As of version 3.3.0, Valgrind supports Linux on x86, x86-64, and PowerPC. In addition, there are other Unix-like platforms that are informally supported (such as FreeBSD, NetBSD, and Mac OS X).
1. Download Valgrind 3.11.0
Download the source package directly
wget http://valgrind.org/downloads/valgrind-3.11.0.tar.bz2tar -xjvf valgrind-3.11.0.tar.bz2 cd valgrind-3.11.0/
Use SVN to clone a
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
2. Generate makefile and use it to compile
The Makefile
steps that README
are generated are written in this file.
-
- Run
./autogen.sh
to set the environment (you need standard autoconf
tools)
This script is actually called aclocal
autoheader
automake
autoconf
, so you must install it first, if not installed, you will be prompted when you run the script.
-
- Run
./configure
to generate Makefile
files
Here you can use ./configure --help
to see which parameter settings you can use.
Generally set the installation path can be./configure --prefix=/usr/local/valgrind
-
- Run to
make
compile, run make install
to install.
Here are the steps I compile
#运行 Autogen.SH[email protected]-pc:~/software/valgrind-3.11.0$./autogen.SHRunning:aclocalrunning:autoheaderrunning:automake-arunning:autoconf# run Configure[email protected]-pc:~/software/valgrind-3.11.0$./configure--prefix=/usr/local/valgrindchecking forA bsd-compatibleInstall.../usr/bin/Install-c ..... config.status:executing depfiles Commands Maximum build arch:amd64 Primary build Arch : AMD64 Secondary build arch:x86 build os:linux ... #运行make [email protected]-pc:~/software/valgrind-3.11.0$ MakeEcho "# This is a generated file, composed of the following suppression rules:">Default.suppEcho "# "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.suppCatExp-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 Makeall-recursive ... #运行makeInstall[email protected]-pc:~/software/valgrind-3.11.0$sudo Make Install[sudo] O's password: Make Install-Recursive ...
3, test
Once the compilation is complete, you can test it.
Because the installation directory was specified when the installation was compiled, the directory path needs to be valgrind
bin
added to the environment variable PATH
. Otherwise, only the full path can be used to runvalgrind
Here I write it to the ~/.bashrc
file. Open the ~/.bashrc
file, and then add a line at the end PATH=${PATH}:/usr/local/valgrind/bin
, then use it source ~/.bashrc
to update it.
Really test OH (this is the readme given in the test command)
[Email protected]:~/software$ valgrindls-L==4504==Memcheck, a memory error detector==4504Copyright (C)2002- -, and GNU GPL'd, by Julian Seward et al.==4504= = Using valgrind-3.11.0and Libvex; Rerun With-h forCopyrightInfo==4504= = Command:ls-L==4504==Total Dosage11636DRWXRWXR-X -o O4096December in One: Onevalgrind-3.11.0-rw-rw-r--1o O11910809September at -: -valgrind-3.11.0.Tar. bz2==4504== ==4504==HEAP SUMMARY:==4504==inchUse at exit: +,436bytesinch 8blocks==4504= = Total Heap Usage:205Allocs,197Frees, the,286Bytes Allocated==4504== ==4504==LEAK SUMMARY:==4504= = Definitely lost:0bytesinch 0blocks==4504= = indirectly lost:0bytesinch 0blocks==4504= = possibly lost:0bytesinch 0blocks==4504= = still reachable: +,436bytesinch 8blocks==4504= = suppressed:0bytesinch 0blocks==4504= = Rerun with--leak-check=Full to see details of leaked memory==4504== ==4504= = Counts of detected and suppressed errors, rerun with:-v==4504= = ERROR SUMMARY:0Errors from0Contexts (suppressed:1From1)
Write yourself a small example of memory access out of bounds and leaks to test
#include <stdlib.h>int main () { (Char*)malloc()[10 ; return 0 ;}
Use the following command to check
valgrind --track-fds=yes --leak-check=full --undef-value-errors=yes
Check Results
==4842==Memcheck, a memory error detector==4842Copyright (C)2002- -, and GNU GPL'd, by Julian Seward et al.==4842= = Using valgrind-3.11.0and Libvex; Rerun With-h forCopyrightInfo==4842= = Command:./Test==4842== ==4842= = InvalidWriteof size1# This detects a memory out-of-bounds access==4842= = at0x400548: Main (inch/home/o/software/test)==4842= = Address0x520204aIs0Bytes after a block of sizeTenAlloc'D==4842= = at0X4C2BC50: malloc (VG_REPLACE_MALLOC.C:299)==4842= = by0x400543: Main (inch/home/o/software/test)==4842== ==4842== ==4842= = FILE descriptors:3Open at exit. #打开了三个文件描述符 (Standard input/output error)==4842= = OpenfileDescriptor2:/dev/pts/ A==4842= = <inherited from parent>==4842== ==4842= = OpenfileDescriptor1:/dev/pts/ A==4842= = <inherited from parent>==4842== ==4842= = OpenfileDescriptor0:/dev/pts/ A==4842= = <inherited from parent>==4842== ==4842== ==4842==HEAP SUMMARY: #堆使用摘要==4842==inchUse at exit:Tenbytesinch 1blocks==4842= = Total Heap Usage:1Allocs,0Frees,TenBytes Allocated #申请/Release Details==4842== ==4842==Tenbytesinch 1Blocks is definitely lostinchLoss record1Of1==4842= = at0X4C2BC50: malloc (VG_REPLACE_MALLOC.C:299)==4842= = by0x400543: Main (inch/home/o/software/test)==4842== ==4842==LEAK SUMMARY: Disclosure Summary==4842= = Definitely lost:Tenbytesinch 1blocks==4842= = indirectly lost:0bytesinch 0blocks==4842= = possibly lost:0bytesinch 0blocks==4842= = still reachable:0bytesinch 0blocks==4842= = suppressed:0bytesinch 0blocks==4842== ==4842= = Counts of detected and suppressed errors, rerun with:-v==4842= = ERROR SUMMARY:2Errors from2Contexts (suppressed:1From1)
You can see that memory out-of-bounds access and memory leaks are detected above.
General Write Play program can be used valgrind
to detect, to avoid memory leakage problems (and file open situation)
Valgrind 3.11.0 Compile and install