[PATCH v2 16/47] gdb, infrun, ze: handle stopping unavailable threads

Tankut Baris Aktemur
2024-12-13T16:17:51Z

From: Markus Metzger <markus.t.metzger@intel.com>

On GPUs, threads may not always respond to interrupt requests. In order
to still be able to support all-stop model on those targets, we allow this
case and model such threads as unavailable.

They do exist but we cannot interact with them. In particular, they do
not have registers, including PC.

Use regcache_read_pc_protected () instead of regcache_read_pc () to
suppress an error when trying to access an unavailable thread's registers.
The thread's waitstatus will be TARGET_WAITKIND_UNAVAILABLE so there is
nothing extra to do here.
---
gdb/infrun.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index d28a5867dcfd9fd7888c1d19008cb5606cb9116b..2abc2331e1821f3058ae00ee8908209dd7be020d 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -5610,7 +5610,7 @@ handle_one (const wait_one_event &event)
}

regcache = get_thread_regcache (t);
- t->set_stop_pc (regcache_read_pc (regcache));
+ t->set_stop_pc (regcache_read_pc_protected (regcache));

infrun_debug_printf ("saved stop_pc=%s for %s "
"(currently_stepping=%d)",
@@ -6237,7 +6237,8 @@ handle_inferior_event (struct execution_control_state *ecs)

handle_solib_event ();

- ecs->event_thread->set_stop_pc (regcache_read_pc (regcache));
+ ecs->event_thread->set_stop_pc
+ (regcache_read_pc_protected (regcache));
address_space *aspace = ecs->event_thread->inf->aspace.get ();
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status_nowatch (aspace,