From 359607468fac0ed11bfc1a3579c69fe4310419cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 4 May 2022 20:50:06 +0200 Subject: Test run monad --- src/GDB.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/GDB.hs') diff --git a/src/GDB.hs b/src/GDB.hs index 40a4e8f..76c33c1 100644 --- a/src/GDB.hs +++ b/src/GDB.hs @@ -4,6 +4,8 @@ module GDB ( gdbSession, ) where +import Control.Monad.IO.Class + import Data.Text qualified as T import Data.Text.IO qualified as T @@ -15,20 +17,20 @@ import Process gdbCmd :: String gdbCmd = "gdb --quiet --interpreter=mi3" -gdbInit :: Process -> IO () +gdbInit :: MonadIO m => Process -> m () gdbInit gdb = do send gdb $ T.pack "-gdb-set schedule-multiple on" send gdb $ T.pack "-gdb-set mi-async on" send gdb $ T.pack "-gdb-set print symbol-loading off" -addInferior :: Process -> Int -> Pid -> IO () +addInferior :: MonadIO m => Process -> Int -> Pid -> m () addInferior gdb i pid = do send gdb $ T.pack $ "-add-inferior" send gdb $ T.pack $ "-target-attach --thread-group i" ++ show i ++ " " ++ show pid send gdb $ T.pack $ "-exec-continue --thread-group i" ++ show i -gdbSession :: Process -> IO () -gdbSession gdb = do +gdbSession :: MonadIO m => Process -> m () +gdbSession gdb = liftIO $ do catchIOError (Just <$> T.getLine) (\e -> if isEOFError e then return Nothing else ioError e) >>= \case Just line -> do send gdb (T.pack "-interpreter-exec console \"" `T.append` line `T.append` T.pack "\"") -- cgit v1.2.3