RE: [Haskell-cafe] Exceptions

Actually GHC does exactly that when you compile with -prof -auto-all. Then if you run with +RTS -xc, you get a backtrace of sorts. (I have not tested this recently!) The backtrace is not yet reified into a data structure that can be examined, but that'd be quite doable if someone wanted to try. The downside is that -prof makes many optimisations work less well, and all modules must be compiled this way. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of MR | K P SCHUPKE | Sent: 01 October 2004 18:29 | To: alastair@reid-consulting-uk.ltd.uk; haskell-cafe@haskell.org | Cc: k.schupke@imperial.ac.uk; jgoerzen@complete.org | Subject: Re: [Haskell-cafe] Exceptions | | >But, being able to see the context in which a thunk was constructed would be | >extremely useful. | | Yes of course... I was thinking along the lines of what is possible, rather | than what is desirable. If only ghc had a -g (debug) flag like gcc that would | force each funtion to push its entry onto some kind of call stack that would | be returned by exceptions... | | Keean. | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Oct 04, 2004 at 09:30:22AM +0100, Simon Peyton-Jones wrote:
Actually GHC does exactly that when you compile with -prof -auto-all. Then if you run with +RTS -xc, you get a backtrace of sorts. (I have not tested this recently!) The backtrace is not yet reified into a data structure that can be examined, but that'd be quite doable if someone wanted to try.
A major problem with this that I notice is that it dumps the stack whenever any exception is raised, which is a big pain if your program does IO and regularly raises and catches exceptions as part of normal operation. A big improvement would be to only dump the backtrace if the exception was uncaught and caused the program to abort. John -- John Meacham - ⑆repetae.net⑆john⑈

[+RTS -xc]
A major problem with this that I notice is that it dumps the stack whenever any exception is raised, which is a big pain if your program does IO and regularly raises and catches exceptions as part of normal operation. A big improvement would be to only dump the backtrace if the exception was uncaught and caused the program to abort.
Agreed. I wrote the -RTS +xc code several years ago, and thought that what you describe would be much nicer. But this would have involved quite a bit more hacking of the RTS. At the point the exception is thrown, the backtrace is just sitting there waiting to be dumped. But once it's thrown this information is lost. I imagined wrapping up the backtrace information into a data structure and including that as an argument to the exception, so that the primitive catch operation would receive a backtrace in addition to the exception itself; then the backtrace could be dumped to stderr or whatever by the default toplevel handler. In the end I didn't have the motivation to implement this, and I don't have the same contact with the GHC codebase any more. I'd be happy to help anyone who wanted to add this, though, or for someone just to go ahead and do it... --KW 8-)
participants (3)
-
John Meacham
-
Keith Wansbrough
-
Simon Peyton-Jones