How to build executables that will dump live backtraces

Carter Schonwald carter.schonwald at gmail.com
Wed Feb 21 18:56:35 UTC 2024


Have you looked at
https://www.haskell.org/ghc/blog/20200403-dwarf-1.html or other docs online
?

On Tue, Feb 20, 2024 at 7:40 PM Clinton Mead <clintonmead at gmail.com> wrote:

> Hi All
>
> I've noticed this is a quiet mailing list recently, but I couldn't find a
> more appropriate place to ask this question. Please say if there's
> somewhere else I should be asking.
>
> It's my understanding that one can get GHC executables to dump backtraces
> of all their running threads to stderr upon receiving SIGQUIT. And the way
> to do that is to build with 'libdw' support.
>
> We have a build system using Nix, and we're unfortunately a bit behind on
> GHC 9.2.2 atm, but in anycase, I noticed in a Nix develop shell when I run
> `ghc --info | grep libdw` I get:
>
> ,("RTS expects libdw","NO")
>
> So I instead added the following to my Haskell package overrides:
>
> ghc = old.ghc.overrideAttrs (oldAttrs: { configureFlags =
> oldAttrs.configureFlags ++ [ "--with-libdw-includes=${pkgs.elfutils.dev}/include"
> "--with-libdw-libraries=${pkgs.elfutils.out}/lib" "--enable-dwarf-unwind"
> ]; buildInputs = oldAttrs.buildInputs ++ [pkgs.elfutils]; });
>
> I basically copy/pastaed this from
> https://github.com/input-output-hk/haskell.nix/blob/master/compiler/ghc/default.nix
>
> And this seems to work, now when I run `ghc --info` I get:
>
> ,("RTS expects libdw","YES")
>
> But despite building with this version of GHC, still when I send `SIGQUIT`
> to a process built with this version of GHC, I just get the message:
>
> "This build does not support backtraces."
>
> Now I have also been building my packages with `-g`, passing
> `--enable-debug-info` etc, although it's my understanding that what I've
> done just with building GHC with `--enable-dwarf-unwind` _should_ be enough
> to get a backtrace upon SIGQUIT, it might just be a poor one if the
> debugging symbols aren't added.
>
> But clearly I've missed something if it's not working. I'm not quite sure
> what set of circumstances the message "This build does not support
> backtraces" is displayed? Is there a runtime check to see whether the
> "libdw" library is actually in the library path, in addition to the
> requirement that GHC be built with libdw support? If that's the case,
> perhaps as I'm running this on NixOS I need to add something to my
> executable's LD_LIBRARY_PATH or something? Or is there some option I need
> to give GHC/Cabal to ensure that backtrace support is added to the
> executable's runtime as well as making sure I've compiled with GHC that's
> compiled with libdw support? Or is there some other runtime RTS option I
> need to give to my executable?
>
> As you can see, I'm completely lost about how to move forward on this, so
> any help would be very much appreciated.
>
> Thanks,
> Clinton
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20240221/953b983c/attachment.html>


More information about the Glasgow-haskell-users mailing list