diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-04-30 08:37:45 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-04-30 08:37:45 +0200 |
commit | cd43896891dc7c6779af0f1d2d8f3f045edc162a (patch) | |
tree | ea930aa99205b045141e8812dd0974c99d8394c4 /src/GDB.hs | |
parent | cb5677c3d4f5fed1cc0f6cf50236281e1d75838e (diff) |
Separate GDB support module
Diffstat (limited to 'src/GDB.hs')
-rw-r--r-- | src/GDB.hs | 36 |
1 files changed, 36 insertions, 0 deletions
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 () |