X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Debug%2FTrace.hs;h=ebacb6c3d7fa28d37e385a2d240c97b2bd4d8d78;hb=f98950484a7cb01e43352e3d88277a2784cd58bf;hp=3e369f5e183c12f728ba0b1534276f33a0325310;hpb=66bcbe67b61d83cb01b6d2c876e7b06e034fba88;p=ghc-base.git diff --git a/Debug/Trace.hs b/Debug/Trace.hs index 3e369f5..ebacb6c 100644 --- a/Debug/Trace.hs +++ b/Debug/Trace.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP, ForeignFunctionInterface #-} + ----------------------------------------------------------------------------- -- | -- Module : Debug.Trace @@ -13,9 +15,10 @@ ----------------------------------------------------------------------------- module Debug.Trace ( - -- * Tracing - putTraceMsg, -- :: String -> IO () - trace -- :: String -> a -> a + -- * Tracing + putTraceMsg, -- :: String -> IO () + trace, -- :: String -> a -> a + traceShow ) where import Prelude @@ -28,7 +31,7 @@ import System.IO (hPutStrLn,stderr) #endif -- | 'putTraceMsg' function outputs the trace message from IO monad. --- Usually the output stream is 'stderr' but if the function is called +-- Usually the output stream is 'System.IO.stderr' but if the function is called -- from Windows GUI application then the output will be directed to the Windows -- debug console. putTraceMsg :: String -> IO () @@ -40,7 +43,10 @@ putTraceMsg msg = do withCString msg $ \cmsg -> debugBelch cfmt cmsg -foreign import ccall unsafe debugBelch :: CString -> CString -> IO () +-- don't use debugBelch() directly, because we cannot call varargs functions +-- using the FFI. +foreign import ccall unsafe "HsBase.h debugBelch2" + debugBelch :: CString -> CString -> IO () #endif {-# NOINLINE trace #-} @@ -56,3 +62,11 @@ trace :: String -> a -> a trace string expr = unsafePerformIO $ do putTraceMsg string return expr + +{-| +Like 'trace', but uses 'show' on the argument to convert it to a 'String'. + +> traceShow = trace . show +-} +traceShow :: (Show a) => a -> b -> b +traceShow = trace . show