thread: add can_access_registers_ptid
authorMarkus Metzger <markus.t.metzger@intel.com>
Fri, 20 Jan 2017 08:05:03 +0000 (09:05 +0100)
committerMarkus Metzger <markus.t.metzger@intel.com>
Wed, 1 Feb 2017 13:34:31 +0000 (14:34 +0100)
Add a function can_access_registers_ptid that behaves like
validate_registers_access but returns a boolean value instead of throwing an
exception.

gdb/
* gdbthread.h (can_access_registers_ptid): New.
* thread.c (can_access_registers_ptid): New.

gdb/ChangeLog
gdb/gdbthread.h
gdb/thread.c

index 710b181578e8b2a660fdfd7a66091207dddf1221..5ce89125cb47a04bf39833f502ddfe2640f86eaf 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-01  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * gdbthread.h (can_access_registers_ptid): New.
+       * thread.c (can_access_registers_ptid): New.
+
 2017-02-01  Pedro Alves  <palves@redhat.com>
 
        * i386-tdep.c (i386_fast_tracepoint_valid_at): Use gdb_insn_length.
index 455cfd8e9372136a3f430c4368ea05e70fee4d8e..06ed78f56819be733eaf6bf8a9b929903574ab27 100644 (file)
@@ -625,6 +625,10 @@ extern void thread_cancel_execution_command (struct thread_info *thr);
    executing).  */
 extern void validate_registers_access (void);
 
+/* Check whether it makes sense to access a register of PTID at this point.
+   Returns true if registers may be accessed; false otherwise.  */
+extern bool can_access_registers_ptid (ptid_t ptid);
+
 /* Returns whether to show which thread hit the breakpoint, received a
    signal, etc. and ended up causing a user-visible stop.  This is
    true iff we ever detected multiple threads.  */
index e45b25750ebfcc3b8fc86fc5e2f78bcd961e445a..99fe42471780c0b74224e19c82eb37f68a6f642a 100644 (file)
@@ -1141,6 +1141,26 @@ validate_registers_access (void)
     error (_("Selected thread is running."));
 }
 
+/* See gdbthread.h.  */
+
+bool
+can_access_registers_ptid (ptid_t ptid)
+{
+  /* No thread, no registers.  */
+  if (ptid_equal (ptid, null_ptid))
+    return false;
+
+  /* Don't try to read from a dead thread.  */
+  if (is_exited (ptid))
+    return false;
+
+  /* ... or from a spinning thread.  FIXME: see validate_registers_access.  */
+  if (is_executing (ptid))
+    return false;
+
+  return true;
+}
+
 int
 pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
 {
This page took 0.027192 seconds and 4 git commands to generate.