Commit 80d7ce80 authored by Bartosz Nitka's avatar Bartosz Nitka Committed by Ben Gamari

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
parent 932d5036
{-# LANGUAGE CPP, ImplicitParams #-}
{- {-
(c) The University of Glasgow 2006-2012 (c) The University of Glasgow 2006-2012
(c) The GRASP Project, Glasgow University, 1992-1998 (c) The GRASP Project, Glasgow University, 1992-1998
...@@ -73,7 +74,7 @@ module Outputable ( ...@@ -73,7 +74,7 @@ module Outputable (
-- * Error handling and debugging utilities -- * Error handling and debugging utilities
pprPanic, pprSorry, assertPprPanic, pprPgmError, pprPanic, pprSorry, assertPprPanic, pprPgmError,
pprTrace, warnPprTrace, pprTrace, warnPprTrace, pprSTrace,
trace, pgmError, panic, sorry, assertPanic, trace, pgmError, panic, sorry, assertPanic,
pprDebugAndThen, pprDebugAndThen,
) where ) where
...@@ -109,6 +110,8 @@ import Data.Graph (SCC(..)) ...@@ -109,6 +110,8 @@ import Data.Graph (SCC(..))
import GHC.Fingerprint import GHC.Fingerprint
import GHC.Show ( showMultiLineString ) import GHC.Show ( showMultiLineString )
import GHC.Stack
import GHC.Exception
{- {-
************************************************************************ ************************************************************************
...@@ -1030,6 +1033,17 @@ pprTrace str doc x ...@@ -1030,6 +1033,17 @@ pprTrace str doc x
| opt_NoDebugOutput = x | opt_NoDebugOutput = x
| otherwise = pprDebugAndThen unsafeGlobalDynFlags trace (text str) doc 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 warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> a
-- ^ Just warn about an assertion failure, recording the given file and line number. -- ^ Just warn about an assertion failure, recording the given file and line number.
-- Should typically be accessed with the WARN macros -- Should typically be accessed with the WARN macros
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment