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]

Re: [patch] delete a range of display numbers


Thank you for this suggestion.  I added the modification you asked for
in the attached file.

Guillaume.

On Fri, Feb 18, 2011 at 11:30 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Fri, 18 Feb 2011 10:36:18 +0100
>> From: Guillaume Leconte <guillaume.leconte@gmail.com>
>>
>> Notice that I've change the prototype of delete_display() in order
>> to have a silent return in case of unknown number. ?If you have set
>> the display numbers 1, 2, 3 and 5, you can remove 2-5 without any
>> error messages (number 4 is missing in the list). ?As a consequence,
>> you can also remove out of bound numbers, as in 'delete display 5-42'
>> without having gdb complaining.
>
> I think it's a convenient feature, but doing this silently may not be
> a good idea. ?How about displaying a note about this? ?Something like
>
> ?(Ignored some display numbers.)
>
> WDYT?
>



-- 
"A fellow of infinite jest, of most excellent fancy."
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 29ffbf5..8ab1a54 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1557,13 +1557,18 @@ clear_displays (void)
 
 /* Delete the auto-display number NUM.  */
 
-static void
-delete_display (int num)
+static int
+delete_display (int num, int ignore)
 {
   struct display *d1, *d;
 
   if (!display_chain)
-    error (_("No display number %d."), num);
+    {
+      if (ignore)
+        return 1;
+      printf_filtered (_("No display number %d.\n"), num);
+      return -1;
+    }
 
   if (display_chain->number == num)
     {
@@ -1575,7 +1580,12 @@ delete_display (int num)
     for (d = display_chain;; d = d->next)
       {
 	if (d->next == 0)
-	  error (_("No display number %d."), num);
+          {
+            if (ignore)
+                return 1;
+            printf_filtered (_("No display number %d.\n"), num);
+            return -1;
+          }
 	if (d->next->number == num)
 	  {
 	    d1 = d->next;
@@ -1584,6 +1594,42 @@ delete_display (int num)
 	    break;
 	  }
       }
+
+  return 0;
+}
+
+static int
+set_int_from_str(char *str, int *result, char *end_delim)
+{
+  char *p;
+  int ret;
+  char *occurrence;
+
+  p = str;
+  ret = -1;
+
+  if (! str)
+    goto err;
+
+  while (p && *p && (' ' == *p || '\t' == *p))
+    p++;
+
+  while (p && *p && *p >= '0' && *p <= '9')
+    p++;
+
+  if (p && *p)
+    {
+      occurrence = strpbrk(p, end_delim);
+      if (! occurrence || occurrence != p)
+        goto err;
+    }
+
+  if (result)
+    *result = atoi(str);
+
+  ret = 0;
+ err:
+  return ret;
 }
 
 /* Delete some values from the auto-display chain.
@@ -1595,6 +1641,9 @@ undisplay_command (char *args, int from_tty)
   char *p = args;
   char *p1;
   int num;
+  int lower, upper, i;
+  char *dash;
+  int err;
 
   if (args == 0)
     {
@@ -1604,23 +1653,52 @@ undisplay_command (char *args, int from_tty)
       return;
     }
 
-  while (*p)
+  dash = strchr(p, '-');
+  if (dash) /* remove all the display IDs within a range */
+    {
+      err = 0;
+
+      if (-1 == set_int_from_str(p, &lower, "- \t"))
+        error (_("Arguments must be display numbers."));
+
+      p = dash+1;
+      while (p && *p && (' ' == *p || '\t' == *p))
+        p++;
+
+      if (-1 == set_int_from_str(p, &upper, " \t"))
+        error (_("Arguments must be display numbers."));
+
+      for (i = lower; i <= upper; i++)
+        err += delete_display (i, 1);
+
+      /* since we called delete_display with 1 as the second argument,
+         we know that err is 0 or > 0.  It can not be negative. */
+      if (err)
+        printf_filtered (_("(Ignored some display numbers)\n"));
+
+      dont_repeat ();
+    }
+  else
     {
-      p1 = p;
-      while (*p1 >= '0' && *p1 <= '9')
-	p1++;
-      if (*p1 && *p1 != ' ' && *p1 != '\t')
-	error (_("Arguments must be display numbers."));
+      while (*p)
+        {
+          p1 = p;
+          while (*p1 >= '0' && *p1 <= '9')
+            p1++;
+          if (*p1 && *p1 != ' ' && *p1 != '\t')
+            error (_("Arguments must be display numbers."));
 
-      num = atoi (p);
+          num = atoi (p);
 
-      delete_display (num);
+          if (-1 == delete_display (num, 0))
+            return;
 
-      p = p1;
-      while (*p == ' ' || *p == '\t')
-	p++;
+          p = p1;
+          while (*p == ' ' || *p == '\t')
+            p++;
+        }
+      dont_repeat ();
     }
-  dont_repeat ();
 }
 
 /* Display a single auto-display.  

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