sourcecode

Monday, May 6, 2013

Start valgrind

Profiler under linux64

1. Install
http://www.cprogramming.com/debugging/valgrind.html
Download from http://www.valgrind.org/downloads/valgrind-3.8.1.tar.bz2
Then
$ bzip2 -d valgrind-XYZ.tar.bz2
$ tar -xf valgrind-XYZ.tar
$ ./configure
$ make
$ make install 
Then need to install the glibc-debuginfo
$ sudo apt-get install valgrind

2. Write a C++ program
http://jblevins.org/log/valgrind
#include <stdlib.h>

  void f(void)
  {
     int* x = (int*)malloc(10 * sizeof(int));
     x[10] = 0;        // problem 1: heap block overrun
  }                    // problem 2: memory leak -- x not freed

  int main(void)
  {
     f();
     return 0;
  }


3. Compile it with -g debug flag on

4. run
$ valgrind ./a.out