| Copyright | (c) The University of Glasgow 2011 |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | cvs-ghc@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
GHC.Stack
Description
Access to GHC's call-stack simulation
Since: 4.5.0.0
errorWithStackTrace ::String -> aSource#
currentCallStack ::IO [String]Source#
Returns a[String] representing the current call stack. This can be useful for debugging.
The implementation uses the call-stack simulation maintained 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.
Since: 4.5.0.0
whoCreated :: a ->IO [String]Source#
Get the stack trace attached to an object.
Since: 4.5.0.0
CallStacks are a lightweight method of obtaining a partial call-stack at any point in the program.
A function can request its call-site with theHasCallStack constraint. For example, we can define
putStrLnWithCallStack :: HasCallStack => String -> IO ()
as a variant ofputStrLn that will get its call-site and print it, along with the string given as argument. We can access the call-stack insideputStrLnWithCallStack withcallStack.
putStrLnWithCallStack :: HasCallStack => String -> IO ()putStrLnWithCallStack msg = do putStrLn msg putStrLn (prettyCallStack callStack)
Thus, if we callputStrLnWithCallStack we will get a formatted call-stack alongside our string.
>>>putStrLnWithCallStack "hello"helloCallStack (from HasCallStack): putStrLnWithCallStack, called at <interactive>:2:1 in interactive:Ghci1
GHC solvesHasCallStack constraints in three steps:
CallStack in scope -- i.e. the enclosing function has aHasCallStack constraint -- GHC will append the new call-site to the existingCallStack.CallStack in scope -- e.g. in the GHCi session above -- and the enclosing definition does not have an explicit type signature, GHC will infer aHasCallStack constraint for the enclosing definition (subject to the monomorphism restriction).CallStack in scope and the enclosing definition has an explicit type signature, GHC will solve theHasCallStack constraint for the singletonCallStack containing just the current call-site.CallStacks do not interact with the RTS and do not require compilation with-prof. On the other hand, as they are built up explicitly via theHasCallStack constraints, they will generally not contain as much information as the simulated call-stacks maintained by the RTS.
ACallStack is a[(String, SrcLoc)]. TheString is the name of function that was called, theSrcLoc is the call-site. The list is ordered with the most recently called function at the head.
NOTE: The intrepid user may notice thatHasCallStack is just an alias for an implicit parameter?callStack :: CallStack. This is an implementation detail andshould not be considered part of theCallStack API, we may decide to change the implementation in the future.
Since: 4.8.1.0
typeHasCallStack = ?callStack ::CallStackSource#
Request a CallStack.
NOTE: The implicit parameter?callStack :: CallStack is an implementation detail andshould not be considered part of theCallStack API, we may decide to change the implementation in the future.
Since: 4.9.0.0
emptyCallStack ::CallStackSource#
The emptyCallStack.
Since: 4.9.0.0
freezeCallStack ::CallStack ->CallStackSource#
Freeze a call-stack, preventing any further call-sites from being appended.
pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack
Since: 4.9.0.0
fromCallSiteList :: [([Char],SrcLoc)] ->CallStackSource#
Convert a list of call-sites to aCallStack.
Since: 4.9.0.0
getCallStack ::CallStack -> [([Char],SrcLoc)]Source#
Extract a list of call-sites from theCallStack.
The list is ordered by most recent call.
Since: 4.8.1.0
popCallStack ::CallStack ->CallStackSource#
Pop the most recent call-site off theCallStack.
This function, likepushCallStack, has no effect on a frozenCallStack.
Since: 4.9.0.0
withFrozenCallStack ::HasCallStack => (HasCallStack => a) -> aSource#
Perform some computation without adding new entries to theCallStack.
Since: 4.9.0.0
A single location in the source code.
Since: 4.8.1.0
Constructors
| SrcLoc | |
Fields
| |
A cost-centre stack from GHC's cost-center profiler.
A cost-centre from GHC's cost-center profiler.
getCurrentCCS :: dummy ->IO (PtrCostCentreStack)Source#
Returns the currentCostCentreStack (value isnullPtr if the current program was not compiled with profiling support). Takes a dummy argument which can be used to avoid the call togetCurrentCCS being floated out by the simplifier, which would result in an uninformative stack (CAF).
getCCSOf :: a ->IO (PtrCostCentreStack)Source#
Get theCostCentreStack associated with the given value.
Run a computation with an empty cost-center stack. For example, this is used by the interpreter to run an interpreted computation without the call stack showing that it was invoked from GHC.
ccsCC ::PtrCostCentreStack ->IO (PtrCostCentre)Source#
Get theCostCentre at the head of aCostCentreStack.
ccsParent ::PtrCostCentreStack ->IO (PtrCostCentreStack)Source#
Get the tail of aCostCentreStack.
ccLabel ::PtrCostCentre ->IOCStringSource#
Get the label of aCostCentre.
ccModule ::PtrCostCentre ->IOCStringSource#
Get the module of aCostCentre.
ccSrcSpan ::PtrCostCentre ->IOCStringSource#
Get the source span of aCostCentre.
ccsToStrings ::PtrCostCentreStack ->IO [String]Source#
Format aCostCentreStack as a list of lines.
renderStack :: [String] ->StringSource#
Produced byHaddock version 2.20.0