summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2006-01-10 23:17:22 +0000
committerJamey Sharp <jamey@minilop.net>2006-01-10 23:17:22 +0000
commit3b7addfe9affc89012c21693fb548ff02b674536 (patch)
treed091eb6c454f7af99fe0290195480df561e6091a
parente4f4b315ae1b9df829f60fd2758ebb7eee34a3a5 (diff)
Add tracing so we can see what order lazy evaluation plus monad sequencing
is selecting.
-rw-r--r--xhsb/XCBExt.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/xhsb/XCBExt.hs b/xhsb/XCBExt.hs
index 3d4c3ee..b61f4d7 100644
--- a/xhsb/XCBExt.hs
+++ b/xhsb/XCBExt.hs
@@ -9,6 +9,9 @@ import Foreign
import Control.Monad.Reader
import Control.Monad.State
import Data.Generics
+import Debug.Trace
+
+trace' s = trace $ " * " ++ s
type ReplyReader a = StateT Int (ReaderT (ForeignPtr Word32) IO) a
@@ -17,8 +20,8 @@ readSize size = do
last <- get
let cur = (last + size - 1) .&. (-size)
put $ cur + size
- p <- ask
- liftIO $ liftIO $ unsafeInterleaveIO $ withForeignPtr p $ \p'-> peek $ plusPtr p' cur
+ p <- return . trace' "read pointer" =<< ask
+ liftIO $ liftIO $ unsafeInterleaveIO $ withForeignPtr p $ \p'-> trace' "peek" $ peek $ plusPtr p' cur
retTypeM :: Monad m => m a -> a
retTypeM _ = undefined
@@ -46,9 +49,9 @@ readReply = ret
foreign import ccall "X11/XCB/xcbext.h XCBWaitForReply" _waitForReply :: Ptr XCBConnection -> Word32 -> Ptr (Ptr XCBGenericError) -> IO (Ptr Word32)
-request = throwIf (== 0) (const "couldn't send request")
+request = return . trace' "sent request" =<< throwIf (== 0) (const "couldn't send request")
requestWithReply :: Data reply => Ptr XCBConnection -> IO Word32 -> IO reply
requestWithReply c req = do
cookie <- request req
- unsafeInterleaveIO $ throwIfNull "couldn't get reply" (_waitForReply c cookie nullPtr) >>= newForeignPtr finalizerFree >>= runReaderT readReply
+ unsafeInterleaveIO $ trace' "got reply" $ throwIfNull "couldn't get reply" (_waitForReply c cookie nullPtr) >>= newForeignPtr finalizerFree >>= runReaderT readReply