Valgrind must have fixed memory limits so that it can accurately track the memory allocations of the program under test. On 64 bit architectures it is limited to 64GB. This script will download, modify and build valgrind for larger memory configurations.
Here is an example of how you might download and use it to create a 128GB version.
1 2 3 4 5 6 |
$ # Example - 128GB $ mkdir -p work/valgrind/3.9.0 $ cd work/valgrind/3.9.0 $ wget http://projects.joelinoff.com/valgrind/valgrind-3.9.0-setup.sh $ ./valgrind-3.9.0-setup.sh 128 2>&1|tee log # Build a 128GB version. $ ./rtf/bin/valgrind -h |
Here is an example of how you might download and use it to create a 256GB version.
1 2 3 4 5 6 |
$ # Example - 256GB $ mkdir -p work/valgrind/3.9.0 $ cd work/valgrind/3.9.0 $ wget http://projects.joelinoff.com/valgrind/valgrind-3.9.0-setup.sh $ ./valgrind-3.9.0-setup.sh 256 2>&1|tee log # Build a 256GB version. $ ./rtf/bin/valgrind -h |
Here is a description of how you might use it on an example program.
Step 1. Compile and link the program
In this very simple example I am using debug compile flags with extensions that provide more information in valgrind. These compile flags must be used with a newer GNU compiler like 4.7.2. I am using 4.9.1 for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
$ RTFDIR="/opt/gcc/4.9.1" # g++ 4.9.1 compiler (local installation) $ export PATH="$RTFDIR/bin:${PATH}" $ export LD_LIBRARY_PATH="$RTFDIR/lib64:$RTFDIR/lib:${LD_LIBRARY_PATH}" $ cat test.cc #include <vector> #include <string> #include <iostream> #include <iomanip> using namespace std; void sub1() { vector<string> strs; for(int i=1; i<10; i++) { char buf[79]; for(unsigned i=0; i<sizeof(buf); i++) { buf[i] = '0' + i; } buf[sizeof(buf)-1] = 0; strs.push_back(buf); } unsigned i=0; for(auto str : strs) { cout << right << setw(4) << ++i << " " << str.size() << "\"" << str << "\" " << endl; } } int main() { cout << "test" << endl; sub1(); cout << "done" << endl; return 0; } $ g++ --version g++ (GCC) 4.9.1 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -DDEBUG \ -std=c++11 \ -Wall \ -g3 \ -gno-strict-dwarf \ -gdwarf-3 \ -fvar-tracking \ --param max-vartrack-size=0 \ --param max-vartrack-expr-depth=50 \ -o ./test.exe \ test.cc $ ./test.exe test 1 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 2 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 3 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 4 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 5 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 6 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 7 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 8 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 9 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" done |
Step 2. Run valgrind
This is how you might run valgrind. It includes a suppression file just to show how it works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
$ cat test.supp # This is an example suppression. # It is not needed for this example. { ipp-suppress-conditional-jump1 Memcheck:Cond fun:index fun:expand_dynamic_string_token fun:_dl_map_object fun:map_doit } $ ~/work/valgrind/3.9.0/rtf/bin/valgrind --version valgrind-3.9.0 $ RTFDIR="/opt/gcc/4.9.1" # g++ 4.9.1 compiler (local installation) $ export PATH="$RTFDIR/bin:${PATH}" $ export LD_LIBRARY_PATH="$RTFDIR/lib64:$RTFDIR/lib:${LD_LIBRARY_PATH}" $ ~/work/valgrind/3.9.0/rtf/bin/valgrind \ --tool=memcheck \ --error-limit=no \ --free-fill=0xcd \ --keep-stacktraces=alloc-and-free \ --leak-check=full \ --leak-resolution=med \ --main-stacksize=16777216 \ --malloc-fill=0xab \ --max-stackframe=4194304 \ --num-callers=50 \ --read-var-info=yes \ --show-reachable=yes \ --suppressions=./test.supp \ --trace-children=yes \ --track-origins=yes \ -v \ ./test.exe ==23754== Memcheck, a memory error detector ==23754== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==23754== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==23754== Command: ./test.exe ==23754== --23754-- Valgrind options: --23754-- --tool=memcheck --23754-- --error-limit=no --23754-- --free-fill=0xcd --23754-- --keep-stacktraces=alloc-and-free --23754-- --leak-check=full --23754-- --leak-resolution=med --23754-- --main-stacksize=16777216 --23754-- --malloc-fill=0xab --23754-- --max-stackframe=4194304 --23754-- --num-callers=50 --23754-- --read-var-info=yes --23754-- --show-reachable=yes --23754-- --suppressions=./test.supp --23754-- --trace-children=yes --23754-- --track-origins=yes --23754-- -v --23754-- Contents of /proc/version: --23754-- Linux version 2.6.18-308.16.1.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Tue Oct 2 2 2:50:05 EDT 2012 --23754-- Arch and hwcaps: AMD64, amd64-cx16-rdtscp-sse3 --23754-- Page sizes: currently 4096, max supported 4096 --23754-- Valgrind library directory: /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind --23754-- Reading syms from /work/jlinoff/work/valgrind/work/cc/test.exe --23754-- Reading syms from /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/memcheck-amd64-linux --23754-- object doesn't have a dynamic symbol table --23754-- warning: addVar: unknown size (ips) --23754-- warning: addVar: unknown size (kwds) --23754-- warning: addVar: unknown size (buf) --23754-- warning: addVar: unknown size (buf) --23754-- warning: addVar: unknown size (buf) --23754-- warning: addVar: unknown size (buf) --23754-- warning: addVar: unknown size (buf) --23754-- warning: addVar: unknown size (comps) --23754-- warning: addVar: unknown size (comps) --23754-- warning: addVar: unknown size (comps) --23754-- Reading syms from /lib64/ld-2.5.so --23754-- Scheduler: using generic scheduler lock implementation. --23754-- Reading suppressions file: ./test.supp --23754-- Reading suppressions file: /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/default.supp ==23754== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-23754-by-jlinoff-on-jlinoff-lin ==23754== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-23754-by-jlinoff-on-jlinoff-lin ==23754== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-23754-by-jlinoff-on-jlinoff-lin ==23754== ==23754== TO CONTROL THIS PROCESS USING vgdb (which you probably ==23754== don't want to do, unless you know exactly what you're doing, ==23754== or are doing some strange experiment): ==23754== /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/../../bin/vgdb --pid=23754 ...command... ==23754== ==23754== TO DEBUG THIS PROCESS USING GDB: start GDB like this ==23754== /path/to/gdb ./test.exe ==23754== and then give GDB the following command ==23754== target remote | /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/../../bin/vgdb --pid=23754 ==23754== --pid is optional if only one valgrind process is running ==23754== --23754-- REDIR: 0x3ecf614730 (strlen) redirected to 0x3804d051 (vgPlain_amd64_linux_REDIR_FOR_strlen) --23754-- Reading syms from /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/vgpreload_core-amd64-linux.so --23754-- Reading syms from /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/vgpreload_memcheck-amd64-linux.so --23754-- REDIR: 0x3ecf614550 (index) redirected to 0x4a08cf0 (index) --23754-- REDIR: 0x3ecf614700 (strcmp) redirected to 0x4a09630 (strcmp) --23754-- Reading syms from /tools/sw/prod/centos-5.5-x86_64/opt/gcc-4.9.1/lib64/libstdc++.so.6.0.20 --23754-- Reading syms from /lib64/libm-2.5.so --23754-- Reading syms from /tools/sw/prod/centos-5.5-x86_64/opt/gcc-4.9.1/lib64/libgcc_s.so.1 --23754-- Reading syms from /lib64/libc-2.5.so --23754-- REDIR: 0x3ecfa78cc0 (rindex) redirected to 0x4a08b40 (rindex) --23754-- REDIR: 0x3ecfa788d0 (strlen) redirected to 0x4a09050 (strlen) --23754-- REDIR: 0x3ecfa78350 (strcmp) redirected to 0x4a09590 (strcmp) --23754-- REDIR: 0x3ecfa79540 (bcmp) redirected to 0x4a0a730 (bcmp) test --23754-- REDIR: 0x4c6d8e0 (operator new(unsigned long)) redirected to 0x4a0861e (operator new(unsigned long)) --23754-- REDIR: 0x3ecfa7afc0 (memcpy) redirected to 0x4a09c20 (memcpy) --23754-- REDIR: 0x4c6bb40 (operator delete(void*)) redirected to 0x4a06fe3 (operator delete(void*)) --23754-- REDIR: 0x3ecfa79b80 (memset) redirected to 0x4a0ac60 (memset) --23754-- REDIR: 0x3ecfa7a6b0 (mempcpy) redirected to 0x4a0b240 (mempcpy) 1 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 2 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 3 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 4 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 5 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 6 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 7 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 8 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" 9 78"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}" done --23754-- REDIR: 0x3ecfa715f0 (free) redirected to 0x4a073fd (free) ==23754== ==23754== HEAP SUMMARY: ==23754== in use at exit: 0 bytes in 0 blocks ==23754== total heap usage: 14 allocs, 14 frees, 1,175 bytes allocated ==23754== ==23754== All heap blocks were freed -- no leaks are possible ==23754== ==23754== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 7) --23754-- --23754-- used_suppression: 4 U1004-ARM-_dl_relocate_object /tools/sw/prod/centos-6.3-x86_64/opt/lib/valgrind/default.supp:1391 --23754-- used_suppression: 3 ipp-suppress-conditional-jump1 ./test.supp:4 ==23754== ==23754== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 7) |
Enjoy!