Can GHCi inspect the state of running threads?

Facundo Domínguez facundo.dominguez at tweag.io
Wed May 20 16:52:27 UTC 2015


Perhaps a more sensible example:

$ cat t.hs
import Control.Concurrent
import Control.Monad

spawnThread :: IO ThreadId
spawnThread =
    forkIO $
      forM_ [0..] $ \i ->
        threadDelay 1000000
$ ghci-7.10.1 t.hs -v0
*Main> t0 <- spawnThread
*Main> :break 8
Breakpoint 0 activated at t.hs:8:9-27
*Main> *** Ignoring breakpoint
*** Ignoring breakpoint
*** Ignoring breakpoint
*** Ignoring breakpoint
:q
$

Thanks,
Facundo

On Wed, May 20, 2015 at 12:51 PM, Facundo Domínguez
<facundo.dominguez at tweag.io> wrote:
> Hello,
>    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
> import Control.Concurrent
> import Control.Exception
> import Control.Monad
> import System.IO
>
> 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")
> *Main>
>
> 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?
>
> Thanks,
> Facundo


More information about the Glasgow-haskell-users mailing list