[project @ 2001-06-28 14:15:04 by simonmar]
[packages/old-time.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/core/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
10 --
11 -- $Id: Trace.hs,v 1.1 2001/06/28 14:15:02 simonmar Exp $
12 --
13 -- The trace function.
14 --
15 -----------------------------------------------------------------------------
16
17 module Debug.Trace (
18 trace -- :: String -> a -> a
19 ) where
20
21 import Prelude
22 import System.IO.Unsafe
23 import System.IO
24
25 #ifdef __GLASGOW_HASKELL__
26 import GHC.IOBase
27 import GHC.Handle
28 #endif
29
30 #ifdef __GLASGOW_HASKELL__
31 {-# NOINLINE trace #-}
32 trace :: String -> a -> a
33 trace string expr = unsafePerformIO $ do
34 hPutStr stderr string
35 hPutChar stderr '\n'
36 fd <- withHandle_ "trace" stderr $ (return.haFD)
37 postTraceHook fd
38 return expr
39
40 foreign import "PostTraceHook" postTraceHook :: Int -> IO ()
41 #endif