Portable debug symbol table without libbfd requirement?
rts/Printer.c
implements various heap printing functions that are used by the debug RTS. When it comes to printing a pointer, it might be a static data/function entity associated with a symbol, and printing the symbol instead of an opaque hex pointer would be much more helpful to debugging.
As of today, if you configure GHC with --enable-bfd-debug
, then the debug RTS would link against libbfd
and use that to parse the Haskell executable itself and extract symbol info. libbfd
has a number of backends representing what binaries it can parse, ELF/COFF is included, but some other modern formats are not (e.g. Mach-O or wasm).
It's actually pretty simple to implement a portable debug symbol table mechanism that works on any target that links the C RTS. We can add a GHC flag to emit a special constructor for each module to update the RTS debug symbol table with mappings from symbols to their name strings. Compared to libbfd
, this is slightly more limited on Linux since the C foreign symbols will be missing, but the majority of the symbols dumped by Printer.c
are Haskell/Cmm entities anyway, so a portable implementation still improves the status quo a lot.