Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Guillaume Leconte <guillaume.leconte@gmail.com>,
	Eli Zaretskii <eliz@gnu.org>
Subject: Re: [patch] delete a range of display numbers
Date: Fri, 18 Feb 2011 12:17:00 -0000	[thread overview]
Message-ID: <201102181159.00201.pedro@codesourcery.com> (raw)
In-Reply-To: <AANLkTi=Gpmr-Atf8zr5Ycf7Ct-sAp8H5atAYCovSOnAA@mail.gmail.com>

The "delete" breakpoint command accepts ranges as
well, and even has code that handles convenience
variables mixed with the numbers.  I think we should
reuse that instead of re-adding code that parses ranges.
Might as well make the "delete display" command
implementation look more like the "delete" command
implementation.  Here's a quick cut at it.

-- 
Pedro Alves

---
 gdb/breakpoint.c |    5 +---
 gdb/breakpoint.h |    2 +
 gdb/printcmd.c   |   62 ++++++++++++++++++++++++++++---------------------------
 3 files changed, 36 insertions(+), 33 deletions(-)

Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2011-02-18 10:13:06.000000000 +0000
+++ src/gdb/breakpoint.c	2011-02-18 10:36:37.487376996 +0000
@@ -573,8 +573,7 @@ get_number_trailer (char **pp, int trail
   char *p = *pp;
 
   if (p == NULL)
-    /* Empty line means refer to the last breakpoint.  */
-    return breakpoint_count;
+    return 0;
   else if (*p == '$')
     {
       /* Make a copy of the name, so we can null-terminate it
@@ -651,7 +650,7 @@ get_number (char **pp)
    is completed.  The call that completes the range will advance
    pointer PP past <number2>.  */
 
-int 
+int
 get_number_or_range (char **pp)
 {
   static int last_retval, end_value;
Index: src/gdb/breakpoint.h
===================================================================
--- src.orig/gdb/breakpoint.h	2011-02-08 09:31:08.000000000 +0000
+++ src/gdb/breakpoint.h	2011-02-18 10:55:56.367376999 +0000
@@ -1191,4 +1191,6 @@ extern struct breakpoint *iterate_over_b
 
 extern int user_breakpoint_p (struct breakpoint *);
 
+extern int get_number_or_range (char **pp);
+
 #endif /* !defined (BREAKPOINT_H) */
Index: src/gdb/printcmd.c
===================================================================
--- src.orig/gdb/printcmd.c	2011-02-01 15:27:37.000000000 +0000
+++ src/gdb/printcmd.c	2011-02-18 11:12:56.587376996 +0000
@@ -167,6 +167,11 @@ static struct display *display_chain;
 
 static int display_number;
 
+/* Walk the following statement or block through all displays.  */
+
+#define ALL_DISPLAYS(B)				\
+  for (B = display_chain; B; B = B->next)
+
 /* Prototypes for exported functions.  */
 
 void output_command (char *, int);
@@ -1555,35 +1560,26 @@ clear_displays (void)
     }
 }
 
-/* Delete the auto-display number NUM.  */
+/* Delete the auto-display DISPLAY.  */
 
 static void
-delete_display (int num)
+delete_display (struct display *display)
 {
-  struct display *d1, *d;
+  struct display *d;
 
-  if (!display_chain)
-    error (_("No display number %d."), num);
+  gdb_assert (display != NULL);
 
-  if (display_chain->number == num)
-    {
-      d1 = display_chain;
-      display_chain = d1->next;
-      free_display (d1);
-    }
-  else
-    for (d = display_chain;; d = d->next)
+  if (display_chain == display)
+    display_chain = display->next;
+
+  ALL_DISPLAYS (d)
+    if (d->next == display)
       {
-	if (d->next == 0)
-	  error (_("No display number %d."), num);
-	if (d->next->number == num)
-	  {
-	    d1 = d->next;
-	    d->next = d1->next;
-	    free_display (d1);
-	    break;
-	  }
+	d->next = display->next;
+	break;
       }
+
+  free_display (display);
 }
 
 /* Delete some values from the auto-display chain.
@@ -1607,18 +1603,24 @@ undisplay_command (char *args, int from_
   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 = get_number_or_range (&p1);
+      if (num == 0)
+	warning (_("bad display number at or near '%s'"), p);
+      else
+	{
+	  struct display *d;
 
-      delete_display (num);
+	  ALL_DISPLAYS (d)
+	    if (d->number == num)
+	      break;
+	  if (d == NULL)
+	    printf_unfiltered (_("No display number %d.\n"), num);
+	  else
+	    delete_display (d);
+	}
 
       p = p1;
-      while (*p == ' ' || *p == '\t')
-	p++;
     }
   dont_repeat ();
 }


  reply	other threads:[~2011-02-18 11:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  9:47 Guillaume Leconte
2011-02-18 10:30 ` Guillaume Leconte
2011-02-18 11:08 ` Eli Zaretskii
2011-02-18 11:48   ` Guillaume Leconte
2011-02-18 12:17     ` Pedro Alves [this message]
2011-02-18 14:41       ` Guillaume Leconte
2011-02-18 15:14       ` Tom Tromey
2011-02-18 15:58         ` Pedro Alves
2011-02-18 16:48           ` Tom Tromey
2011-02-18 16:57             ` Pedro Alves
2011-02-18 17:41               ` Eli Zaretskii
2011-02-18 17:54                 ` Pedro Alves
2011-02-18 17:54                   ` Michael Snyder
2011-02-18 18:06                     ` Pedro Alves
2011-03-14 21:24                       ` [patch+docs] make 'disable|enable display' also accept ranges (Re: [patch] delete a range of display numbers) Pedro Alves
2011-03-14 21:34                         ` Eli Zaretskii
2011-03-15 14:43                           ` Pedro Alves
2011-02-18 18:17                     ` [patch] delete a range of display numbers Eli Zaretskii
2011-02-18 17:52       ` Michael Snyder
2011-02-18 17:57         ` Pedro Alves
2011-02-18 17:44 ` Michael Snyder

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=201102181159.00201.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=guillaume.leconte@gmail.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