This is the mail archive of the gdb-patches@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]

ALL_LWPS, get rid of the ptid parameter


While working on something, I found a genuine case where
we end up with 0 LWPs on the list (without the inferior exiting),
and then ALL_LWPS crashed (on new code in linux-nat.c that used
the macro).  The need for the ptid parameter has
annoyed me before, so I just went away and got rid of it.

Tested on x86-64-linux and applied.

Let me know if I missed anything.

-- 
Pedro Alves

2011-10-07  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* linux-nat.h (ALL_LWPS): Remove the ptid parameter.
	* amd64-linux-nat.c (amd64_linux_dr_set_control)
	(amd64_linux_dr_set_addr, amd64_linux_dr_unset_status): Adjust.
	* arm-linux-nat.c (arm_linux_insert_hw_breakpoint)
	(arm_linux_remove_hw_breakpoint, arm_linux_insert_watchpoint)
	(arm_linux_remove_watchpoint): Adjust.
	* i386-linux-nat.c (i386_linux_dr_set_control)
	(i386_linux_dr_set_addr, i386_linux_dr_unset_status): Adjust.
	* ia64-linux-nat.c (ia64_linux_insert_watchpoint)
	(ia64_linux_remove_watchpoint): Adjust.
	* mips-linux-nat.c (write_watchpoint_regs): Adjust.
	* ppc-linux-nat.c (ppc_linux_insert_hw_breakpoint)
	(ppc_linux_insert_hw_breakpoint, ppc_linux_remove_hw_breakpoint)
	(ppc_linux_insert_mask_watchpoint)
	(ppc_linux_remove_mask_watchpoint, ppc_linux_insert_watchpoint)
	(ppc_linux_remove_watchpoint): Adjust.
	* s390-nat.c (s390_insert_watchpoint, s390_remove_watchpoint):
	Adjust.

---
 gdb/amd64-linux-nat.c |   17 +++++++----------
 gdb/arm-linux-nat.c   |   20 ++++++++------------
 gdb/i386-linux-nat.c  |   19 ++++++++-----------
 gdb/ia64-linux-nat.c  |   12 +++++-------
 gdb/linux-nat.h       |    9 ++++-----
 gdb/mips-linux-nat.c  |    5 ++---
 gdb/ppc-linux-nat.c   |   38 ++++++++++++++++----------------------
 gdb/s390-nat.c        |   10 ++++------
 8 files changed, 54 insertions(+), 76 deletions(-)

Index: src/gdb/linux-nat.h
===================================================================
--- src.orig/gdb/linux-nat.h	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/linux-nat.h	2011-10-07 16:45:59.519110141 +0100
@@ -118,12 +118,11 @@ struct lwp_info
    native target is active.  */
 extern struct lwp_info *lwp_list;
 
-/* Iterate over the PTID each active thread (light-weight process).  There
-   must be at least one.  */
-#define ALL_LWPS(LP, PTID)						\
-  for ((LP) = lwp_list, (PTID) = (LP)->ptid;				\
+/* Iterate over each active thread (light-weight process).  */
+#define ALL_LWPS(LP)							\
+  for ((LP) = lwp_list;							\
        (LP) != NULL;							\
-       (LP) = (LP)->next, (PTID) = (LP) ? (LP)->ptid : (PTID))
+       (LP) = (LP)->next)
 
 #define GET_LWP(ptid)		ptid_get_lwp (ptid)
 #define GET_PID(ptid)		ptid_get_pid (ptid)
Index: src/gdb/amd64-linux-nat.c
===================================================================
--- src.orig/gdb/amd64-linux-nat.c	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/amd64-linux-nat.c	2011-10-07 16:45:59.519110141 +0100
@@ -319,11 +319,10 @@ static void
 amd64_linux_dr_set_control (unsigned long control)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
   amd64_linux_dr[DR_CONTROL] = control;
-  ALL_LWPS (lp, ptid)
-    amd64_linux_dr_set (ptid, DR_CONTROL, control);
+  ALL_LWPS (lp)
+    amd64_linux_dr_set (lp->ptid, DR_CONTROL, control);
 }
 
 /* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST.  */
@@ -332,13 +331,12 @@ static void
 amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
   gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
 
   amd64_linux_dr[DR_FIRSTADDR + regnum] = addr;
-  ALL_LWPS (lp, ptid)
-    amd64_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
+  ALL_LWPS (lp)
+    amd64_linux_dr_set (lp->ptid, DR_FIRSTADDR + regnum, addr);
 }
 
 /* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST.  */
@@ -363,15 +361,14 @@ static void
 amd64_linux_dr_unset_status (unsigned long mask)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
-  ALL_LWPS (lp, ptid)
+  ALL_LWPS (lp)
     {
       unsigned long value;
       
-      value = amd64_linux_dr_get (ptid, DR_STATUS);
+      value = amd64_linux_dr_get (lp->ptid, DR_STATUS);
       value &= ~mask;
-      amd64_linux_dr_set (ptid, DR_STATUS, value);
+      amd64_linux_dr_set (lp->ptid, DR_STATUS, value);
     }
 }
 
Index: src/gdb/arm-linux-nat.c
===================================================================
--- src.orig/gdb/arm-linux-nat.c	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/arm-linux-nat.c	2011-10-07 16:45:59.519110141 +0100
@@ -1075,7 +1075,6 @@ static int
 arm_linux_insert_hw_breakpoint (struct gdbarch *gdbarch, 
 				struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1083,8 +1082,8 @@ arm_linux_insert_hw_breakpoint (struct g
     return -1;
 
   arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (ptid), 0);
+  ALL_LWPS (lp)
+    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (lp->ptid), 0);
 
   return 0;
 }
@@ -1094,7 +1093,6 @@ static int
 arm_linux_remove_hw_breakpoint (struct gdbarch *gdbarch, 
 				struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1102,8 +1100,8 @@ arm_linux_remove_hw_breakpoint (struct g
     return -1;
 
   arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (ptid), 0);
+  ALL_LWPS (lp)
+    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (lp->ptid), 0);
 
   return 0;
 }
@@ -1146,7 +1144,6 @@ static int
 arm_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
 			     struct expression *cond)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1154,8 +1151,8 @@ arm_linux_insert_watchpoint (CORE_ADDR a
     return -1;
 
   arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (ptid), 1);
+  ALL_LWPS (lp)
+    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (lp->ptid), 1);
 
   return 0;
 }
@@ -1165,7 +1162,6 @@ static int
 arm_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
 			     struct expression *cond)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1173,8 +1169,8 @@ arm_linux_remove_watchpoint (CORE_ADDR a
     return -1;
 
   arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (ptid), 1);
+  ALL_LWPS (lp)
+    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (lp->ptid), 1);
 
   return 0;
 }
Index: src/gdb/i386-linux-nat.c
===================================================================
--- src.orig/gdb/i386-linux-nat.c	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/i386-linux-nat.c	2011-10-07 16:45:59.519110141 +0100
@@ -707,11 +707,10 @@ static void
 i386_linux_dr_set_control (unsigned long control)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
   i386_linux_dr[DR_CONTROL] = control;
-  ALL_LWPS (lp, ptid)
-    i386_linux_dr_set (ptid, DR_CONTROL, control);
+  ALL_LWPS (lp)
+    i386_linux_dr_set (lp->ptid, DR_CONTROL, control);
 }
 
 /* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST.  */
@@ -720,13 +719,12 @@ static void
 i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
   gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
 
   i386_linux_dr[DR_FIRSTADDR + regnum] = addr;
-  ALL_LWPS (lp, ptid)
-    i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
+  ALL_LWPS (lp)
+    i386_linux_dr_set (lp->ptid, DR_FIRSTADDR + regnum, addr);
 }
 
 /* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST.  */
@@ -751,15 +749,14 @@ static void
 i386_linux_dr_unset_status (unsigned long mask)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
 
-  ALL_LWPS (lp, ptid)
+  ALL_LWPS (lp)
     {
       unsigned long value;
-      
-      value = i386_linux_dr_get (ptid, DR_STATUS);
+
+      value = i386_linux_dr_get (lp->ptid, DR_STATUS);
       value &= ~mask;
-      i386_linux_dr_set (ptid, DR_STATUS, value);
+      i386_linux_dr_set (lp->ptid, DR_STATUS, value);
     }
 }
 
Index: src/gdb/ia64-linux-nat.c
===================================================================
--- src.orig/gdb/ia64-linux-nat.c	2011-10-07 16:37:10.089109957 +0100
+++ src/gdb/ia64-linux-nat.c	2011-10-07 16:45:59.529110141 +0100
@@ -535,7 +535,6 @@ ia64_linux_insert_watchpoint (CORE_ADDR
 			      struct expression *cond)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   int idx;
   long dbr_addr, dbr_mask;
   int max_watchpoints = 4;
@@ -576,10 +575,10 @@ ia64_linux_insert_watchpoint (CORE_ADDR
 
   debug_registers[2 * idx] = dbr_addr;
   debug_registers[2 * idx + 1] = dbr_mask;
-  ALL_LWPS (lp, ptid)
+  ALL_LWPS (lp)
     {
-      store_debug_register_pair (ptid, idx, &dbr_addr, &dbr_mask);
-      enable_watchpoints_in_psr (ptid);
+      store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask);
+      enable_watchpoints_in_psr (lp->ptid);
     }
 
   return 0;
@@ -603,15 +602,14 @@ ia64_linux_remove_watchpoint (CORE_ADDR
       if ((dbr_mask & (0x3UL << 62)) && addr == (CORE_ADDR) dbr_addr)
 	{
 	  struct lwp_info *lp;
-	  ptid_t ptid;
 
 	  debug_registers[2 * idx] = 0;
 	  debug_registers[2 * idx + 1] = 0;
 	  dbr_addr = 0;
 	  dbr_mask = 0;
 
-	  ALL_LWPS (lp, ptid)
-	    store_debug_register_pair (ptid, idx, &dbr_addr, &dbr_mask);
+	  ALL_LWPS (lp)
+	    store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask);
 
 	  return 0;
 	}
Index: src/gdb/mips-linux-nat.c
===================================================================
--- src.orig/gdb/mips-linux-nat.c	2011-10-07 16:37:10.089109957 +0100
+++ src/gdb/mips-linux-nat.c	2011-10-07 16:45:59.529110141 +0100
@@ -871,12 +871,11 @@ static int
 write_watchpoint_regs (void)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   int tid;
 
-  ALL_LWPS (lp, ptid)
+  ALL_LWPS (lp)
     {
-      tid = ptid_get_lwp (ptid);
+      tid = ptid_get_lwp (lp->ptid);
       if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1)
 	perror_with_name (_("Couldn't write debug register"));
     }
Index: src/gdb/ppc-linux-nat.c
===================================================================
--- src.orig/gdb/ppc-linux-nat.c	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/ppc-linux-nat.c	2011-10-07 16:45:59.529110141 +0100
@@ -1654,7 +1654,6 @@ static int
 ppc_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
 				  struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
 
@@ -1681,8 +1680,8 @@ ppc_linux_insert_hw_breakpoint (struct g
       p.addr2 = 0;
     }
 
-  ALL_LWPS (lp, ptid)
-    booke_insert_point (&p, TIDGET (ptid));
+  ALL_LWPS (lp)
+    booke_insert_point (&p, TIDGET (lp->ptid));
 
   return 0;
 }
@@ -1691,7 +1690,6 @@ static int
 ppc_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
 				  struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
 
@@ -1718,8 +1716,8 @@ ppc_linux_remove_hw_breakpoint (struct g
       p.addr2 = 0;
     }
 
-  ALL_LWPS (lp, ptid)
-    booke_remove_point (&p, TIDGET (ptid));
+  ALL_LWPS (lp)
+    booke_remove_point (&p, TIDGET (lp->ptid));
 
   return 0;
 }
@@ -1748,7 +1746,6 @@ static int
 ppc_linux_insert_mask_watchpoint (struct target_ops *ops, CORE_ADDR addr,
 				  CORE_ADDR mask, int rw)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
 
@@ -1762,8 +1759,8 @@ ppc_linux_insert_mask_watchpoint (struct
   p.addr2 = mask;
   p.condition_value = 0;
 
-  ALL_LWPS (lp, ptid)
-    booke_insert_point (&p, TIDGET (ptid));
+  ALL_LWPS (lp)
+    booke_insert_point (&p, TIDGET (lp->ptid));
 
   return 0;
 }
@@ -1777,7 +1774,6 @@ static int
 ppc_linux_remove_mask_watchpoint (struct target_ops *ops, CORE_ADDR addr,
 				  CORE_ADDR mask, int rw)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
 
@@ -1791,8 +1787,8 @@ ppc_linux_remove_mask_watchpoint (struct
   p.addr2 = mask;
   p.condition_value = 0;
 
-  ALL_LWPS (lp, ptid)
-    booke_remove_point (&p, TIDGET (ptid));
+  ALL_LWPS (lp)
+    booke_remove_point (&p, TIDGET (lp->ptid));
 
   return 0;
 }
@@ -2059,7 +2055,6 @@ ppc_linux_insert_watchpoint (CORE_ADDR a
 			     struct expression *cond)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   int ret = -1;
 
   if (have_ptrace_booke_interface ())
@@ -2068,8 +2063,8 @@ ppc_linux_insert_watchpoint (CORE_ADDR a
 
       create_watchpoint_request (&p, addr, len, rw, cond, 1);
 
-      ALL_LWPS (lp, ptid)
-	booke_insert_point (&p, TIDGET (ptid));
+      ALL_LWPS (lp)
+	booke_insert_point (&p, TIDGET (lp->ptid));
 
       ret = 0;
     }
@@ -2112,8 +2107,8 @@ ppc_linux_insert_watchpoint (CORE_ADDR a
 
       saved_dabr_value = dabr_value;
 
-      ALL_LWPS (lp, ptid)
-	if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0,
+      ALL_LWPS (lp)
+	if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (lp->ptid), 0,
 		    saved_dabr_value) < 0)
 	  return -1;
 
@@ -2128,7 +2123,6 @@ ppc_linux_remove_watchpoint (CORE_ADDR a
 			     struct expression *cond)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   int ret = -1;
 
   if (have_ptrace_booke_interface ())
@@ -2137,16 +2131,16 @@ ppc_linux_remove_watchpoint (CORE_ADDR a
 
       create_watchpoint_request (&p, addr, len, rw, cond, 0);
 
-      ALL_LWPS (lp, ptid)
-	booke_remove_point (&p, TIDGET (ptid));
+      ALL_LWPS (lp)
+	booke_remove_point (&p, TIDGET (lp->ptid));
 
       ret = 0;
     }
   else
     {
       saved_dabr_value = 0;
-      ALL_LWPS (lp, ptid)
-	if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0,
+      ALL_LWPS (lp)
+	if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (lp->ptid), 0,
 		    saved_dabr_value) < 0)
 	  return -1;
 
Index: src/gdb/s390-nat.c
===================================================================
--- src.orig/gdb/s390-nat.c	2011-10-07 16:37:10.099109957 +0100
+++ src/gdb/s390-nat.c	2011-10-07 16:45:59.529110141 +0100
@@ -339,7 +339,6 @@ s390_insert_watchpoint (CORE_ADDR addr,
 			struct expression *cond)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   struct watch_area *area = xmalloc (sizeof (struct watch_area));
 
   if (!area)
@@ -351,8 +350,8 @@ s390_insert_watchpoint (CORE_ADDR addr,
   area->next = watch_base;
   watch_base = area;
 
-  ALL_LWPS (lp, ptid)
-    s390_fix_watch_points (ptid);
+  ALL_LWPS (lp)
+    s390_fix_watch_points (lp->ptid);
   return 0;
 }
 
@@ -361,7 +360,6 @@ s390_remove_watchpoint (CORE_ADDR addr,
 			struct expression *cond)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   struct watch_area *area, **parea;
 
   for (parea = &watch_base; *parea; parea = &(*parea)->next)
@@ -380,8 +378,8 @@ s390_remove_watchpoint (CORE_ADDR addr,
   *parea = area->next;
   xfree (area);
 
-  ALL_LWPS (lp, ptid)
-    s390_fix_watch_points (ptid);
+  ALL_LWPS (lp)
+    s390_fix_watch_points (lp->ptid);
   return 0;
 }
 


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