Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 05/13 v2] Introduce basic LWP accessors
Date: Thu, 09 Oct 2014 10:18:00 -0000	[thread overview]
Message-ID: <1412848358-9958-6-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1412848358-9958-1-git-send-email-gbenson@redhat.com>

This commit introduces three accessors that shared Linux code can
use to access fields of struct lwp_info.  The GDB and gdbserver
Linux x86 code is modified to use them.

gdb/ChangeLog:

	* nat/linux-nat.h (ptid_of_lwp): New declaration.
	(lwp_is_stopped): Likewise.
	(lwp_is_stopped_by_watchpoint): Likewise.
	* linux-nat.c (ptid_of_lwp): New function.
	(lwp_is_stopped): Likewise.
	(lwp_is_stopped_by_watchpoint): Likewise.
	* x86-linux-nat.c (update_debug_registers_callback):
	Use lwp_is_stopped.
	(x86_linux_prepare_to_resume): Use ptid_of_lwp and
	lwp_is_stopped_by_watchpoint.

gdb/gdbserver/ChangeLog:

	* linux-low.c (ptid_of_lwp): New function.
	(lwp_is_stopped): Likewise.
	(lwp_is_stopped_by_watchpoint): Likewise.
	* linux-x86-low.c (update_debug_registers_callback):
	Use lwp_is_stopped.
	(x86_linux_prepare_to_resume): Use ptid_of_lwp and
	lwp_is_stopped_by_watchpoint.
---
 gdb/ChangeLog                 |   13 +++++++++++++
 gdb/gdbserver/ChangeLog       |   10 ++++++++++
 gdb/gdbserver/linux-low.c     |   26 ++++++++++++++++++++++++++
 gdb/gdbserver/linux-x86-low.c |    6 +++---
 gdb/linux-nat.c               |   27 +++++++++++++++++++++++++++
 gdb/nat/linux-nat.h           |   14 ++++++++++++++
 gdb/x86-linux-nat.c           |   15 ++++++++-------
 7 files changed, 101 insertions(+), 10 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index c980d10..4992945 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -134,6 +134,32 @@ typedef struct
 } Elf64_auxv_t;
 #endif
 
+/* LWP accessors.  */
+
+/* See nat/linux-nat.h.  */
+
+ptid_t
+ptid_of_lwp (struct lwp_info *lwp)
+{
+  return ptid_of (get_lwp_thread (lwp));
+}
+
+/* See nat/linux-nat.h.  */
+
+int
+lwp_is_stopped (struct lwp_info *lwp)
+{
+  return lwp->stopped;
+}
+
+/* See nat/linux-nat.h.  */
+
+int
+lwp_is_stopped_by_watchpoint (struct lwp_info *lwp)
+{
+  return lwp->stopped_by_watchpoint;
+}
+
 /* A list of all unknown processes which receive stop signals.  Some
    other process will presumably claim each of these as forked
    children momentarily.  */
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index a861872..64fab4c 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -570,7 +570,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg)
 
   /* If the lwp isn't stopped, force it to momentarily pause, so
      we can update its debug registers.  */
-  if (!lwp->stopped)
+  if (!lwp_is_stopped (lwp))
     linux_stop_lwp (lwp);
 
   return 0;
@@ -770,7 +770,7 @@ x86_debug_reg_state (pid_t pid)
 static void
 x86_linux_prepare_to_resume (struct lwp_info *lwp)
 {
-  ptid_t ptid = ptid_of (get_lwp_thread (lwp));
+  ptid_t ptid = ptid_of_lwp (lwp);
   int clear_status = 0;
 
   if (lwp->arch_private->debug_registers_changed)
@@ -799,7 +799,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp)
       lwp->arch_private->debug_registers_changed = 0;
     }
 
-  if (clear_status || lwp->stopped_by_watchpoint)
+  if (clear_status || lwp_is_stopped_by_watchpoint (lwp))
     x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
 \f
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 1353d43..4a32bb9 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -278,6 +278,33 @@ static void delete_lwp (ptid_t ptid);
 static struct lwp_info *find_lwp_pid (ptid_t ptid);
 
 \f
+/* LWP accessors.  */
+
+/* See nat/linux-nat.h.  */
+
+ptid_t
+ptid_of_lwp (struct lwp_info *lwp)
+{
+  return lwp->ptid;
+}
+
+/* See nat/linux-nat.h.  */
+
+int
+lwp_is_stopped (struct lwp_info *lwp)
+{
+  return lwp->stopped;
+}
+
+/* See nat/linux-nat.h.  */
+
+int
+lwp_is_stopped_by_watchpoint (struct lwp_info *lwp)
+{
+  return lwp->stopped_by_watchpoint;
+}
+
+\f
 /* Trivial list manipulation functions to keep track of a list of
    new stopped processes.  */
 static void
diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h
index da94f2f..502c2cb 100644
--- a/gdb/nat/linux-nat.h
+++ b/gdb/nat/linux-nat.h
@@ -45,6 +45,20 @@ extern struct lwp_info *iterate_over_lwps (ptid_t filter,
 					   iterate_over_lwps_ftype callback,
 					   void *data);
 
+/* Return the ptid of LWP.  */
+
+extern ptid_t ptid_of_lwp (struct lwp_info *lwp);
+
+/* Return nonzero if LWP is stopped, zero otherwise.  This function
+   must be provided by the client.  */
+
+extern int lwp_is_stopped (struct lwp_info *lwp);
+
+/* Return nonzero if LWP is stopped with a data watchpoint trap,
+   zero otherwise.  This function must be provided by the client.  */
+
+extern int lwp_is_stopped_by_watchpoint (struct lwp_info *lwp);
+
 /* Cause LWP to stop.  This function must be provided by the
    client.  */
 
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 7a80991..c25240d 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -133,7 +133,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg)
 
   /* If the lwp isn't stopped, force it to momentarily pause, so we
      can update its debug registers.  */
-  if (!lwp->stopped)
+  if (!lwp_is_stopped (lwp))
     linux_stop_lwp (lwp);
 
   /* Continue the iteration.  */
@@ -169,6 +169,7 @@ x86_linux_dr_set_addr (int regnum, CORE_ADDR addr)
 static void
 x86_linux_prepare_to_resume (struct lwp_info *lwp)
 {
+  ptid_t ptid = ptid_of_lwp (lwp);
   int clear_status = 0;
 
   /* NULL means this is the main thread still going through the shell,
@@ -180,7 +181,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp)
   if (lwp->arch_private->debug_registers_changed)
     {
       struct x86_debug_reg_state *state
-	= x86_debug_reg_state (ptid_get_pid (lwp->ptid));
+	= x86_debug_reg_state (ptid_get_pid (ptid));
       int i;
 
       /* On Linux kernel before 2.6.33 commit
@@ -193,12 +194,12 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp)
       /* Clear DR_CONTROL first.  In some cases, setting DR0-3 to a
 	 value that doesn't match what is enabled in DR_CONTROL
 	 results in EINVAL.  */
-      x86_linux_dr_set (lwp->ptid, DR_CONTROL, 0);
+      x86_linux_dr_set (ptid, DR_CONTROL, 0);
 
       ALL_DEBUG_ADDRESS_REGISTERS (i)
 	if (state->dr_ref_count[i] > 0)
 	  {
-	    x86_linux_dr_set (lwp->ptid, i, state->dr_mirror[i]);
+	    x86_linux_dr_set (ptid, i, state->dr_mirror[i]);
 
 	    /* If we're setting a watchpoint, any change the inferior
 	       had done itself to the debug registers needs to be
@@ -210,13 +211,13 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp)
       /* If DR_CONTROL is supposed to be zero, we've already set it
 	 above.  */
       if (state->dr_control_mirror != 0)
-	x86_linux_dr_set (lwp->ptid, DR_CONTROL, state->dr_control_mirror);
+	x86_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirror);
 
       lwp->arch_private->debug_registers_changed = 0;
     }
 
-  if (clear_status || lwp->stopped_by_watchpoint)
-    x86_linux_dr_set (lwp->ptid, DR_STATUS, 0);
+  if (clear_status || lwp_is_stopped_by_watchpoint (lwp))
+    x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
 
 static void
-- 
1.7.1


  parent reply	other threads:[~2014-10-09 10:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-09  9:53 [PATCH 00/13 v2] Refactor low-level Linux x86 debug register code Gary Benson
2014-10-09  9:53 ` [PATCH 01/13 v2] Introduce current_lwp_ptid Gary Benson
2014-10-28 12:56   ` Pedro Alves
2014-10-28 16:44     ` Doug Evans
2014-10-28 17:12       ` Doug Evans
2014-10-28 17:13         ` Doug Evans
2014-10-28 18:35       ` Pedro Alves
2014-10-28 19:43         ` Doug Evans
2014-10-31 18:57   ` Doug Evans
2014-10-09  9:53 ` [PATCH 04/13 v2] Make linux_stop_lwp be a shared function Gary Benson
2014-10-28 12:56   ` Pedro Alves
2014-10-09  9:53 ` [PATCH 02/13 v2] Add x86_debug_reg_state to gdbserver Gary Benson
2014-10-28 12:56   ` Pedro Alves
2014-10-09  9:54 ` [PATCH 12/13 v2] Move low-level Linux x86 debug register code to a shared file Gary Benson
2014-10-28 13:01   ` Pedro Alves
2014-10-09 10:18 ` [PATCH 03/13 v2] Add iterate_over_lwps to gdbserver Gary Benson
2014-10-28 12:56   ` Pedro Alves
2014-10-09 10:18 ` [PATCH 07/13 v2] Make lwp_info.arch_private handling shared Gary Benson
2014-10-28 12:57   ` Pedro Alves
2014-10-09 10:18 ` Gary Benson [this message]
2014-10-28 12:57   ` [PATCH 05/13 v2] Introduce basic LWP accessors Pedro Alves
2014-10-09 10:21 ` [PATCH 08/13 v2] Rename gdbserver's low-level Linux x86 debug register accessors Gary Benson
2014-10-28 12:58   ` Pedro Alves
2014-10-09 10:21 ` [PATCH 10/13 v2] Linux x86 low-level debug register comment synchronization Gary Benson
2014-10-28 12:59   ` Pedro Alves
2014-10-09 10:35 ` [PATCH 06/13 v2] Change signature of linux_target_ops.new_thread Gary Benson
2014-10-28 12:57   ` Pedro Alves
2014-10-09 10:35 ` [PATCH 11/13 v2] Introduce x86_linux_update_debug_registers Gary Benson
2014-10-28 13:00   ` Pedro Alves
2014-10-09 10:44 ` [PATCH 09/13 v2] Linux x86 low-level debug register code synchronization Gary Benson
2014-10-28 12:59   ` Pedro Alves
2014-10-09 10:44 ` [PATCH 13/13 v2] Move duplicated Linux x86 code to nat/x86-linux.c Gary Benson
2014-10-28 13:01   ` Pedro Alves
2015-03-24 14:11 ` [pushed] Refactor low-level Linux x86 debug register code Gary Benson

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=1412848358-9958-6-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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