浏览代码

LibDebug: Add ability to detach from debuggee

Itamar 4 年之前
父节点
当前提交
8ce641cefc
共有 2 个文件被更改,包括 17 次插入2 次删除
  1. 8 0
      Libraries/LibDebug/DebugSession.cpp
  2. 9 2
      Libraries/LibDebug/DebugSession.h

+ 8 - 0
Libraries/LibDebug/DebugSession.cpp

@@ -266,4 +266,12 @@ void* DebugSession::single_step()
     return (void*)regs.eip;
 }
 
+void DebugSession::detach()
+{
+    for (auto& breakpoint : m_breakpoints.keys()) {
+        remove_breakpoint(breakpoint);
+    }
+    continue_debugee();
+}
+
 }

+ 9 - 2
Libraries/LibDebug/DebugSession.h

@@ -90,11 +90,14 @@ public:
     };
     void continue_debugee(ContinueType type = ContinueType::FreeRun);
 
-    //returns the wstatus result of waitpid()
+    // Returns the wstatus result of waitpid()
     int continue_debugee_and_wait(ContinueType type = ContinueType::FreeRun);
 
+    // Returns the new eip
     void* single_step();
 
+    void detach();
+
     template<typename Callback>
     void run(Callback callback);
 
@@ -236,7 +239,11 @@ void DebugSession::run(Callback callback)
             state = State::SingleStep;
         }
 
-        if (decision == DebugDecision::Kill || decision == DebugDecision::Detach) {
+        if (decision == DebugDecision::Detach) {
+            detach();
+            break;
+        }
+        if (decision == DebugDecision::Kill) {
             ASSERT_NOT_REACHED(); // TODO: implement
         }