mikestillman / M2

The primary source code repository for Macaulay2
4 stars 2 forks source link

howto debug memory errors using valgrind+garbage collector #28

Open jakobkroeker opened 10 years ago

jakobkroeker commented 10 years ago

we should figure out, how to debug memory errors using valgrind+garbage collector, or is it possible to disable gc?

(recall the bug in ColumnRankProfile, see https://groups.google.com/forum/#!topic/ffpack-devel/2mwmhJpvQQ4 ) somewhat useful: GC_DONT_GC environment flag

another helpful way is replacing GC_MALLOC with malloc using LD_PRELOAD e.g.

with malloc.c:

#include <stdio.h>
#include <stdlib.h>

void * GC_malloc(size_t a)
{
 // printf("calling my malloc\n");
  return malloc(a);
}

gcc -fPIC -shared malloc.c -o libmygc.so

export LD_PRELOAD = ./libmygc.so

mikestillman commented 10 years ago

In order for the e/unit-tests to not use gc (so that valgrind will detect more issues), what is needed?

  1. remove calls to GC_MALLOC, etc. in M2mem-replacement.c
  2. flint needs to be compiled without gc support
  3. use of finalizers in e directory: these functions should be made into no ops.
  4. remove -lgc from the included libraries
  5. remember to add libraries to LD_LIBRARY_PATH (add libraries/final/lib to this list)
  6. initialize factory correctly? (Is something needed here: need to check this)
  7. what else?
mahrud commented 5 years ago

With new changes to GC, would be good to document debugging memory issues. One way I've tried is using Flamegraphs: http://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html