RE: [Haskell] modern language design, stone age tools
On 23 June 2004 18:39, Fergus Henderson wrote:
On 23-Jun-2004, MR K P SCHUPKE <k.schupke@imperial.ac.uk> wrote:
This may not be the right answer to the question (which is of course lets write a debugger) - But I have never used a debugger, and find them more or less the most unfriendly and useless things
So how do you debug problems like "Prelude.head: empty list" in large programs?
The two most useful techniques, both have which have already been suggested by others are: 1. Compile with -prof -auto-all and run with +RTS -xc. 2. Use the mapException trick to annotate exceptions as they travel up the stack (see Alastair Reid's message). (1) doesn't work that well, as you noticed. For example, sometimes the exception will stop at a CAF, due to the way cost centres work in GHC. I'd really like us to do better here - keeping track of the call stack in a lazy higher-order language has turned out to be surprisingly tricky. (2) requires that you add lots of annotations to your code, so it's not entirely satisfactory for that reason. Even if we had an interactive debugger, getting a good call stack is still going to be a hard problem. Cheers, Simon
[...] 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' [] = .. -- Alastair
participants (2)
-
Alastair Reid -
Simon Marlow