X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Debug%2FTrace.hs;h=742044e4d4c3e1eef013234f23d92500c260a852;hb=8aca076f0de902842f6c5df7322ba42d4664fce4;hp=3e369f5e183c12f728ba0b1534276f33a0325310;hpb=66bcbe67b61d83cb01b6d2c876e7b06e034fba88;p=ghc-base.git diff --git a/Debug/Trace.hs b/Debug/Trace.hs index 3e369f5..742044e 100644 --- a/Debug/Trace.hs +++ b/Debug/Trace.hs @@ -13,9 +13,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 +29,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 +41,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 +60,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