From: Andrew STUBBS <andrew.stubbs@st.com>
To: Jim Blandy <jimb@red-bean.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [PATCH] init-if-undefined command
Date: Fri, 02 Dec 2005 13:05:00 -0000 [thread overview]
Message-ID: <439033E8.5020505@st.com> (raw)
In-Reply-To: <8f2776cb0512011449y1e3b1b27r80de4669b74bca8e@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 150 bytes --]
Jim Blandy wrote:
> This looks okay.
Thanks.
I have committed the attached. This includes the NEWS incorporating
Eli's suggestions.
Andrew Stubbs
[-- Attachment #2: init-if-undefined.patch --]
[-- Type: text/plain, Size: 4255 bytes --]
2005-12-02 Andrew Stubbs <andrew.stubbs@st.com>
* 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
prev parent reply other threads:[~2005-12-02 11:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-16 14:58 Andrew STUBBS
2005-11-16 20:00 ` Eli Zaretskii
2005-11-16 20:09 ` Joel Brobecker
2005-11-17 1:19 ` Jim Blandy
[not found] ` <8f2776cb0511161507j33208ae1k1e0753b72b992c73@mail.gmail.com>
[not found] ` <20051116233326.GZ1635@adacore.com>
[not found] ` <8f2776cb0511161602wb469964xdd904aab0d70d2a6@mail.gmail.com>
2005-11-17 3:45 ` Joel Brobecker
2005-11-17 4:47 ` Daniel Jacobowitz
2005-11-30 1:58 ` Andrew STUBBS
2005-11-30 13:59 ` Jim Blandy
2005-11-30 20:28 ` Andrew STUBBS
2005-11-30 21:20 ` Jim Blandy
2005-11-30 23:01 ` Daniel Jacobowitz
[not found] ` <8f2776cb0511301501t4eb7bb50w484427fd892f5a58@mail.gmail.com>
2005-12-01 11:55 ` Andrew STUBBS
2005-12-01 17:32 ` Andrew STUBBS
2005-12-01 23:38 ` Jim Blandy
2005-12-02 10:44 ` Andrew STUBBS
2005-12-02 10:33 ` Eli Zaretskii
2005-12-02 11:18 ` Andrew STUBBS
2005-12-01 22:50 ` Jim Blandy
2005-12-02 13:05 ` Andrew STUBBS [this message]
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=439033E8.5020505@st.com \
--to=andrew.stubbs@st.com \
--cc=gdb-patches@sources.redhat.com \
--cc=jimb@red-bean.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