[RFC,2/8] gdb, infrun: track last waitstatus per thread

Message ID 20261001102847.576880-3-markus.t.metzger@intel.com
State New
Headers
Series breakpoint handling |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Skipped because it is an RFC

Commit Message

Metzger, Markus T Oct. 1, 2026, 10:28 a.m. UTC
  ---
 gdb/gdbthread.h |  3 +++
 gdb/infrun.c    | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
  

Patch

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