[project @ 2002-05-09 13:16:29 by simonmar]
[packages/base.git] / Debug / Trace.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : Debug.Trace
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
10 --
11 -- The trace function.
12 --
13 -----------------------------------------------------------------------------
14
15 module Debug.Trace (
16 trace -- :: String -> a -> a
17 ) where
18
19 import Prelude
20 import System.IO.Unsafe
21 import System.IO
22
23 #ifdef __GLASGOW_HASKELL__
24 import GHC.IOBase
25 import GHC.Handle
26 #endif
27
28 #ifdef __GLASGOW_HASKELL__
29 {-# NOINLINE trace #-}
30 trace :: String -> a -> a
31 trace string expr = unsafePerformIO $ do
32 hPutStr stderr string
33 hPutChar stderr '\n'
34 fd <- withHandle_ "trace" stderr $ (return.haFD)
35 postTraceHook fd
36 return expr
37
38 foreign import ccall "PostTraceHook" postTraceHook :: Int -> IO ()
39 #endif