gdbserver/Linux: unbreak thread event randomization
authorPedro Alves <palves@redhat.com>
Sun, 15 Mar 2015 19:35:26 +0000 (19:35 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 19 Mar 2015 12:38:05 +0000 (12:38 +0000)
Wanting to make sure the new continue-pending-status.exp test tests
both cases of threads 2 and 3 reporting an event, I added counters to
the test, to make it FAIL if events for both threads aren't seen.
Assuming a well behaved backend, and given a reasonable number of
iterations, it should PASS.

However, running that against GNU/Linux gdbserver, I found that
surprisingly, that FAILed.  GDBserver always reported the breakpoint
hit for the same thread.

Turns out that I broke gdbserver's thread event randomization
recently, with git commit 582511be ([gdbserver] linux-low.c: better
starvation avoidance, handle non-stop mode too).  In that commit I
missed that the thread structure also has a status_pending_p field...
The end result was that count_events_callback always returns 0, and
then if no thread is stepping, select_event_lwp always returns the
event thread.  IOW, no randomization is happening at all.  Quite
curious how all the other changes in that patch were sufficient to fix
non-stop-fair-events.exp anyway even with that broken.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/gdbserver/ChangeLog:
2015-03-19 Pedro Alves  <palves@redhat.com>

* linux-low.c (count_events_callback, select_event_lwp_callback):
Use the lwp's status_pending_p field, not the thread's.

gdb/testsuite/ChangeLog:
2015-03-19  Pedro Alves  <palves@redhat.com>

* gdb.threads/continue-pending-status.exp (saw_thread_2)
(saw_thread_3): New globals.
(top level): Increment them when an event for the corresponding
thread is seen.
(no thread starvation): New test.

gdb/ChangeLog
gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c
gdb/linux-nat.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/continue-pending-status.exp

index 7ae3c58347776ebd9c2fac1201ec637e884fb124..cfbd576d5b83ae28e10b5d9cf5a66937ab32b487 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-19 Pedro Alves  <palves@redhat.com>
+
+       * linux-low.c (count_events_callback, select_event_lwp_callback):
+       Use the lwp's status_pending_p field, not the thread's.
+
 2015-03-19  Pedro Alves  <palves@redhat.com>
 
        * linux-nat.c (status_callback): Return early if the LWP has no
index 6efab5b53d17e27e6dd733faa7a94fb2ed70f04a..df8f9ab888c820bae2f2958291238654126295d1 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-19 Pedro Alves  <palves@redhat.com>
+
+       * linux-low.c (count_events_callback, select_event_lwp_callback):
+       Use the lwp's status_pending_p field, not the thread's.
+
 2015-03-19  Pedro Alves  <palves@redhat.com>
 
        * linux-low.c (select_event_lwp_callback): Update comments to
index 9558f46371664d5cd86a3ff8ed44b5229e70e867..e53e0fc187d39cf5996e6c6e16de01485721f778 100644 (file)
@@ -2238,6 +2238,7 @@ static int
 count_events_callback (struct inferior_list_entry *entry, void *data)
 {
   struct thread_info *thread = (struct thread_info *) entry;
+  struct lwp_info *lp = get_thread_lwp (thread);
   int *count = data;
 
   gdb_assert (count != NULL);
@@ -2245,7 +2246,7 @@ count_events_callback (struct inferior_list_entry *entry, void *data)
   /* Count only resumed LWPs that have an event pending. */
   if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
       && thread->last_resume_kind != resume_stop
-      && thread->status_pending_p)
+      && lp->status_pending_p)
     (*count)++;
 
   return 0;
@@ -2273,6 +2274,7 @@ static int
 select_event_lwp_callback (struct inferior_list_entry *entry, void *data)
 {
   struct thread_info *thread = (struct thread_info *) entry;
+  struct lwp_info *lp = get_thread_lwp (thread);
   int *selector = data;
 
   gdb_assert (selector != NULL);
@@ -2280,7 +2282,7 @@ select_event_lwp_callback (struct inferior_list_entry *entry, void *data)
   /* Select only resumed LWPs that have an event pending. */
   if (thread->last_resume_kind != resume_stop
       && thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && thread->status_pending_p)
+      && lp->status_pending_p)
     if ((*selector)-- == 0)
       return 1;
 
@@ -2324,6 +2326,7 @@ select_event_lwp (struct lwp_info **orig_lp)
 
       /* First see how many events we have.  */
       find_inferior (&all_threads, count_events_callback, &num_events);
+      gdb_assert (num_events > 0);
 
       /* Now randomly pick a LWP out of those that have had
         events.  */
index f5f92d9d96b65411ff93ca7ab2364a3a26b4238f..40f1e1fce4056e4460d01f45e4dfec2359152822 100644 (file)
@@ -2841,6 +2841,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
 
       /* First see how many events we have.  */
       iterate_over_lwps (filter, count_events_callback, &num_events);
+      gdb_assert (num_events > 0);
 
       /* Now randomly pick a LWP out of those that have had
         events.  */
index 94dae82fe9866099dd4e9d2ae962b1e13d8a1c4f..6bf008a3df4f944979bd6ecb05b3eed8b5fdd6f7 100644 (file)
@@ -1,3 +1,11 @@
+2015-03-19  Pedro Alves  <palves@redhat.com>
+
+       * gdb.threads/continue-pending-status.exp (saw_thread_2)
+       (saw_thread_3): New globals.
+       (top level): Increment them when an event for the corresponding
+       thread is seen.
+       (no thread starvation): New test.
+
 2015-03-19  Pedro Alves  <palves@redhat.com>
 
        * gdb.threads/continue-pending-status.c: New file.
index ff73ce4abbb7df11763c885c38cbb9668d4c85b6..1f170f74ef4ddf70cca73d7ebb068a009131ee3e 100644 (file)
@@ -56,6 +56,13 @@ proc get_current_thread {} {
 
 set attempts 20
 
+# These track whether we saw events for both threads 2 and 3.  If the
+# backend always returns the breakpoint hit for the same thread, then
+# it fails to make sure threads aren't starved, and we'll fail the
+# assert after the loop.
+set saw_thread_2 0
+set saw_thread_3 0
+
 for {set i 0} {$i < $attempts} {incr i} {
     with_test_prefix "attempt $i" {
        gdb_test "b $srcfile:$break_line" \
@@ -71,8 +78,10 @@ for {set i 0} {$i < $attempts} {incr i} {
        # the resume and go straight to consuming the pending event.
        set thread [get_current_thread]
        if {$thread == 2} {
+           incr saw_thread_2
            set thread 3
        } else {
+           incr saw_thread_3
            set thread 2
        }
        gdb_test "thread $thread" \
@@ -108,3 +117,8 @@ for {set i 0} {$i < $attempts} {incr i} {
        }
     }
 }
+
+verbose -log "saw_thread_2=$saw_thread_2"
+verbose -log "saw_thread_3=$saw_thread_3"
+
+gdb_assert {$saw_thread_2 > 0 && $saw_thread_3 > 0} "no thread starvation"
This page took 0.039986 seconds and 4 git commands to generate.