Movatterモバイル変換
[0]ホーム
{-# OPTIONS_GHC -optc-DPROFILING #-}{-# LINE1"GHC/Stack/CCS.hsc"#-}{-# LANGUAGE Trustworthy #-}------------------------------------------------------------------------------- |-- Module : GHC.Stack.CCS-- Copyright : (c) The University of Glasgow 2011-- License : see libraries/base/LICENSE---- Maintainer : cvs-ghc@haskell.org-- Stability : internal-- Portability : non-portable (GHC Extensions)---- Access to GHC's call-stack simulation---- @since 4.5.0.0-----------------------------------------------------------------------------{-# LANGUAGE UnboxedTuples, MagicHash, NoImplicitPrelude #-}moduleGHC.Stack.CCS(-- * Call stackscurrentCallStack,whoCreated,-- * InternalsCostCentreStack,CostCentre,getCurrentCCS,getCCSOf,clearCCS,ccsCC,ccsParent,ccLabel,ccModule,ccSrcSpan,ccsToStrings,renderStack)whereimportForeignimportForeign.CimportGHC.BaseimportGHC.PtrimportGHC.ForeignasGHCimportGHC.IO.EncodingimportGHC.List(concatMap,reverse)-- | A cost-centre stack from GHC's cost-center profiler.dataCostCentreStack-- | A cost-centre from GHC's cost-center profiler.dataCostCentre-- | Returns the current 'CostCentreStack' (value is @nullPtr@ if the current-- program was not compiled with profiling support). Takes a dummy argument-- which can be used to avoid the call to @getCurrentCCS@ being floated out by-- the simplifier, which would result in an uninformative stack ("CAF").getCurrentCCS::dummy->IO(PtrCostCentreStack)getCurrentCCSdummy=IO$\s->casegetCurrentCCS#dummysof(#s',addr#)->(#s',Ptraddr#)-- | Get the 'CostCentreStack' associated with the given value.getCCSOf::a->IO(PtrCostCentreStack)getCCSOfobj=IO$\s->casegetCCSOf#objsof(#s',addr#)->(#s',Ptraddr#)-- | 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.clearCCS::IOa->IOaclearCCS(IOm)=IO$\s->clearCCS#ms-- | Get the 'CostCentre' at the head of a 'CostCentreStack'.ccsCC::PtrCostCentreStack->IO(PtrCostCentre)ccsCCp=((\hsc_ptr->peekByteOffhsc_ptr8))p{-# LINE81"GHC/Stack/CCS.hsc"#-}-- | Get the tail of a 'CostCentreStack'.ccsParent::PtrCostCentreStack->IO(PtrCostCentreStack)ccsParentp=((\hsc_ptr->peekByteOffhsc_ptr16))p{-# LINE85"GHC/Stack/CCS.hsc"#-}-- | Get the label of a 'CostCentre'.ccLabel::PtrCostCentre->IOCStringccLabelp=((\hsc_ptr->peekByteOffhsc_ptr8))p{-# LINE89"GHC/Stack/CCS.hsc"#-}-- | Get the module of a 'CostCentre'.ccModule::PtrCostCentre->IOCStringccModulep=((\hsc_ptr->peekByteOffhsc_ptr16))p{-# LINE93"GHC/Stack/CCS.hsc"#-}-- | Get the source span of a 'CostCentre'.ccSrcSpan::PtrCostCentre->IOCStringccSrcSpanp=((\hsc_ptr->peekByteOffhsc_ptr24))p{-# LINE97"GHC/Stack/CCS.hsc"#-}-- | 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.0currentCallStack::IO[String]currentCallStack=ccsToStrings=<<getCurrentCCS()-- | Format a 'CostCentreStack' as a list of lines.ccsToStrings::PtrCostCentreStack->IO[String]ccsToStringsccs0=goccs0[]wheregoccsacc|ccs==nullPtr=returnacc|otherwise=docc<-ccsCCccslbl<-GHC.peekCStringutf8=<<ccLabelccmdl<-GHC.peekCStringutf8=<<ccModuleccloc<-GHC.peekCStringutf8=<<ccSrcSpanccparent<-ccsParentccsif(mdl=="MAIN"&&lbl=="MAIN")thenreturnaccelsegoparent((mdl++'.':lbl++' ':'(':loc++")"):acc)-- | Get the stack trace attached to an object.---- @since 4.5.0.0whoCreated::a->IO[String]whoCreatedobj=doccs<-getCCSOfobjccsToStringsccsrenderStack::[String]->StringrenderStackstrs="CallStack (from -prof):"++concatMap("\n "++)(reversestrs)
[8]ページ先頭