eightbitraptor[wiki]

Debugging Ruby GC

Most of the stuff in [debugging] also applies but there are some specific things that can help out when debugging the GC

Custom info from weird parts of the code

There’s a common pattern of printing to stderr by doing

if (0) fprintf(stderr, "stuff");

This is particularly prevalent around the GC and the VM code.

If you want to see what the output is, just change the 0 to 1 and then recompile and rerun.

GC_DEBUG

Enable by editing the Makefile and adding -DGC_DEBUG to the debugflags

embeds GC debugging information inside the RVALUE struct (file and line that the object was created)

This is added in gc.c during the newobj_init function.

It’s also used during gc_mark_children

RGENGC_DEBUG

Enable by editing the Makefile and adding -DRGENGC_DEBUG=<n> to the debugflags

Where <n> is a number representing the level at which we want to print out debug information.

'RGENGC_CHECK_MODE

This checks the internal state of the GC at various points (and is basically the only way to trigger the gc_check_internal_consistency function)