Provide a native Haskell stack unwinder
While DWARF is great for BSDs and Linux, we currently have no story for stack unwinding on non-ELF platforms. However, one of the largest use-cases for stack unwinding, exception backtraces (see #18159) could be served adequately with a simple Haskell-only stack unwinder.
The unwinder itself would be nearly trivial to write. The challenge is providing source locations and meaningful symbol names. In principle we could attach this information to return frame info tables, although this would come at a performance cost. I think it would be preferable to rather maintain this information out-of-band. That is, the compiler (when requested by the user with -fclosure-provs
) emits top-level values of the form for each return info table:
-- | Source provenance for a closure or stack frame.
data ClosureProv = ClosureProv { srcLoc :: SrcLoc, moduleName :: Addr#, bindName :: Addr# }
Along with a section containing an associated list of (StgInfoTable*, ClosureProv*)
pairs. We could then traverse this list at runtime, allowing us to build a hashmap to determine the ClosureProv*
of a particular return frame.