Stack trace
General usage
Recent versions of GHC allow a dump of a stack trace (of all cost centres) when an exception is raised. In order to enable this, compile with -prof , and run with +RTS -xc . (Since only the cost centre stack will be printed, you may want to add -fprof-auto -fprof-cafs [1] to the compilation step to include all definitions in the trace.) Since GHC version 7.8, the function errorWithStackTrace can be used to programmatically dump the stack trace, see How to get (approx) stack traces with profiled builds.
A more detailed list of options can be found in the RTS section of the GHC user's guide.
Example
-- test.hs crash = sum [1,2,3,undefined,5,6,7,8] main = print crash
> ghc-7.6.3 test.hs -prof -fprof-auto -fprof-cafs && ./test +RTS -xc *** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: GHC.Err.CAF --> evaluated by: Main.crash, called from Main.CAF:crash_reH test: Prelude.undefined
... continue reading