From: Vladimir Prus <ghost@cs.msu.su>
To: gdb-patches@sources.redhat.com
Subject: Re: [Patch] Try2: -var-evaluate-expression [-f FORMAT] NAME
Date: Wed, 02 Apr 2008 16:26:00 -0000 [thread overview]
Message-ID: <ft019v$62t$1@ger.gmane.org> (raw)
In-Reply-To: <6D19CA8D71C89C43A057926FE0D4ADAA04290FFC@ecamlmw720.eamcs.ericsson.se>
Marc Khouzam wrote:
> 2008-04-01  Marc Khouzam  <marc.khouzam@ericsson.com>
>
> Â Â Â Â * mi/mi-cmd-var.c: Include "mi-getopt.h".
> Â Â Â Â (mi_parse_format): New. Â Factored out from mi_cmd_var_set_format.
> Â Â Â Â (mi_cmd_var_set_format): Use new mi_parse_format.
> Â Â Â Â (mi_cmd_var_evaluate_expression): Support for -f option to specify
> Â Â Â Â format.
> Â Â Â Â * Makefile.in (mi-cmd-var.o): Update dependencies.
>
> Â Â Â Â * varobj.h (varobj_get_formatted_value): Declare.
> Â Â Â Â * varobj.c (my_value_of_variable): Added format parameter.
> Â Â Â Â (cplus_value_of_variable): Likewise.
> Â Â Â Â (java_value_of_variable): Likewise.
> Â Â Â Â (*(value_of_variable)): Likewise.
Is '*(value_of_variable)' really a name of a function? :-)
> Â Â Â Â (c_value_of_variable): Likewise. Â Evaluate expression based
> Â Â Â Â on format parameter.
> Â Â Â Â (varobj_get_formatted_value): New.
> Â Â Â Â (varobj_get_value): Added format parameter to method call.
> +/* Parse a string argument into a format value. Â */
As meta-remark, can you pass the "-p" option to diff when generating patches,
so that function names are present right in the patch?
> +
> +static enum varobj_display_formats
> +mi_parse_format (const char *arg)
> +{
> + Â int len;
> +
> + Â len = strlen (arg);
> +
> + Â if (strncmp (arg, "natural", len) == 0)
> + Â Â return FORMAT_NATURAL;
> + Â else if (strncmp (arg, "binary", len) == 0)
> + Â Â return FORMAT_BINARY;
> + Â else if (strncmp (arg, "decimal", len) == 0)
> + Â Â return FORMAT_DECIMAL;
> + Â else if (strncmp (arg, "hexadecimal", len) == 0)
> + Â Â return FORMAT_HEXADECIMAL;
> + Â else if (strncmp (arg, "octal", len) == 0)
> + Â Â return FORMAT_OCTAL;
> + Â else
> + Â Â error (_("Unknown display format: must be: \"natural\", \"binary\", \"decimal\",
\"hexadecimal\", or \"octal\""));
> +}
> +
> Â enum mi_cmd_result
> Â mi_cmd_var_set_format (char *command, char **argv, int argc)
> Â {
> Â Â enum varobj_display_formats format;
> - Â int len;
> Â Â struct varobj *var;
> Â Â char *formspec;
> Â
> @@ -216,21 +239,8 @@
> Â Â if (formspec == NULL)
> Â Â Â error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\",
\"decimal\", \"hexadecimal\", or \"octal\""));
Can we drop this...
> Â
> - Â len = strlen (formspec);
> -
> - Â if (strncmp (formspec, "natural", len) == 0)
> - Â Â format = FORMAT_NATURAL;
> - Â else if (strncmp (formspec, "binary", len) == 0)
> - Â Â format = FORMAT_BINARY;
> - Â else if (strncmp (formspec, "decimal", len) == 0)
> - Â Â format = FORMAT_DECIMAL;
> - Â else if (strncmp (formspec, "hexadecimal", len) == 0)
> - Â Â format = FORMAT_HEXADECIMAL;
> - Â else if (strncmp (formspec, "octal", len) == 0)
> - Â Â format = FORMAT_OCTAL;
> - Â else
> - Â Â error (_("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\",
\"decimal\", \"hexadecimal\", or \"octal\""));
> -
> + Â format = mi_parse_format (formspec);
..and make mi_parse_format emit an error message both if the passed format
is NULL and when it's not NULL, but unknown?
> Â Â /* Set the format of VAR to given format */
> Â Â varobj_set_display_format (var, format);
> Â
> @@ -493,15 +503,58 @@
> Â {
> Â Â struct varobj *var;
> Â
> - Â if (argc != 1)
> - Â Â error (_("mi_cmd_var_evaluate_expression: Usage: NAME."));
> + Â enum varobj_display_formats format;
> + Â int formatFound;
> + Â int optind;
> + Â char *optarg;
> + Â Â
> + Â enum opt
> + Â Â {
> + Â Â Â OP_FORMAT
> + Â Â };
> + Â static struct mi_opt opts[] =
> + Â {
> + Â Â {"f", OP_FORMAT, 1},
> + Â Â { 0, 0, 0 }
> + Â };
> +
> + Â /* Parse arguments */
> + Â format = FORMAT_NATURAL;
> + Â formatFound = 0;
> + Â optind = 0;
> + Â while (1)
> + Â Â {
> + Â Â Â int opt = mi_getopt ("mi_cmd_var_evaluate_expression", argc, argv, opts, &optind, &optarg);
> + Â Â Â if (opt < 0)
> + Â Â Â break;
> + Â Â Â switch ((enum opt) opt)
> + Â Â Â {
> + Â Â Â case OP_FORMAT:
> + Â Â Â Â if (formatFound)
> + Â Â Â Â Â error (_("mi_cmd_var_evaluate_expression: cannot specify format more than once"));
> + Â
I think the current position is that error messages need not name the name of function, since
if this error message ever make it to the user, he has no idea what
is "mi_cmd_var_evaluate_expression", and when debugging GDB or frontend, it's not very
helpful. Can you drop that prefix, here, and everywhere?
> + Â Â Â Â format = mi_parse_format (optarg);
> + Â Â Â Â formatFound = 1;
> + Â Â Â Â break;
> + Â Â Â }
> + Â Â }
> Â
> - Â /* Get varobj handle, if a valid var obj name was specified */
> - Â var = varobj_get_handle (argv[0]);
> + Â if (optind >= argc)
> + Â Â error (_("mi_cmd_var_evaluate_expression: Usage: [-f FORMAT] NAME"));
> + Â
> + Â if (optind < argc - 1)
> + Â Â error (_("mi_cmd_var_evaluate_expression: Garbage at end of command"));
> +
> + Â Â /* Get varobj handle, if a valid var obj name was specified */
> + Â var = varobj_get_handle (argv[optind]);
> Â Â if (var == NULL)
> Â Â Â error (_("mi_cmd_var_evaluate_expression: Variable object not found"));
> + Â
> + Â if (formatFound)
> + Â Â ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format));
It's not the problem introduced by your patch, but still -- it appears we have a memory
leak here. In c_value_of_variable, we either xstrdup the value, or use value_get_print_value
which uses ui_file_xstrdup, so we end up with newly allocated char* pointer. I think
we have to free it here.
> + Â else
> + Â Â ui_out_field_string (uiout, "value", varobj_get_value (var));
> Â
> - Â ui_out_field_string (uiout, "value", varobj_get_value (var));
> Â Â return MI_CMD_DONE;
The code patch is OK with those changes, thanks!
Eli, does the doc patch look good for you?
- Volodya
next prev parent reply other threads:[~2008-04-02 13:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-01 14:33 Marc Khouzam
2008-04-02 0:17 ` Nick Roberts
2008-04-02 13:23 ` Marc Khouzam
2008-04-02 16:26 ` Vladimir Prus [this message]
2008-04-02 18:20 ` Michael Snyder
2008-04-02 18:50 ` Daniel Jacobowitz
2008-04-02 19:10 ` Marc Khouzam
2008-04-02 21:26 ` Marc Khouzam
2008-04-03 4:42 ` Nick Roberts
2008-04-04 15:07 ` Marc Khouzam
2008-04-06 6:42 ` OT: IDES [was RE: Re: [Patch] Try2: -var-evaluate-expression [-f FORMAT] NAME] Nick Roberts
2008-04-06 22:46 ` Daniel Jacobowitz
2008-04-04 15:17 ` [Patch] Try2: -var-evaluate-expression [-f FORMAT] NAME Vladimir Prus
2008-04-08 17:04 ` Marc Khouzam
2008-04-08 22:24 ` Eli Zaretskii
2008-04-09 14:54 ` Marc Khouzam
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='ft019v$62t$1@ger.gmane.org' \
--to=ghost@cs.msu.su \
--cc=gdb-patches@sources.redhat.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