summaryrefslogtreecommitdiff
path: root/src/GDB.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GDB.hs')
-rw-r--r--src/GDB.hs36
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 ()