diff options
author | Bartosz Nitka <bnitka@fb.com> | 2015-11-08 00:21:11 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-11-08 00:54:05 +0100 |
commit | 80d7ce8038a100f6797a89755c893c6f67f18a30 (patch) | |
tree | 918e5d0f9214d17d64dd2ca804c9a364e6de2350 /compiler/utils/Outputable.hs | |
parent | 932d50364912087e2051505290acde7a16532b4d (diff) | |
download | haskell-80d7ce8038a100f6797a89755c893c6f67f18a30.tar.gz |
Add pprSTrace for debugging with call stacks
I've spent quite a bit of time giving unique labels to my `pprTrace`
calls and then trying to intuit where the function is called from.
Thanks to the new implicit parameter CallStack functionality I don't
have to do that anymore.
Test Plan: harbormaster
Reviewers: austin, simonmar, bgamari
Reviewed By: simonmar, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1440
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r-- | compiler/utils/Outputable.hs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index 23fa37d77a..c74f738706 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP, ImplicitParams #-} {- (c) The University of Glasgow 2006-2012 (c) The GRASP Project, Glasgow University, 1992-1998 @@ -73,7 +74,7 @@ module Outputable ( -- * Error handling and debugging utilities pprPanic, pprSorry, assertPprPanic, pprPgmError, - pprTrace, warnPprTrace, + pprTrace, warnPprTrace, pprSTrace, trace, pgmError, panic, sorry, assertPanic, pprDebugAndThen, ) where @@ -109,6 +110,8 @@ import Data.Graph (SCC(..)) import GHC.Fingerprint import GHC.Show ( showMultiLineString ) +import GHC.Stack +import GHC.Exception {- ************************************************************************ @@ -1030,6 +1033,17 @@ pprTrace str doc x | opt_NoDebugOutput = x | otherwise = pprDebugAndThen unsafeGlobalDynFlags trace (text str) doc x + +-- | If debug output is on, show some 'SDoc' on the screen along +-- with a call stack when available. +#if __GLASGOW_HASKELL__ >= 710 +pprSTrace :: (?location :: CallStack) => SDoc -> a -> a +pprSTrace = pprTrace (showCallStack ?location) +#else +pprSTrace :: SDoc -> a -> a +pprSTrace = pprTrace "no callstack info" +#endif + warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> a -- ^ Just warn about an assertion failure, recording the given file and line number. -- Should typically be accessed with the WARN macros |