diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 51e9ae1b3f0..fdb6b749387 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -225,6 +225,9 @@ struct thread_control_state
   /* Nonzero if stopped due to a step command.  */
   int stop_step = 0;
 
+  /* The last waitstatus for this thread.  */
+  target_waitstatus stop_ws {};
+
   /* Chain containing status of breakpoint(s) the thread stopped
      at.  */
   bpstat *stop_bpstat = nullptr;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index a70d88cd4a7..b347459f335 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3134,6 +3134,7 @@ clear_proceed_status_thread (struct thread_info *tp)
 
   /* Discard any remaining commands or status from previous stop.  */
   bpstat_clear (&tp->control.stop_bpstat);
+  tp->control.stop_ws.set_ignore ();
 }
 
 /* Notify the current interpreter and observers that the target is about to
@@ -4169,7 +4170,8 @@ do_target_wait_1 (inferior *inf, ptid_t ptid,
 	}
 
       tp->set_stop_reason (TARGET_STOPPED_BY_NO_REASON);
-      *status = tp->pending_waitstatus ();
+      tp->control.stop_ws = tp->pending_waitstatus ();
+      *status = tp->control.stop_ws;
       tp->set_internal_state (THREAD_INT_STOPPED);
       tp->clear_pending_waitstatus ();
 
@@ -4187,7 +4189,12 @@ do_target_wait_1 (inferior *inf, ptid_t ptid,
   if (!target_can_async_p ())
     options &= ~TARGET_WNOHANG;
 
-  return target_wait (ptid, status, options);
+  ptid_t event_ptid = target_wait (ptid, status, options);
+  tp = inf->find_thread (event_ptid);
+  if (tp != nullptr)
+    tp->control.stop_ws = *status;
+
+  return event_ptid;
 }
 
 /* Wrapper for target_wait that first checks whether threads have
