This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] thread: add can_access_registers_ptid


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cf77c34ea71c27c3cb6dd31c9448249276e8a8a6

commit cf77c34ea71c27c3cb6dd31c9448249276e8a8a6
Author: Markus Metzger <markus.t.metzger@intel.com>
Date:   Fri Jan 20 09:05:03 2017 +0100

    thread: add can_access_registers_ptid
    
    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.

Diff:
---
 gdb/ChangeLog   |  5 +++++
 gdb/gdbthread.h |  4 ++++
 gdb/thread.c    | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 710b181..5ce8912 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 455cfd8..06ed78f 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -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.  */
diff --git a/gdb/thread.c b/gdb/thread.c
index e45b257..99fe424 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -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)
 {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]