This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Checkpoint: wait the defunct process when delete it


Hui Zhu wrote:
Hi,

I found that when we delete the checkpoint process, it keep defunct.
This is because the parent process is still running and didn't wait
it.
So I add a wait_ptid function after ptrace kill.

Please help me review it.

I think it should be called something more informative than "wait_ptid". The name should reflect the fact that it is actually the inferior that is calling wait, not gdb.

Something like "inferior_call_wait_ptid", perhaps.

Other than that it seems like a good idea...


2010-05-09 Hui Zhu <teawater@gmail.com>

	* linux-fork.c (wait_ptid): New function.
	(delete_checkpoint_command): Call wait_ptid.


--- linux-fork.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)

--- a/linux-fork.c
+++ b/linux-fork.c
@@ -410,6 +410,35 @@ linux_fork_detach (char *args, int from_
     delete_fork (inferior_ptid);
 }

+static int
+wait_ptid (ptid_t ptid)
+{
+  struct objfile *waitpid_objf;
+  struct value *waitpid_fn = NULL;
+  struct value *argv[4];
+  struct gdbarch *gdbarch = get_current_arch ();
+
+  /* Get the waitpid_fn.  */
+  if (lookup_minimal_symbol ("waitpid", NULL, NULL) != NULL)
+    waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);
+  if (!waitpid_fn)
+    if (lookup_minimal_symbol ("_waitpid", NULL, NULL) != NULL)
+      waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);
+  if (!waitpid_fn)
+    return -1;
+
+  /* Get the argv.  */
+  argv[0] = value_from_longest (builtin_type (gdbarch)->builtin_int,
PIDGET (ptid));
+  argv[1] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
+  argv[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
+  argv[3] = 0;
+
+  if (call_function_by_hand (waitpid_fn, 3, argv) == 0)
+    return -1;
+
+  return 0;
+}
+
 /* Fork list <-> user interface.  */

 static void
@@ -431,6 +460,9 @@ Please switch to another checkpoint befo
   if (ptrace (PTRACE_KILL, PIDGET (ptid), 0, 0))
     error (_("Unable to kill pid %s"), target_pid_to_str (ptid));

+  if (wait_ptid (ptid))
+    error (_("Unable to wait pid %s"), target_pid_to_str (ptid));
+
   if (from_tty)
     printf_filtered (_("Killed %s\n"), target_pid_to_str (ptid));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]