[commit: ghc] master: Add pprSTrace for debugging with call stacks (80d7ce8)

git at git.haskell.org git at git.haskell.org
Sat Nov 7 23:54:21 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/80d7ce8038a100f6797a89755c893c6f67f18a30/ghc

>---------------------------------------------------------------

commit 80d7ce8038a100f6797a89755c893c6f67f18a30
Author: Bartosz Nitka <bnitka at fb.com>
Date:   Sun Nov 8 00:21:11 2015 +0100

    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


>---------------------------------------------------------------

80d7ce8038a100f6797a89755c893c6f67f18a30
 compiler/utils/Outputable.hs | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs
index 23fa37d..c74f738 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



More information about the ghc-commits mailing list