Skip to content

RTS execution stacks are broken in GHC 8.10-9.2

Summary

The execution stack feature accessible through GHC.ExecutionStack doesn't seem to work at all under at last GHC 8.10.5 and the 9.2.0 prerelease. Trying to use either showStackTrace or getStackTrace prints an error and the stack trace ends in rts/libdw.c. This is related to #14510.

Steps to reproduce

  1. Install the ghc-8.10.5-x86_64-deb10-linux-dwarf.tar.xz bindist. I also tested a self compiled version of GHC 8.10.5 and 9.2.0.20210422 with DWARF support and debug symbols. To install this bindist I used ghcup install ghc -u https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-deb10-linux-dwarf.tar.xz ghc-8.10.5-dwarf.

  2. Create ExecutionStacks.hs containing the following:

    module Main where
    
    import           Control.Monad                  ( forM_ )
    import           GHC.ExecutionStack
    
    main :: IO ()
    main = foo
    
    foo :: IO ()
    foo = do
        Just stack <- getStackTrace
        forM_ stack $ \(Location object fn loc) ->
            putStrLn $ maybe object sourceFile loc ++ ": " ++ fn
    
  3. Compile and run this with ghc-8.10.5-dwarf -debug -g3 ExecutionStacks.hs && ./ExecutionStacks.

Expected behavior

I expect to see a stack trace containing some kind of reference to both foo and to main, and no errors.

Observed behavior

The following gets printed:

/home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/ghc: /usr/lib/libtinfo.so.6: no version information available (required by /home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/../haskeline-0.8.0.1/libHShaskeline-0.8.0.1-ghc8.10.5.so)
/home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/ghc: /usr/lib/libtinfo.so.6: no version information available (required by /home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/../ghc-8.10.5/libHSghc-8.10.5-ghc8.10.5.so)
/home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/ghc: /usr/lib/libtinfo.so.6: no version information available (required by /home/robbert/.ghcup/ghc/8.10.5-dwarf/lib/ghc-8.10.5/bin/../terminfo-0.4.1.4/libHSterminfo-0.4.1.4-ghc8.10.5.so)
[1 of 1] Compiling Main             ( ExecutionStacks.hs, ExecutionStacks.o )
Linking ExecutionStacks ...
ExecutionStacks: Failed to get stack frames of current process: no matching address range: Invalid argument
rts/Libdw.c: set_initial_registers
: dwfl_thread_getframes
/usr/lib/libdw-0.185.so: 
/usr/lib/libdw-0.185.so: dwfl_getthreads
/usr/lib/libdw-0.185.so: dwfl_getthread_frames
rts/Libdw.c: libdwGetBacktrace
libraries/base/GHC/ExecutionStack/Internal.hsc: base_GHCziExecutionStackziInternal_collectStackTrace1_info

Environment

  • GHC versions used: Self compiled GHC 8.10.5 and 9.2.0.20210422 with --enable-dwarf-unwind and both GhcLibHcOpts += -g3 and GhcRtsHcOpts += -g3 set through build.mk, as well as the ghc-8.10.5-x86_64-deb10-linux-dwarf.tar.xz bindist
  • Operating System: Manjaro Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information