Introduce basic LWP accessors
authorGary Benson <gbenson@redhat.com>
Tue, 24 Mar 2015 14:05:44 +0000 (14:05 +0000)
committerGary Benson <gbenson@redhat.com>
Tue, 24 Mar 2015 14:05:44 +0000 (14:05 +0000)
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_stop_reason): 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_stop_reason.

gdb/gdbserver/ChangeLog:

* linux-low.c (ptid_of_lwp): New function.
(lwp_is_stopped): Likewise.
(lwp_stop_reason): Likewise.
* linux-x86-low.c (update_debug_registers_callback):
Use lwp_is_stopped.
(x86_linux_prepare_to_resume): Use ptid_of_lwp and
lwp_stop_reason.

gdb/ChangeLog
gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c
gdb/gdbserver/linux-x86-low.c
gdb/linux-nat.c
gdb/nat/linux-nat.h
gdb/x86-linux-nat.c

index d38e8283f0103ba0f4d47764955efb640624707b..fd5c10ba4f32dc251b80052441bb5ad36579ff9e 100644 (file)
@@ -1,3 +1,16 @@
+2015-03-24  Gary Benson  <gbenson@redhat.com>
+
+       * nat/linux-nat.h (ptid_of_lwp): New declaration.
+       (lwp_is_stopped): Likewise.
+       (lwp_stop_reason): 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_stop_reason.
+
 2015-03-24  Gary Benson  <gbenson@redhat.com>
 
        * linux-nat.h (linux_stop_lwp): Move declaration to...
index 0eef24e601c7db95cf4fbd9f42ab7c8cc6caa3ae..a77f04ba705e747a0bf4feff743e92c7d858695e 100644 (file)
@@ -1,3 +1,13 @@
+2015-03-24  Gary Benson  <gbenson@redhat.com>
+
+       * linux-low.c (ptid_of_lwp): New function.
+       (lwp_is_stopped): Likewise.
+       (lwp_stop_reason): Likewise.
+       * linux-x86-low.c (update_debug_registers_callback):
+       Use lwp_is_stopped.
+       (x86_linux_prepare_to_resume): Use ptid_of_lwp and
+       lwp_stop_reason.
+
 2015-03-24  Gary Benson  <gbenson@redhat.com>
 
        * linux-low.h (linux_stop_lwp): Remove declaration.
index 0c74e11b6ef0bf3ff712237058133561823735be..f2a2224601514833e615e76da8b45fe9f345bdd0 100644 (file)
@@ -136,6 +136,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.  */
+
+enum target_stop_reason
+lwp_stop_reason (struct lwp_info *lwp)
+{
+  return lwp->stop_reason;
+}
+
 /* A list of all unknown processes which receive stop signals.  Some
    other process will presumably claim each of these as forked
    children momentarily.  */
index 34254920d99c8632da88f8ecaeebb59cc73222f9..43bf8296f5e888441daf64fa4b67bd59158dc384 100644 (file)
@@ -583,7 +583,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;
@@ -783,7 +783,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)
@@ -812,7 +812,8 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp)
       lwp->arch_private->debug_registers_changed = 0;
     }
 
-  if (clear_status || lwp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
+  if (clear_status
+      || lwp_stop_reason (lwp) == TARGET_STOPPED_BY_WATCHPOINT)
     x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
 \f
index 5a2cba580fcc702ab353f05ab7687f650fba785e..283a12bc7125d327a8c2295aae4f3f0ccf273ef7 100644 (file)
@@ -281,6 +281,33 @@ static int check_stopped_by_breakpoint (struct lwp_info *lp);
 static int sigtrap_is_event (int status);
 static int (*linux_nat_status_is_event) (int status) = sigtrap_is_event;
 
+\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.  */
+
+enum target_stop_reason
+lwp_stop_reason (struct lwp_info *lwp)
+{
+  return lwp->stop_reason;
+}
+
 \f
 /* Trivial list manipulation functions to keep track of a list of
    new stopped processes.  */
index c9830254dcc83888de85f8a896a9763e231e16f3..51d9ead21b8244c6d61c2b4161cb592eed8c53c9 100644 (file)
@@ -47,6 +47,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 the reason the LWP last stopped.  This function must be
+   provided by the client.  */
+
+extern enum target_stop_reason lwp_stop_reason (struct lwp_info *lwp);
+
 /* Cause LWP to stop.  This function must be provided by the
    client.  */
 
index 7e451100518a76a9265dd191b2f615c9b9bf8146..74b48e378ee3238be06731c5a50bb60aa7e9208b 100644 (file)
@@ -142,7 +142,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.  */
@@ -178,6 +178,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,
@@ -189,7 +190,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
@@ -202,12 +203,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
@@ -219,13 +220,14 @@ 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->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
-    x86_linux_dr_set (lwp->ptid, DR_STATUS, 0);
+  if (clear_status
+      || lwp_stop_reason (lwp) == TARGET_STOPPED_BY_WATCHPOINT)
+    x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
 
 static void
This page took 0.042451 seconds and 4 git commands to generate.