gdbserver: hide fork child threads from GDB
[deliverable/binutils-gdb.git] / gdbserver / linux-low.h
index 106d4893312833bebb26e62ec27af36dae64b0c8..6e4549fab2cfee52a26870a36cbffd79da963111 100644 (file)
@@ -311,6 +311,8 @@ public:
                      int *handle_len) override;
 #endif
 
+  thread_info *thread_pending_parent (thread_info *thread) override;
+
   bool supports_catch_syscall () override;
 
   /* Return the information to access registers.  This has public
@@ -726,6 +728,33 @@ struct lwp_info
     this->waitstatus.kind = TARGET_WAITKIND_IGNORE;
   }
 
+  /* If this LWP is a fork child that wasn't reported to GDB yet, return
+     its parent, else nullptr.  */
+  lwp_info *pending_parent () const
+  {
+    if (this->fork_relative == nullptr)
+      return nullptr;
+
+    gdb_assert (this->fork_relative->fork_relative == this);
+
+    /* In a fork parent/child relationship, the parent has a status pending and
+       the child does not, and a thread can only be in one such relationship
+       at most.  So we can recognize who is the parent based on which one has
+       a pending status.  */
+    gdb_assert (!!this->status_pending_p
+               != !!this->fork_relative->status_pending_p);
+
+    if (!this->fork_relative->status_pending_p)
+      return nullptr;
+
+    const target_waitstatus &ws
+      = this->fork_relative->waitstatus;
+    gdb_assert (ws.kind == TARGET_WAITKIND_FORKED
+               || ws.kind == TARGET_WAITKIND_VFORKED);
+
+    return this->fork_relative;
+  }
+
   /* Backlink to the parent object.  */
   struct thread_info *thread = nullptr;
 
This page took 0.027146 seconds and 4 git commands to generate.