make_cleanup_restore_current_thread: Look up thread earlier
authorPedro Alves <palves@redhat.com>
Thu, 4 May 2017 13:43:34 +0000 (14:43 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 4 May 2017 14:17:38 +0000 (15:17 +0100)
The unconditional is_stopped call already asserts that the thread exists.

gdb/ChangeLog:
2017-05-04  Pedro Alves  <palves@redhat.com>

* thread.c (make_cleanup_restore_current_thread): Move
find_thread_ptid call before the is_stopped call.  Assert that the
thread is found.  Replace is_stopped call by checking the thread's
state directly.  Remove unnecessary NULL-thread check.

gdb/ChangeLog
gdb/thread.c

index aeb83ddebba0f71ebca3cf4686915070f77cdc68..7c48c3d311dafd0fe115846e91189de4d10255f1 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-04  Pedro Alves  <palves@redhat.com>
+
+       * thread.c (make_cleanup_restore_current_thread): Move
+       find_thread_ptid call before the is_stopped call.  Assert that the
+       thread is found.  Replace is_stopped call by checking the thread's
+       state directly.  Remove unnecessary NULL-thread check.
+
 2017-05-04  Pedro Alves  <palves@redhat.com>
 
        * corelow.c (thread_section_name): New class.
index d08f414327330c7fd6243943bed3020d17d9ac6e..fce37c5cb8080b608ab089e35421047bcbf10179 100644 (file)
@@ -1626,9 +1626,12 @@ make_cleanup_restore_current_thread (void)
 
   if (inferior_ptid != null_ptid)
     {
+      thread_info *tp = find_thread_ptid (inferior_ptid);
       struct frame_info *frame;
 
-      old->was_stopped = is_stopped (inferior_ptid);
+      gdb_assert (tp != NULL);
+
+      old->was_stopped = tp->state == THREAD_STOPPED;
       if (old->was_stopped
          && target_has_registers
          && target_has_stack
@@ -1647,10 +1650,7 @@ make_cleanup_restore_current_thread (void)
       old->selected_frame_id = get_frame_id (frame);
       old->selected_frame_level = frame_relative_level (frame);
 
-      struct thread_info *tp = find_thread_ptid (inferior_ptid);
-
-      if (tp)
-       tp->incref ();
+      tp->incref ();
       old->thread = tp;
     }