|Copyright||(c) The University of Glasgow 2011|
|Portability||non-portable (GHC Extensions)|
Access to GHC's call-stack simulation
returns a '[String]' representing the current call stack. This can be useful for debugging.
The implementation uses the call-stack simulation maintined by the profiler, so it only works if the program was compiled with
-prof and contains suitable SCC annotations (e.g. by using
-fprof-auto). Otherwise, the list returned is likely to be empty or uninformative.
Get the stack trace attached to an object.
Like the function
error, but appends a stack trace to the error message if one is available.
CallStacks are an alternate method of obtaining the call stack at a given point in the program.
When an implicit-parameter of type
CallStack occurs in a program, GHC will solve it with the current location. If another
CallStack implicit-parameter is in-scope (e.g. as a function argument), the new location will be appended to the one in-scope, creating an explicit call-stack. For example,
myerror :: (?loc :: CallStack) => String -> a myerror msg = error (msg ++ "n" ++ showCallStack ?loc)
ghci> myerror "die" *** Exception: die ?loc, called at MyError.hs:7:51 in main:MyError myerror, called at interactive:2:1 in interactive:Ghci1
CallStacks do not interact with the RTS and do not require compilation with
-prof. On the other hand, as they are built up explicitly using implicit-parameters, they will generally not contain as much information as the simulated call-stacks maintained by the RTS.
CallStack type is abstract, but it can be converted into a
[(String, SrcLoc)] via
String is the name of function that was called, the
SrcLoc is the call-site. The list is ordered with the most recently called function at the head.
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).