How to build executables that will dump live backtraces

Clinton Mead <[email protected]> Wed, 21 Feb 2024 11:39:56 +1100
Newsgroups gmane.comp.lang.haskell.glasgow.user
Message-ID <CAFDVgwHZyfLtDuJO-aWAcMhGZxJ1CPRvq4krJ-6NyFrm0ahxZg@mail.gmail.com>
--===============3061447177062729207==
Content-Type: multipart/alternative; boundary="0000000000009962e60611d991c8"

--0000000000009962e60611d991c8
Content-Type: text/plain; charset="UTF-8"

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

--0000000000009962e60611d991c8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi All<br><br>I&#39;ve noticed this is a quiet mailing lis=
t recently, but I couldn&#39;t find a more appropriate place to ask this qu=
estion. Please say if there&#39;s somewhere else I should be asking.<br><br=
>It&#39;s my understanding that one can get GHC executables to dump backtra=
ces of all their running threads to stderr upon receiving SIGQUIT. And the =
way to do that is to build with &#39;libdw&#39; support.<div><br></div><div=
>We have a build system using Nix, and we&#39;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:</div><div><br></div><div><span style=
=3D"color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,&quot;Courier New=
&quot;,monospace;font-size:12px;font-variant-ligatures:none;background-colo=
r:rgba(29,28,29,0.04)">,(&quot;RTS expects libdw&quot;,&quot;NO&quot;)</spa=
n><br></div><div><br></div><div>So I instead added the following to my Hask=
ell package overrides:<br></div><div><br></div><div><span style=3D"color:rg=
b(29,28,29);font-family:Monaco,Menlo,Consolas,&quot;Courier New&quot;,monos=
pace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28=
,29,0.04)">ghc =3D=20
  old.ghc.overrideAttrs (oldAttrs: {
    configureFlags =3D oldAttrs.configureFlags ++
      [
        &quot;--with-libdw-includes=3D${<a href=3D"http://pkgs.elfutils.dev=
">pkgs.elfutils.dev</a>}/include&quot;=20
        &quot;--with-libdw-libraries=3D${pkgs.elfutils.out}/lib&quot;=20
        &quot;--enable-dwarf-unwind&quot;
      ];
    buildInputs =3D oldAttrs.buildInputs ++ [pkgs.elfutils];
  });</span><br></div><div><br></div><div>I basically copy/pastaed=C2=A0thi=
s from <a href=3D"https://github.com/input-output-hk/haskell.nix/blob/maste=
r/compiler/ghc/default.nix">https://github.com/input-output-hk/haskell.nix/=
blob/master/compiler/ghc/default.nix</a><br><br>And this seems to work, now=
 when I run `ghc --info` I get:<br><br><span style=3D"color:rgb(29,28,29);f=
ont-family:Monaco,Menlo,Consolas,&quot;Courier New&quot;,monospace;font-siz=
e:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">,(=
&quot;RTS expects libdw&quot;,&quot;YES&quot;)</span><br><br>But despite bu=
ilding with this version of GHC, still when I send `SIGQUIT` to a process b=
uilt with this version of GHC, I just get the message:<br><br><span style=
=3D"color:rgb(28,28,28);font-family:&quot;Noto Sans&quot;,Arial,sans-serif;=
font-size:14px">&quot;This build does not support backtraces.&quot;</span><=
br><br>Now I have also been building my packages with `-g`, passing `--enab=
le-debug-info` etc, although it&#39;s my understanding that what I&#39;ve d=
one 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 debuggi=
ng symbols aren&#39;t added.<br><br>But clearly I&#39;ve missed something i=
f it&#39;s not working. I&#39;m not quite sure what set of circumstances th=
e message=C2=A0<span style=3D"color:rgb(28,28,28);font-family:&quot;Noto Sa=
ns&quot;,Arial,sans-serif;font-size:14px">&quot;This build does not support=
 backtraces&quot;</span>=C2=A0is displayed? Is there a runtime check to see=
 whether the &quot;libdw&quot; library is actually in the library path, in =
addition to the requirement that GHC be built with libdw support? If that&#=
39;s the case, perhaps as I&#39;m running this on NixOS I need to add somet=
hing to my executable&#39;s LD_LIBRARY_PATH or something? Or is there some =
option I need to give GHC/Cabal to ensure that backtrace support is added t=
o the executable&#39;s runtime as well as making sure I&#39;ve compiled wit=
h GHC that&#39;s compiled with libdw support? Or is there some other runtim=
e RTS option I need to give to my executable?<br><br>As you can see, I&#39;=
m completely lost about how to move forward on this, so any help would be v=
ery much appreciated.<br><br>Thanks,<br>Clinton</div></div>

--0000000000009962e60611d991c8--

--===============3061447177062729207==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR2xhc2dvdy1o
YXNrZWxsLXVzZXJzIG1haWxpbmcgbGlzdApHbGFzZ293LWhhc2tlbGwtdXNlcnNAaGFza2VsbC5v
cmcKaHR0cDovL21haWwuaGFza2VsbC5vcmcvY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL2dsYXNn
b3ctaGFza2VsbC11c2Vycwo=

--===============3061447177062729207==--