]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix next over threaded execl with "set scheduler-locking step".
authorPedro Alves <palves@redhat.com>
Thu, 19 Jun 2014 10:59:03 +0000 (11:59 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 19 Jun 2014 10:59:03 +0000 (11:59 +0100)
Running gdb.threads/thread-execl.exp with scheduler-locking set to
"step" reveals a problem:

 (gdb) next^M
 [Thread 0x7ffff7fda700 (LWP 27168) exited]^M
 [New LWP 27168]^M
 [Thread 0x7ffff74ee700 (LWP 27174) exited]^M
 process 27168 is executing new program: /home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.threads/thread-execl^M
 [Thread debugging using libthread_db enabled]^M
 Using host libthread_db library "/lib64/libthread_db.so.1".^M
 infrun.c:5225: internal-error: switch_back_to_stepped_thread: Assertion `!schedlock_applies (1)' failed.^M
 A problem internal to GDB has been detected,^M
 further debugging may prove unreliable.^M
 Quit this debugging session? (y or n) FAIL: gdb.threads/thread-execl.exp: schedlock step: get to main in new image (GDB internal error)

The assertion is correct.  The issue is that GDB is mistakenly trying
to switch back to an exited thread, that was previously stepping when
it exited.  This is exactly the sort of thing the test wants to make
sure doesn't happen:

# Now set a breakpoint at `main', and step over the execl call.  The
# breakpoint at main should be reached.  GDB should not try to revert
# back to the old thread from the old image and resume stepping it

We don't see this bug with schedlock off only because a different
sequence of events makes GDB manage to delete the thread instead of
marking it exited.

This particular internal error can be fixed by making the loop over
all threads in switch_back_to_stepped_thread skip exited threads.
But, looking over other ALL_THREADS users, all either can or should be
skipping exited threads too.  So for simplicity, this patch replaces
ALL_THREADS with a new macro that skips exited threads itself, and
updates everything to use it.

Tested on x86_64 Fedora 20.

gdb/
2014-06-19  Pedro Alves  <palves@redhat.com>

* gdbthread.h (ALL_THREADS): Delete.
(ALL_NON_EXITED_THREADS): New macro.
* btrace.c (btrace_free_objfile): Use ALL_NON_EXITED_THREADS
instead of ALL_THREADS.
* infrun.c (find_thread_needs_step_over)
(switch_back_to_stepped_thread): Use ALL_NON_EXITED_THREADS
instead of ALL_THREADS.
* record-btrace.c (record_btrace_open)
(record_btrace_stop_recording, record_btrace_close)
(record_btrace_is_replaying, record_btrace_resume)
(record_btrace_find_thread_to_move, record_btrace_wait): Likewise.
* remote.c (append_pending_thread_resumptions): Likewise.
* thread.c (thread_apply_all_command): Likewise.

gdb/testsuite/
2014-06-19  Pedro Alves  <palves@redhat.com>

* gdb.threads/thread-execl.exp (do_test): New procedure, factored
out from ...
(top level): ... here.  Iterate running tests under different
scheduler-locking settings.

gdb/ChangeLog
gdb/btrace.c
gdb/gdbthread.h
gdb/infrun.c
gdb/record-btrace.c
gdb/remote.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/thread-execl.exp
gdb/thread.c

index f13c19a63c73ae59cea89804a294d2cfe8973ed2..850b26754bf10c68d141b2a45da74f686d0dd4a1 100644 (file)
@@ -1,3 +1,19 @@
+2014-06-19  Pedro Alves  <palves@redhat.com>
+
+       * gdbthread.h (ALL_THREADS): Delete.
+       (ALL_NON_EXITED_THREADS): New macro.
+       * btrace.c (btrace_free_objfile): Use ALL_NON_EXITED_THREADS
+       instead of ALL_THREADS.
+       * infrun.c (find_thread_needs_step_over)
+       (switch_back_to_stepped_thread): Use ALL_NON_EXITED_THREADS
+       instead of ALL_THREADS.
+       * record-btrace.c (record_btrace_open)
+       (record_btrace_stop_recording, record_btrace_close)
+       (record_btrace_is_replaying, record_btrace_resume)
+       (record_btrace_find_thread_to_move, record_btrace_wait): Likewise.
+       * remote.c (append_pending_thread_resumptions): Likewise.
+       * thread.c (thread_apply_all_command): Likewise.
+
 2014-06-19  Gary Benson  <gbenson@redhat.com>
 
        * i386-nat.c (i386_stopped_by_watchpoint):
index 601eb4126c6ce28d0f16335cb22af727a6fc2195..87a171e812eb9b212679bb7b72275b73cf40fdab 100644 (file)
@@ -958,7 +958,7 @@ btrace_free_objfile (struct objfile *objfile)
 
   DEBUG ("free objfile");
 
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     btrace_clear (tp);
 }
 
index 9f5dee6ea00c0f4a77f52f08f9249488977e67cc..64e37c3cdc74b2760f82f999458bb56964af4e9f 100644 (file)
@@ -317,10 +317,12 @@ void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
 typedef int (*thread_callback_func) (struct thread_info *, void *);
 extern struct thread_info *iterate_over_threads (thread_callback_func, void *);
 
-/* Traverse all threads.  */
+/* Traverse all threads, except those that have THREAD_EXITED
+   state.  */
 
-#define ALL_THREADS(T)                         \
-  for (T = thread_list; T; T = T->next)
+#define ALL_NON_EXITED_THREADS(T)                              \
+  for (T = thread_list; T; T = T->next) \
+    if ((T)->state != THREAD_EXITED)
 
 extern int thread_count (void);
 
index 2be2e5e7d40b0385149481668197ac1d16812d82..bef69a8124b15fbfb85afb151b12a13b1bcca171 100644 (file)
@@ -2160,7 +2160,7 @@ find_thread_needs_step_over (int step, struct thread_info *except)
       return NULL;
     }
 
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     {
       /* Ignore the EXCEPT thread.  */
       if (tp == except)
@@ -5204,7 +5204,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs)
         step/next/etc.  */
       stepping_thread = NULL;
       step_over = NULL;
-      ALL_THREADS (tp)
+      ALL_NON_EXITED_THREADS (tp)
         {
          /* Ignore threads of processes we're not resuming.  */
          if (!sched_multi
index e0c537a8d33330641ca30cfbb6cec0c376e00505..6a9bfe118791535ce1f66bf04612ae56c2c82fcf 100644 (file)
@@ -206,7 +206,7 @@ record_btrace_open (char *args, int from_tty)
   gdb_assert (record_btrace_thread_observer == NULL);
 
   disable_chain = make_cleanup (null_cleanup, NULL);
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     if (args == NULL || *args == 0 || number_is_in_list (args, tp->num))
       {
        btrace_enable (tp);
@@ -238,7 +238,7 @@ record_btrace_stop_recording (struct target_ops *self)
 
   record_btrace_auto_disable ();
 
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     if (tp->btrace.target != NULL)
       btrace_disable (tp);
 }
@@ -259,7 +259,7 @@ record_btrace_close (struct target_ops *self)
 
   /* We should have already stopped recording.
      Tear down btrace in case we have not.  */
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     btrace_teardown (tp);
 }
 
@@ -835,7 +835,7 @@ record_btrace_is_replaying (struct target_ops *self)
 {
   struct thread_info *tp;
 
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     if (btrace_is_replaying (tp))
       return 1;
 
@@ -1522,7 +1522,7 @@ record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
 
   /* Stop replaying other threads if the thread to resume is not replaying.  */
   if (!btrace_is_replaying (tp) && execution_direction != EXEC_REVERSE)
-    ALL_THREADS (other)
+    ALL_NON_EXITED_THREADS (other)
       record_btrace_stop_replaying (other);
 
   /* As long as we're not replaying, just forward the request.  */
@@ -1572,7 +1572,7 @@ record_btrace_find_thread_to_move (ptid_t ptid)
     return tp;
 
   /* Otherwise, find one other thread that has been resumed.  */
-  ALL_THREADS (tp)
+  ALL_NON_EXITED_THREADS (tp)
     if ((tp->btrace.flags & BTHR_MOVE) != 0)
       return tp;
 
@@ -1777,7 +1777,7 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
 
   /* Stop all other threads. */
   if (!non_stop)
-    ALL_THREADS (other)
+    ALL_NON_EXITED_THREADS (other)
       other->btrace.flags &= ~BTHR_MOVE;
 
   /* Start record histories anew from the current position.  */
index 6915dd8d04f17851756c8a3eacf2a9db361e6125..b5318f1d07bda8e1aa2173b69f48d5353f58807e 100644 (file)
@@ -4626,7 +4626,7 @@ append_pending_thread_resumptions (char *p, char *endp, ptid_t ptid)
 {
   struct thread_info *thread;
 
-  ALL_THREADS (thread)
+  ALL_NON_EXITED_THREADS (thread)
     if (ptid_match (thread->ptid, ptid)
        && !ptid_equal (inferior_ptid, thread->ptid)
        && thread->suspend.stop_signal != GDB_SIGNAL_0
index 2fdcbb46010f6be2787189baf7fecbac758732b7..af374091d044fc705e8fe20072749871543b18e8 100644 (file)
@@ -1,3 +1,10 @@
+2014-06-19  Pedro Alves  <palves@redhat.com>
+
+       * gdb.threads/thread-execl.exp (do_test): New procedure, factored
+       out from ...
+       (top level): ... here.  Iterate running tests under different
+       scheduler-locking settings.
+
 2014-06-18  Luis Machado  <lgustavo@codesourcery.com>
 
        * gdb.cp/nsalias.exp: Set type of low_pc and high_pc entries
index d837fe4d1ce1cf492a2287878a7ba9b4138c43e3..14b96d21d780a5c36044559c72b3a012830bab26 100644 (file)
@@ -28,19 +28,33 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
     return -1
 }
 
-clean_restart ${binfile}
-
-runto_main
-
-# Get ourselves to the thread that execs
-gdb_breakpoint "thread_execler"
-gdb_test "continue" ".*thread_execler.*" "continue to thread start"
-
-# Now set a breakpoint at `main', and step over the execl call.  The
-# breakpoint at main should be reached.  GDB should not try to revert
-# back to the old thread from the old image and resume stepping it
-# (since it is gone).
-gdb_breakpoint "main"
-gdb_test "next" ".*main.*" "get to main in new image"
+# Run the test proper.  SCHEDLOCK specifies what scheduler-locking
+# should be set to.
+
+proc do_test { schedlock } {
+    global binfile
+
+    with_test_prefix "schedlock $schedlock" {
+       clean_restart ${binfile}
+
+       if ![runto_main] {
+           return 0
+       }
+
+       # Get ourselves to the thread that execs.
+       gdb_breakpoint "thread_execler"
+       gdb_test "continue" ".*thread_execler.*" "continue to thread start"
+
+       # Now set a breakpoint at `main', and step over the execl call.  The
+       # breakpoint at main should be reached.  GDB should not try to revert
+       # back to the old thread from the old image and resume stepping it
+       # (since it is gone).
+       gdb_breakpoint "main"
+       gdb_test_no_output "set scheduler-locking $schedlock"
+       gdb_test "next" ".*main.*" "get to main in new image"
+    }
+}
 
-return 0
+foreach schedlock {"off" "step" "on"} {
+    do_test $schedlock
+}
index 7bc5271fedd1369c5efa4c10e7374f443f959b08..532149ddc6354ea17c7f58b666ebc74b68e5ca5b 100644 (file)
@@ -1243,7 +1243,7 @@ thread_apply_all_command (char *cmd, int from_tty)
       ta_cleanup.tp_array = tp_array;
       ta_cleanup.count = tc;
 
-      ALL_THREADS (tp)
+      ALL_NON_EXITED_THREADS (tp)
         {
           tp_array[i] = tp;
           tp->refcount++;