From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28746 invoked by alias); 9 May 2010 06:23:42 -0000 Received: (qmail 28737 invoked by uid 22791); 9 May 2010 06:23:41 -0000 X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL,BAYES_05,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SARE_MSGID_LONG45,TW_BJ X-Spam-Check-By: sourceware.org Received: from mail-pw0-f41.google.com (HELO mail-pw0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 09 May 2010 06:23:38 +0000 Received: by pwi10 with SMTP id 10so1248241pwi.0 for ; Sat, 08 May 2010 23:23:36 -0700 (PDT) Received: by 10.143.21.14 with SMTP id y14mr1439053wfi.43.1273386215513; Sat, 08 May 2010 23:23:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.143.4.9 with HTTP; Sat, 8 May 2010 23:23:15 -0700 (PDT) From: Hui Zhu Date: Sun, 09 May 2010 06:23:00 -0000 Message-ID: Subject: [RFA] Checkpoint: wait the defunct process when delete it To: gdb-patches ml Cc: Michael Snyder Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-05/txt/msg00219.txt.bz2 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. Thanks, Hui 2010-05-09 Hui Zhu * 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));