From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24891 invoked by alias); 2 Dec 2005 11:48:24 -0000 Received: (qmail 24883 invoked by uid 22791); 2 Dec 2005 11:48:23 -0000 X-Spam-Check-By: sourceware.org Received: from lon-del-03.spheriq.net (HELO lon-del-03.spheriq.net) (195.46.50.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 02 Dec 2005 11:48:21 +0000 Received: from lon-out-03.spheriq.net ([195.46.50.131]) by lon-del-03.spheriq.net with ESMTP id jB2BmIAQ013689 for ; Fri, 2 Dec 2005 11:48:18 GMT Received: from lon-cus-01.spheriq.net (lon-cus-01.spheriq.net [195.46.50.37]) by lon-out-03.spheriq.net with ESMTP id jB2BmGod029219 for ; Fri, 2 Dec 2005 11:48:17 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by lon-cus-01.spheriq.net with ESMTP id jB2BmFjV031842 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Fri, 2 Dec 2005 11:48:16 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5AEEADA43; Fri, 2 Dec 2005 11:48:04 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id F16C7473D7; Fri, 2 Dec 2005 11:51:09 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9466F75994; Fri, 2 Dec 2005 11:51:09 +0000 (UTC) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EB87A473DF; Fri, 2 Dec 2005 11:51:08 +0000 (GMT) Received: from [164.129.15.13] (terrorhawk.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CHA54552 (AUTH "andrew stubbs"); Fri, 2 Dec 2005 11:48:01 GMT Message-ID: <439033E8.5020505@st.com> Date: Fri, 02 Dec 2005 13:05:00 -0000 From: Andrew STUBBS User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) MIME-Version: 1.0 To: Jim Blandy Cc: gdb-patches@sources.redhat.com Subject: Re: [PATCH] init-if-undefined command References: <437B3E56.3080306@st.com> <8f2776cb0511292141t2f9711a2l9633236db737e67b@mail.gmail.com> <438DB351.2050500@st.com> <20051130190311.GA25377@nevyn.them.org> <8f2776cb0511301501t4eb7bb50w484427fd892f5a58@mail.gmail.com> <438EE3F8.70103@st.com> <8f2776cb0512011449y1e3b1b27r80de4669b74bca8e@mail.gmail.com> In-Reply-To: <8f2776cb0512011449y1e3b1b27r80de4669b74bca8e@mail.gmail.com> Content-Type: multipart/mixed; boundary="------------010005020100060904030701" X-O-Spoofed: Not Scanned X-O-General-Status: No X-O-Spam1-Status: Not Scanned X-O-Spam2-Status: Not Scanned X-O-URL-Status: Not Scanned X-O-Virus1-Status: No X-O-Virus2-Status: Not Scanned X-O-Virus3-Status: No X-O-Virus4-Status: No X-O-Virus5-Status: Not Scanned X-O-Image-Status: Not Scanned X-O-Attach-Status: Not Scanned X-SpheriQ-Ver: 4.2.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00046.txt.bz2 This is a multi-part message in MIME format. --------------010005020100060904030701 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 150 Jim Blandy wrote: > This looks okay. Thanks. I have committed the attached. This includes the NEWS incorporating Eli's suggestions. Andrew Stubbs --------------010005020100060904030701 Content-Type: text/plain; name="init-if-undefined.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="init-if-undefined.patch" Content-length: 4255 2005-12-02 Andrew Stubbs * value.c (init_if_undefined_command): New function. (_initialize_values): Add command init-if-undefined. * NEWS (Changes since GDB 6.3): Rename to 'Changes in GDB 6.4'. (Changes since GDB 6.4): New section. Mention new command init-if-undefined. doc/ * gdb.texinfo (Convenience variables): Add init-if-undefined command. Index: src/gdb/value.c =================================================================== --- src.orig/gdb/value.c 2005-12-02 10:54:11.000000000 +0000 +++ src/gdb/value.c 2005-12-02 11:29:50.000000000 +0000 @@ -727,6 +727,39 @@ show_values (char *num_exp, int from_tty static struct internalvar *internalvars; +/* If the variable does not already exist create it and give it the value given. + If no value is given then the default is zero. */ +static void +init_if_undefined_command (char* args, int from_tty) +{ + struct internalvar* intvar; + + /* Parse the expression - this is taken from set_command(). */ + struct expression *expr = parse_expression (args); + register struct cleanup *old_chain = + make_cleanup (free_current_contents, &expr); + + /* Validate the expression. + Was the expression an assignment? + Or even an expression at all? */ + if (expr->nelts == 0 || expr->elts[0].opcode != BINOP_ASSIGN) + error (_("Init-if-undefined requires an assignment expression.")); + + /* Extract the variable from the parsed expression. + In the case of an assign the lvalue will be in elts[1] and elts[2]. */ + if (expr->elts[1].opcode != OP_INTERNALVAR) + error (_("The first parameter to init-if-undefined should be a GDB variable.")); + intvar = expr->elts[2].internalvar; + + /* Only evaluate the expression if the lvalue is void. + This may still fail if the expresssion is invalid. */ + if (TYPE_CODE (value_type (intvar->value)) == TYPE_CODE_VOID) + evaluate_expression (expr); + + do_cleanups (old_chain); +} + + /* Look up an internal variable with name NAME. NAME should not normally include a dollar sign. @@ -1639,4 +1672,11 @@ A few convenience variables are given va add_cmd ("values", no_class, show_values, _("Elements of value history around item number IDX (or last ten)."), &showlist); + + add_com ("init-if-undefined", class_vars, init_if_undefined_command, _("\ +Initialize a convenience variable if necessary.\n\ +init-if-undefined VARIABLE = EXPRESSION\n\ +Set an internal VARIABLE to the result of the EXPRESSION if it does not\n\ +exist or does not contain a value. The EXPRESSION is not evaluated if the\n\ +VARIABLE is already initialized.")); } Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2005-12-02 11:29:50.000000000 +0000 +++ src/gdb/doc/gdb.texinfo 2005-12-02 11:29:50.000000000 +0000 @@ -6131,6 +6131,18 @@ variable, when used as an expression, ha @item show convenience Print a list of convenience variables used so far, and their values. Abbreviated @code{show conv}. + +@kindex init-if-undefined +@cindex convenience variables, initializing +@item init-if-undefined $@var{variable} = @var{expression} +Set a convenience variable if it has not already been set. This is useful +for user-defined commands that keep some state. It is similar, in concept, +to using local static variables with initializers in C (except that +convenience variables are global). It can also be used to allow users to +override default values used in a command script. + +If the variable is already defined then the expression is not evaluated so +any side-effects do not occur. @end table One of the ways to use a convenience variable is as a counter to be Index: src/gdb/NEWS =================================================================== --- src.orig/gdb/NEWS 2005-12-02 10:54:11.000000000 +0000 +++ src/gdb/NEWS 2005-12-02 11:33:01.000000000 +0000 @@ -1,7 +1,14 @@ What has changed in GDB? (Organized release by release) -*** Changes since GDB 6.3 +*** Changes since GDB 6.4 + +* New commands + +init-if-undefined Initialize a convenience variable, but + only if it doesn't already have a value. + +*** Changes in GDB 6.4 * New native configurations --------------010005020100060904030701--