Skip to content

Valgrind

Michael Torpey edited this page Sep 16, 2016 · 4 revisions

On a Linux machine with valgrind installed, start running GAP with

valgrind --trace-children=yes gap

trace-children indicates that you want to use Valgrind inside the actual GAP executable, not just in the script that starts it.

To check for memory leaks, use the additional flag --leak-check=full. Then when you exit, valgrind will show a list of any memory allocations that were not freed.

Note that in order to inspect GAP with Valgrind in this way, optimisation needs to be turned off, and a "memory canary" needs to be defined. In src/gasman.h, before line 265 #ifdef MEMORY_CANARY, add the line

#define MEMORY_CANARY

Now, from your gap directory, go to the directory called something like bin/x86_64-unknown-linux-gnu-gcc-default64/, and open Makefile. Change the line that looks like

CFLAGS=-Wall -g -O2  -g -O2 $(COPTS)

to

CFLAGS=-Wall -g $(COPTS)

(i.e. remove the occurrences of -O2)

This should allow you to use Valgrind as shown above. The rest is just using the debugger as normal.

This page contains instructions for debugging with GDB if an error is found.

Clone this wiki locally