Initialize last_resume_kind for remote fork child
authorDon Breazeal <donb@codesourcery.com>
Thu, 28 May 2015 20:12:01 +0000 (13:12 -0700)
committerDon Breazeal <donb@codesourcery.com>
Thu, 28 May 2015 21:40:30 +0000 (14:40 -0700)
This patch fixes some intermittent test failures in
gdb.base/foll-vfork.exp where a vfork child would be (incorrectly)
resumed when handling the vfork event.  In this case the result
was a subsequent event reported to the client side as a SIGTRAP
delivered to the as-yet-unknown child thread.

The new thread was resumed (incorrectly) in linux-low.c when
resume_stopped_resumed_lwps was called from
linux_wait_for_event_filtered after the vfork event had been
handled in handle_extended_wait.

Gdbserver/linux-low.c's add_thread function creates threads with
last_resume_kind == resume_continue by default.  This field is
used by resume_stopped_resumed_lwps to decide whether to perform
the resume:

static void
resume_stopped_resumed_lwps (struct inferior_list_entry *entry) {
  struct thread_info *thread = (struct thread_info *) entry;
  struct lwp_info *lp = get_thread_lwp (thread);

  if (lp->stopped
      && !lp->status_pending_p
      && thread->last_resume_kind != resume_stop
      && thread->last_status.kind == TARGET_WAITKIND_IGNORE)
    {

So the fix is to make sure to set thread->last_resume_kind to
resume_stop.  Here we do that for new fork children in
gdbserver/linux-low.c:handle_extended_wait.

In addition, it seemed prudent to initialize lwp_info.status_pending_p
for the new fork child.  I also rearranged the initialization code
so that all of the lwp_info initialization was together, rather than
intermixed with thread_info and process_info initialization.

Tested native, native-gdbserver, native-extended-gdbserver on
x86_64 GNU/Linux.

gdb/gdbserver/

* linux-low.c (handle_extended_wait): Initialize
thread_info.last_resume_kind for new fork children.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c

index 0f30c66d0eef3038b883d23c58b3be0ac5b89ea7..4e4f42935b620e145ef0e34b4633dfa24adee5c0 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-28  Don Breazeal  <donb@codesourcery.com>
+
+       * linux-low.c (handle_extended_wait): Initialize
+       thread_info.last_resume_kind for new fork children.
+
 2015-05-15  Pedro Alves  <palves@redhat.com>
 
        * target.h (target_handle_new_gdb_connection): Rewrite using if
index 9f3ea4881ff4f0ba015fe998eb14e022c6b573b1..d763c66e5b10ebc73936555071573bfb3961bcdd 100644 (file)
@@ -457,6 +457,7 @@ handle_extended_wait (struct lwp_info *event_lwp, int wstat)
          struct process_info *parent_proc;
          struct process_info *child_proc;
          struct lwp_info *child_lwp;
+         struct thread_info *child_thr;
          struct target_desc *tdesc;
 
          ptid = ptid_build (new_pid, new_pid, 0);
@@ -479,6 +480,10 @@ handle_extended_wait (struct lwp_info *event_lwp, int wstat)
          child_lwp = add_lwp (ptid);
          gdb_assert (child_lwp != NULL);
          child_lwp->stopped = 1;
+         child_lwp->must_set_ptrace_flags = 1;
+         child_lwp->status_pending_p = 0;
+         child_thr = get_lwp_thread (child_lwp);
+         child_thr->last_resume_kind = resume_stop;
          parent_proc = get_thread_process (event_thr);
          child_proc->attached = parent_proc->attached;
          clone_all_breakpoints (&child_proc->breakpoints,
@@ -488,7 +493,6 @@ handle_extended_wait (struct lwp_info *event_lwp, int wstat)
          tdesc = xmalloc (sizeof (struct target_desc));
          copy_target_description (tdesc, parent_proc->tdesc);
          child_proc->tdesc = tdesc;
-         child_lwp->must_set_ptrace_flags = 1;
 
          /* Clone arch-specific process data.  */
          if (the_low_target.new_fork != NULL)