From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18270 invoked by alias); 18 Feb 2011 17:41:25 -0000 Received: (qmail 18146 invoked by uid 22791); 18 Feb 2011 17:41:22 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-outbound-2.vmware.com (HELO smtp-outbound-2.vmware.com) (65.115.85.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Feb 2011 17:41:14 +0000 Received: from mailhost2.vmware.com (mailhost2.vmware.com [10.16.67.167]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 346711A002; Fri, 18 Feb 2011 09:41:11 -0800 (PST) Received: from msnyder-server.eng.vmware.com (promd-2s-dhcp138.eng.vmware.com [10.20.124.138]) by mailhost2.vmware.com (Postfix) with ESMTP id 2AE838ED28; Fri, 18 Feb 2011 09:41:11 -0800 (PST) Message-ID: <4D5EAF36.2000908@vmware.com> Date: Fri, 18 Feb 2011 17:44:00 -0000 From: Michael Snyder User-Agent: Thunderbird 2.0.0.24 (X11/20101201) MIME-Version: 1.0 To: Guillaume Leconte CC: "gdb-patches@sourceware.org" Subject: Re: [patch] delete a range of display numbers References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00481.txt.bz2 Guillaume Leconte wrote: > I often have a bunch of display numbers when I use gdb. It's pretty > annoying to be unable to remove for example the N first ones I've > previously set. > > This patch allow the user to do this: > > (gdb) delete display 1-7 > > 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'm concerned about this. What happens if I want to delete 24, but by mistake I type "delete display 42"? If gdb fails silently, I will not be informed of my mistake. > > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index 29ffbf5..6f718c4 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -1420,7 +1420,7 @@ x_command (char *exp, int from_tty) > val = coerce_ref (val); > /* In rvalue contexts, such as this, functions are coerced into > pointers to functions. This makes "x/i main" work. */ > - if (/* last_format == 'i' && */ > + if (/* last_format == 'i' && */ > TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC > && VALUE_LVAL (val) == lval_memory) > next_address = value_address (val); > @@ -1558,12 +1558,17 @@ clear_displays (void) > /* Delete the auto-display number NUM. */ > > static void > -delete_display (int num) > +delete_display (int num, > + int ignore) > { > struct display *d1, *d; > > if (!display_chain) > - error (_("No display number %d."), num); > + { > + if (ignore) > + return; > + error (_("No display number %d."), num); > + } > > if (display_chain->number == num) > { > @@ -1575,7 +1580,11 @@ delete_display (int num) > for (d = display_chain;; d = d->next) > { > if (d->next == 0) > - error (_("No display number %d."), num); > + { > + if (ignore) > + return; > + error (_("No display number %d."), num); > + } > if (d->next->number == num) > { > d1 = d->next; > @@ -1586,6 +1595,42 @@ delete_display (int num) > } > } > > +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. > Specify the element numbers. */ > > @@ -1595,6 +1640,8 @@ undisplay_command (char *args, int from_tty) > char *p = args; > char *p1; > int num; > + int lower, upper, i; > + char *dash; > > if (args == 0) > { > @@ -1604,26 +1651,47 @@ undisplay_command (char *args, int from_tty) > return; > } > > - while (*p) > + dash = strchr(p, '-'); > + if (dash) /* remove all the display IDs within a range */ > + { > + 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++) > + delete_display(i, 1); > + > + 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); > + delete_display (num); > > - p = p1; > - while (*p == ' ' || *p == '\t') > - p++; > + p = p1; > + while (*p == ' ' || *p == '\t') > + p++; > + } > + dont_repeat (); > } > - dont_repeat (); > } >