Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: gdb-patches@sourceware.org
Cc: palves@redhat.com
Subject: [PATCH v2 1/2] thread: add can_access_registers_ptid
Date: Fri, 20 Jan 2017 14:39:00 -0000	[thread overview]
Message-ID: <1484923135-31270-2-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1484923135-31270-1-git-send-email-markus.t.metzger@intel.com>

Add a function can_access_registers_ptid that behaves like
validate_registers_access but returns a boolean value instead of throwing an
exception.

2017-01-20  Markus Metzger  <markus.t.metzger@intel.com>

	* gdbthread.h (can_access_registers_ptid): New.
	* thread.c (can_access_registers_ptid): New.
---
 gdb/gdbthread.h |  4 ++++
 gdb/thread.c    | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 455cfd8..041b7c2 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 non-zero if registers may be accessed; zero otherwise.  */
+extern int 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..d5dfe80 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.  */
+
+int
+can_access_registers_ptid (ptid_t ptid)
+{
+  /* No thread, no registers.  */
+  if (ptid_equal (ptid, null_ptid))
+    return 0;
+
+  /* Don't try to read from a dead thread.  */
+  if (is_exited (ptid))
+    return 0;
+
+  /* ... or from a spinning thread.  FIXME: see validate_registers_access.  */
+  if (is_executing (ptid))
+    return 0;
+
+  return 1;
+}
+
 int
 pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
 {
-- 
1.8.3.1


  reply	other threads:[~2017-01-20 14:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 14:39 [PATCH v2 0/2] thread, btrace: allow "record btrace" for running threads Markus Metzger
2017-01-20 14:39 ` Markus Metzger [this message]
2017-01-25 14:33   ` [PATCH v2 1/2] thread: add can_access_registers_ptid Pedro Alves
2017-01-20 14:39 ` [PATCH v2 2/2] btrace: allow recording to be started for running threads Markus Metzger
2017-01-25 14:32   ` Pedro Alves
2017-01-25 14:36     ` Pedro Alves
2017-01-25 15:53     ` Metzger, Markus T
2017-01-25 16:13       ` Pedro Alves
2017-01-26 14:54         ` Metzger, Markus T

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484923135-31270-2-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox