Can GHCi inspect the state of running threads?
facundo.dominguez at tweag.io
Wed May 20 15:51:08 UTC 2015
I have a multi-threaded and interactive application that sometimes
stops responding, and it would be helpful being able to inspect the
state when it doesn't.
I thought the GHCi debugger could be useful here, however I see no way
to signal a thread and have GHCi show me its state.
Here is an example GHCi session:
$ cat t.hs
spawnThread :: String -> IO ThreadId
spawnThread label =
forkIO $ flip finally (putStrLn $ "bye " ++ label) $
forM_ [0..] $ \i -> threadDelay 1000000
$ ghci-7.10.1 t.hs -fbreak-on-exception -v0
*Main> hSetBuffering stdout LineBuffering
*Main> t0 <- spawnThread "t0"
*Main> throwTo t0 (ErrorCall "end")
It looks like I'm not getting the "bye t0" message when stopping the
thread while using -fbreak-on-exception.
Is the debugger supposed to be used like this? Otherwise, is there any
way in which I could inspect the state of a running thread?
More information about the Glasgow-haskell-users