summaryrefslogtreecommitdiff
path: root/compiler/utils/Outputable.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2017-10-19 13:25:51 -0400
committerBen Gamari <ben@smart-cactus.org>2017-10-19 16:43:24 -0400
commitafc04b2689e5b936ecc8689c194a0ed2c0a2e6da (patch)
tree5a7406b1a01ee898f22a7e498d471e3bde391b6d /compiler/utils/Outputable.hs
parent2ca8cf69c50f6fcae17fdcbbcad16227519e5d02 (diff)
downloadhaskell-afc04b2689e5b936ecc8689c194a0ed2c0a2e6da.tar.gz
Outputable: Add pprTraceException
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r--compiler/utils/Outputable.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs
index c79cbc5551..95960f59b0 100644
--- a/compiler/utils/Outputable.hs
+++ b/compiler/utils/Outputable.hs
@@ -81,8 +81,9 @@ module Outputable (
-- * Error handling and debugging utilities
pprPanic, pprSorry, assertPprPanic, pprPgmError,
pprTrace, pprTraceDebug, pprTraceIt, warnPprTrace, pprSTrace,
+ pprTraceException,
trace, pgmError, panic, sorry, assertPanic,
- pprDebugAndThen, callStackDoc
+ pprDebugAndThen, callStackDoc,
) where
import GhcPrelude
@@ -126,6 +127,8 @@ import Data.List (intersperse)
import GHC.Fingerprint
import GHC.Show ( showMultiLineString )
import GHC.Stack ( callStack, prettyCallStack )
+import Control.Monad.IO.Class
+import Exception
{-
************************************************************************
@@ -1168,6 +1171,13 @@ pprTrace str doc x
pprTraceIt :: Outputable a => String -> a -> a
pprTraceIt desc x = pprTrace desc (ppr x) x
+-- | @pprTraceException desc x action@ runs action, printing a message
+-- if it throws an exception.
+pprTraceException :: ExceptionMonad m => String -> SDoc -> m a -> m a
+pprTraceException heading doc =
+ handleGhcException $ \exc -> liftIO $ do
+ putStrLn $ showSDocDump unsafeGlobalDynFlags (sep [text heading, nest 2 doc])
+ throwGhcExceptionIO exc
-- | If debug output is on, show some 'SDoc' on the screen along
-- with a call stack when available.