[Haskell] modern language design, stone age tools
simonmar at microsoft.com
Thu Jun 24 05:50:29 EDT 2004
On 24 June 2004 10:31, Alastair Reid wrote:
>> 2. Use the mapException trick to annotate exceptions as they
>> travel up the stack (see Alastair Reid's message). [...]
>> (2) requires that you add lots of annotations to your code, so it's
>> not entirely satisfactory for that reason.
> Would it be possible to generalise ghc's -prof-all mechanism so that
> annotations could be added automatically. For example, suppose I have
> an annotation function
> Debug.Callstack.callstack :: ModuleName -> LineNumber -> a -> a
> Then, if I compile with:
> ghc -annotate=Debug.Callstack.callstack Foo.hs
> then ghc could add
> import Debug.Callstack(callstack)
> to the import list and transform every top level function body
> as follows:
> foo (x:xs) = ..
> foo  = ...
> foo arg = callstack
> "Foo" -- module name
> 42 -- line number
> (foo' arg)
> foo' (x:xs) = ..
> foo'  = ..
Yes, this could be done. I should have mentioned though: this technique
gives you the lazy call stack, whereas what you probably want is the
strict call stack (which is what GHC's profiler tries to give you).
Getting the lazy call stack is easy from a debugger, we don't need to
annotate the program to do that, but we might want to add source
locations in the form of debug info to the object file in a similar way
to C compilers.
It may be that giving programmers access to the lazy call stack is a
heck of a lot better than nothing.
More information about the Haskell