Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Cc: Ulrich Weigand <uweigand@de.ibm.com>
Subject: [PATCH 2/6] S390: Migrate watch areas from list to VEC type
Date: Thu, 15 Sep 2016 12:02:00 -0000	[thread overview]
Message-ID: <1473940907-4449-1-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1473940399-2891-1-git-send-email-arnez@linux.vnet.ibm.com>

For S390, the list of active watchpoints is maintained in a list based
at "watch_base".  This refactors the list to a vector "watch_areas".

gdb/ChangeLog:

	* s390-linux-nat.c (s390_watch_area): New typedef.  Define a VEC.
	(watch_base): Remove variable.
	(watch_areas): New variable.
	(s390_stopped_by_watchpoint): Transform operations on the
	watch_base list to equivalent operations on the watch_areas VEC.
	(s390_prepare_to_resume): Likewise.
	(s390_insert_watchpoint): Likewise.
	(s390_remove_watchpoint): Likewise.
---
 gdb/s390-linux-nat.c | 71 +++++++++++++++++++++++++---------------------------
 1 file changed, 34 insertions(+), 37 deletions(-)

diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
index 1e937f9..13bf7fd 100644
--- a/gdb/s390-linux-nat.c
+++ b/gdb/s390-linux-nat.c
@@ -436,14 +436,15 @@ s390_linux_store_inferior_registers (struct target_ops *ops,
    The only thing we actually need is the total address space area
    spanned by the watchpoints.  */
 
-struct watch_area
+typedef struct watch_area
 {
-  struct watch_area *next;
   CORE_ADDR lo_addr;
   CORE_ADDR hi_addr;
-};
+} s390_watch_area;
+
+DEF_VEC_O (s390_watch_area);
 
-static struct watch_area *watch_base = NULL;
+VEC_s390_watch_area *watch_areas = NULL;
 
 static int
 s390_stopped_by_watchpoint (struct target_ops *ops)
@@ -453,7 +454,7 @@ s390_stopped_by_watchpoint (struct target_ops *ops)
   int result;
 
   /* Speed up common case.  */
-  if (!watch_base)
+  if (VEC_empty (s390_watch_area, watch_areas))
     return 0;
 
   parea.len = sizeof (per_lowcore);
@@ -487,7 +488,8 @@ s390_prepare_to_resume (struct lwp_info *lp)
   ptrace_area parea;
 
   CORE_ADDR watch_lo_addr = (CORE_ADDR)-1, watch_hi_addr = 0;
-  struct watch_area *area;
+  unsigned ix;
+  s390_watch_area *area;
   struct arch_lwp_info *lp_priv = lwp_arch_private_info (lp);
 
   if (lp_priv == NULL || !lp_priv->per_info_changed)
@@ -499,20 +501,22 @@ s390_prepare_to_resume (struct lwp_info *lp)
   if (tid == 0)
     tid = ptid_get_pid (ptid_of_lwp (lp));
 
-  for (area = watch_base; area; area = area->next)
-    {
-      watch_lo_addr = min (watch_lo_addr, area->lo_addr);
-      watch_hi_addr = max (watch_hi_addr, area->hi_addr);
-    }
-
   parea.len = sizeof (per_info);
   parea.process_addr = (addr_t) & per_info;
   parea.kernel_addr = offsetof (struct user_regs_struct, per_info);
   if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea, 0) < 0)
     perror_with_name (_("Couldn't retrieve watchpoint status"));
 
-  if (watch_base)
+  if (!VEC_empty (s390_watch_area, watch_areas))
     {
+      for (ix = 0;
+	   VEC_iterate (s390_watch_area, watch_areas, ix, area);
+	   ix++)
+	{
+	  watch_lo_addr = min (watch_lo_addr, area->lo_addr);
+	  watch_hi_addr = max (watch_hi_addr, area->hi_addr);
+	}
+
       per_info.control_regs.bits.em_storage_alteration = 1;
       per_info.control_regs.bits.storage_alt_space_ctl = 1;
     }
@@ -575,16 +579,11 @@ s390_insert_watchpoint (struct target_ops *self,
 			CORE_ADDR addr, int len, enum target_hw_bp_type type,
 			struct expression *cond)
 {
-  struct watch_area *area = XNEW (struct watch_area);
+  s390_watch_area area;
 
-  if (!area)
-    return -1;
-
-  area->lo_addr = addr;
-  area->hi_addr = addr + len - 1;
-
-  area->next = watch_base;
-  watch_base = area;
+  area.lo_addr = addr;
+  area.hi_addr = addr + len - 1;
+  VEC_safe_push (s390_watch_area, watch_areas, &area);
 
   return s390_refresh_per_info ();
 }
@@ -594,25 +593,23 @@ s390_remove_watchpoint (struct target_ops *self,
 			CORE_ADDR addr, int len, enum target_hw_bp_type type,
 			struct expression *cond)
 {
-  struct watch_area *area, **parea;
-
-  for (parea = &watch_base; *parea; parea = &(*parea)->next)
-    if ((*parea)->lo_addr == addr
-	&& (*parea)->hi_addr == addr + len - 1)
-      break;
+  unsigned ix;
+  s390_watch_area *area;
 
-  if (!*parea)
+  for (ix = 0;
+       VEC_iterate (s390_watch_area, watch_areas, ix, area);
+       ix++)
     {
-      fprintf_unfiltered (gdb_stderr,
-			  "Attempt to remove nonexistent watchpoint.\n");
-      return -1;
+      if (area->lo_addr == addr && area->hi_addr == addr + len - 1)
+	{
+	  VEC_unordered_remove (s390_watch_area, watch_areas, ix);
+	  return s390_refresh_per_info ();
+	}
     }
 
-  area = *parea;
-  *parea = area->next;
-  xfree (area);
-
-  return s390_refresh_per_info ();
+  fprintf_unfiltered (gdb_stderr,
+		      "Attempt to remove nonexistent watchpoint.\n");
+  return -1;
 }
 
 static int
-- 
2.5.0


  parent reply	other threads:[~2016-09-15 12:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-15 11:53 [PATCH 0/6] S390: Watchpoint enhancements and hardware breakpoints Andreas Arnez
2016-09-15 11:54 ` [PATCH] Fix order of inferiors in "thread apply all" Andreas Arnez
2016-09-15 12:03   ` Andreas Arnez
2016-09-15 11:59 ` [PATCH 1/6] S390: Avoid direct access to lwp_info structure Andreas Arnez
2016-09-15 12:01 ` [PATCH 3/6] S390: Multi-inferior watchpoint support Andreas Arnez
2016-09-15 12:02 ` [PATCH 4/6] S390: Enable "maint set show-debug-regs" Andreas Arnez
2016-09-15 12:02 ` Andreas Arnez [this message]
2016-09-15 12:02 ` [PATCH 6/6] S390: Hardware breakpoint support Andreas Arnez
2016-09-15 12:02 ` [PATCH 5/6] linux-nat: Add function lwp_is_stepping Andreas Arnez
2016-09-15 15:08   ` Yao Qi
2016-09-15 14:11 ` [PATCH 0/6] S390: Watchpoint enhancements and hardware breakpoints Pedro Alves
2016-09-16 12:43   ` Ulrich Weigand
2016-09-16 15:43     ` Pedro Alves
2016-09-16 17:30       ` Andreas Arnez
2016-09-15 14:58 ` Yao Qi
2016-09-15 17:14   ` Andreas Arnez

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=1473940907-4449-1-git-send-email-arnez@linux.vnet.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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