How to work out why a data constructor is allocated using gdb?

Matthew Pickering matthewtpickering at gmail.com
Tue Aug 13 07:29:54 UTC 2019


Hi,

I am trying to work out questions such as

* Why are there thousands of Module data constructors allocated when
building something with GHC
* What is allocating all a lot of strings when building GHC?

In order to do this I can use gdb in order to find some of the
Module/String closures but then I'm a bit stuck about what to do.

gdb displays a list of all the Module closures for example and then
you can usually try to find the retainer for Module by using findPtr.

If the retainer is a THUNK closure, it would be easy, as THUNK
closures have DWARF information which maps straight to a particular
line. However if the retainer is just some other
data constructor, for example, the Module is stored in a Map, it's
data constructors all the way up and none of them have DWARF info. I
need to fall back to domain specific knowledge
to work out where such a sequence of constructors might appear in my program.

* Is there anything better I can do to map a constructor allocation to
a more precise source location?

The string closures were causing me some particular issues as
`findPtr` was not showing any retainers so it's hard to work out why
they are not GCd.

* What situations can an object be retained but show no retainer when
using findPtr?

Cheers,

Matt


More information about the ghc-devs mailing list