[Haskell-cafe] Closure trace?

Esa Ilari Vuokko eivuokko at gmail.com
Wed Jun 14 08:00:25 EDT 2006


Hi Michael,

On 6/14/06, Michael Marte <marte at pms.informatik.uni-muenchen.de> wrote:
> I wonder whether it is possible to print a "closure trace" similar to a
> stack trace in procedural programming. Say we have two modules A and B:

I wrote small (external) utility that does something like that for
ghc-built binaries.
It can print traces on user defined breakpoints.  As there isn't much
use for it,
I haven't played with a while, but it might help or provide starting point.

darcs get http://tamelambda.net/darcs/tracer/
(requires ghc 6.4.2 and Windows to compile and use)

Example output for tracing "lines", of a program something like this:
getContents >>= mapM_ putStrLn . lines

Trace:  Data.List.lines                +   0 <CtFUN_STATIC>
 stg_upd_frame                  +   0 <CtUPDATE_FRAME>
 GHC.Base.map                   + 108 <CtRET_VEC_SMALL>
 stg_upd_frame                  +   0 <CtUPDATE_FRAME>
 GHC.Base.foldr                 +  76 <CtRET_VEC_SMALL>
 stg_upd_frame                  +   0 <CtUPDATE_FRAME>
 stg_ap_v                       +   0 <CtRET_SMALL>
 GHC.IOBase.bindIO              +  46 <CtRET_SMALL>
 GHC.TopHandler.runMainIO       + 126 <CtRET_SMALL>
 stg_catch_frame                +   0 <CtCATCH_FRAME>
 stg_noforceIO                  +   0 <CtRET_SMALL>
 stg_stop_thread                +   0 <CtSTOP_FRAME>

The output isn't too pretty, but it is often possible to see where calls to,
say error occur.  Unfortunately (for tracing) ghc aggressively inlines (and
libraries have RULES-pragmas) functions.  That causes traces to have
big "holes" in them.

Best regards,
--Esa


More information about the Haskell-Cafe mailing list