From cd43896891dc7c6779af0f1d2d8f3f045edc162a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 30 Apr 2022 08:37:45 +0200 Subject: Separate GDB support module --- src/GDB.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/GDB.hs (limited to 'src/GDB.hs') diff --git a/src/GDB.hs b/src/GDB.hs new file mode 100644 index 0000000..40a4e8f --- /dev/null +++ b/src/GDB.hs @@ -0,0 +1,36 @@ +module GDB ( + gdbCmd, gdbInit, + addInferior, + gdbSession, +) where + +import Data.Text qualified as T +import Data.Text.IO qualified as T + +import System.IO.Error +import System.Process + +import Process + +gdbCmd :: String +gdbCmd = "gdb --quiet --interpreter=mi3" + +gdbInit :: Process -> IO () +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 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 + 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 "\"") + gdbSession gdb + Nothing -> return () -- cgit v1.2.3