I'm writing a logger/tracer that emits a line for every function
entry/exit. It naturally makes use of the GC, as it manipulates
strings (and calls to!string on arguments, etc).
Traced functions may be called normally, but sometimes they are
called from a destructor (during a collection). When the latter
happens, it gets to my tracer's code, which tries to allocate
memory, and dies with a SEGFAULT. It seems that it tried to raise
an exception but failed:
Program received signal SIGSEGV, Segmentation fault.
0x00000000007f406d in _d_throwc ()
(gdb) bt
#0 0x00000000007f406d in _d_throwc ()
#1 0x0000000000835ec8 in onInvalidMemoryOperationError ()
#2 0x0000000000831296 in gc.gc.GC.mallocNoSync() ()
#3 0x0000000000831207 in gc.gc.GC.malloc() ()
#4 0x00000000007f2578 in gc_qalloc ()
#5 0x00000000007f507a in _d_newarrayiT ()
#6 0x0000000000546385 in
std.array.__T9replicateTAyaZ.replicate() (n=2, s=...) at
/usr/include/dmd/phobos/std/array.d:1313
#7 0x000000000067a3a7 in
foo.runtime.tracing.__T9enterFuncTkZ.enterFunc() (_param_1=0,
funcName=...) at ...
...
#17 0x000000000055d9fd in main ()
First of all, the SEGFAULT seems to be a bug in the GC itself
which probably deserves a ticket. I'd settle with simply
disabling my tracer during GC, but there doesn't seem to be any
way to tell if I'm in a collection or not.
This is what I'm after:
https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L440
Any help would be appreciated.
-tomer