Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Hui Zhu <teawater@gmail.com>, Michael Snyder <msnyder@vmware.com>
Subject: Re: [RFA] Checkpoint: wait the defunct process when delete it
Date: Mon, 10 May 2010 23:30:00 -0000	[thread overview]
Message-ID: <201005110030.09328.pedro@codesourcery.com> (raw)
In-Reply-To: <i2odaef60381005082323jf45a1b90h4f76e7767cfae9bc@mail.gmail.com>

On Sunday 09 May 2010 07:23:15, Hui Zhu wrote:

> 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.

You're assuming inferior_ptid is the parent process
of the checkpoint fork, but I don't believe that is always
true.  E.g., if you do

(gdb) checkpoint
(gdb) checkpoint
(gdb) checkpoint
(gdb) info checkpoints
  3 process 15353 at 0x457d43, file gdb.c, line 28
  2 process 15352 at 0x457d43, file gdb.c, line 28
  1 process 15351 at 0x457d43, file gdb.c, line 28
* 0 Thread 0x7ffff7fcc6f0 (LWP 15348) (main process) at 0x457d43, file gdb.c, line 28
(gdb) restart 1
...
(gdb) delete checkpoint 2

At this point, inferior_ptid will be process 15351, but that
is not the parent of 15352, the process you're killing.  15348
is.

> +static int
> +wait_ptid (ptid_t ptid)
> +{

I'd rename this to call_waitpid, similarly to the call_lseek function
already present in the file.  You may want to reimplement your
function similarly to call_lseek is implemented too.  Your call.

> +  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" here,

> +      waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);

but "waitpid" here?

You could also put those two 'if's on a single line, like:
 
 if (lookup_minimal_symbol ("waitpid", NULL, NULL) != NULL)
   waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);
 if (!waitpid_fn && lookup_minimal_symbol ("_waitpid", NULL, NULL) != NULL)
   waitpid_fn = find_function_in_inferior ("_waitpid", &waitpid_objf);

> +  /* 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;

The second argument of waitpid is a pointer, not an integer.  From
`man waitpid':

 pid_t waitpid(pid_t pid, int *status, int options);

> +  if (call_function_by_hand (waitpid_fn, 3, argv) == 0)
> +    return -1;

This doesn't work in non-stop/async modes if the parent
is presently running.  Maybe just take the easy route for now, and
add an is_stopped check, bailing out if not stopped?

> +  if (wait_ptid (ptid))
> +    error (_("Unable to wait pid %s"), target_pid_to_str (ptid));

-- 
Pedro Alves


  parent reply	other threads:[~2010-05-10 23:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-09  6:23 Hui Zhu
2010-05-10 19:31 ` Michael Snyder
2010-05-10 23:30 ` Pedro Alves [this message]
2010-05-11 21:50   ` Michael Snyder
2010-05-11 22:28     ` Michael Snyder
2010-05-12  0:02     ` Pedro Alves
2010-05-11 22:43 ` Michael Snyder
2010-05-12  0:05   ` Pedro Alves
2010-05-12  0:27     ` Michael Snyder
2010-05-12  4:19       ` Hui Zhu
2010-05-12 18:39         ` Pedro Alves
2010-05-12 18:57           ` Pedro Alves
2010-05-13  9:11           ` Hui Zhu
2010-05-13 11:50             ` Pedro Alves
2010-05-14 11:05               ` Hui Zhu
2010-05-14 14:43                 ` Pedro Alves
2010-05-14 15:08                   ` Hui Zhu
2010-05-14 16:19                     ` Pedro Alves
2010-05-17  6:41                       ` Hui Zhu
2010-05-17 10:45                         ` Pedro Alves
2010-05-18 17:18                           ` Hui Zhu
2010-05-14 19:29                     ` Michael Snyder
2010-05-17  8:11                       ` Hui Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201005110030.09328.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=msnyder@vmware.com \
    --cc=teawater@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox