From: "Marc Khouzam" <marc.khouzam@ericsson.com>
To: "Daniel Jacobowitz" <drow@false.org>
Cc: "Nick Roberts" <nickrob@snap.net.nz>, <gdb-patches@sourceware.org>
Subject: RE: [Patch] -var-evaluate-expression NAME [FORMAT]
Date: Wed, 23 Jan 2008 17:04:00 -0000 [thread overview]
Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04290E59@ecamlmw720.eamcs.ericsson.se> (raw)
In-Reply-To: <20080123144006.GA5885@caradoc.them.org>
Here is a new version of the patch using Nick's suggestion.
I had a bit of trouble with the cleanup and am not sure
this is how it should be done.
Comments?
Marc
### Eclipse Workspace Patch 1.0
#P gdb
Index: mi/mi-cmd-var.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v
retrieving revision 1.44
diff -u -r1.44 mi-cmd-var.c
--- mi/mi-cmd-var.c 23 Jan 2008 06:13:44 -0000 1.44
+++ mi/mi-cmd-var.c 23 Jan 2008 16:59:00 -0000
@@ -190,11 +190,33 @@
return MI_CMD_DONE;
}
+/* Parse a string argument into a format value. */
+
+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;
@@ -211,21 +233,8 @@
if (formspec == NULL)
error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
- 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);
+
/* Set the format of VAR to given format */
varobj_set_display_format (var, format);
@@ -492,16 +501,25 @@
mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
{
struct varobj *var;
+ enum varobj_display_formats format;
- if (argc != 1)
- error (_("mi_cmd_var_evaluate_expression: Usage: NAME."));
+ if (argc != 1 &&
+ (argc != 3 || strcmp(argv[1], "-f") != 0))
+ error (_("mi_cmd_var_evaluate_expression: Usage: NAME [-f FORMAT]"));
/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
error (_("mi_cmd_var_evaluate_expression: Variable object not found"));
- ui_out_field_string (uiout, "value", varobj_get_value (var));
+ if (argc == 3)
+ {
+ format = mi_parse_format(argv[2]);
+ ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format));
+ }
+ else
+ ui_out_field_string (uiout, "value", varobj_get_value (var));
+
return MI_CMD_DONE;
}
Index: varobj.h
===================================================================
RCS file: /cvs/src/src/gdb/varobj.h,v
retrieving revision 1.14
diff -u -r1.14 varobj.h
--- varobj.h 1 Jan 2008 22:53:13 -0000 1.14
+++ varobj.h 23 Jan 2008 16:59:00 -0000
@@ -104,6 +104,9 @@
extern int varobj_get_attributes (struct varobj *var);
+extern char *varobj_get_formatted_value (struct varobj *var,
+ enum varobj_display_formats format);
+
extern char *varobj_get_value (struct varobj *var);
extern int varobj_set_value (struct varobj *var, char *expression);
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.99
diff -u -r1.99 varobj.c
--- varobj.c 1 Jan 2008 22:53:13 -0000 1.99
+++ varobj.c 23 Jan 2008 16:59:00 -0000
@@ -192,6 +192,9 @@
static struct cleanup *make_cleanup_free_variable (struct varobj *var);
+static struct cleanup *make_cleanup_set_format (struct varobj *var,
+ enum varobj_display_formats format);
+
static struct type *get_type (struct varobj *var);
static struct type *get_value_type (struct varobj *var);
@@ -854,6 +857,24 @@
return my_value_of_variable (var);
}
+char *
+varobj_get_formatted_value (struct varobj *var,
+ enum varobj_display_formats format)
+{
+ enum varobj_display_formats oldformat;
+ struct cleanup *old_chain;
+ char* value;
+
+ oldformat = var->format;
+ old_chain = make_cleanup_set_format (var, oldformat);
+
+ var->format = format;
+ value = my_value_of_variable (var);
+
+ do_cleanups (old_chain);
+ return value;
+}
+
/* Set the value of an object variable (if it is editable) to the
value of the given expression */
/* Note: Invokes functions that can call error() */
@@ -1543,6 +1564,36 @@
return make_cleanup (do_free_variable_cleanup, var);
}
+struct cleanup_set_format_struct
+{
+ struct varobj *var;
+ enum varobj_display_formats format;
+};
+
+static void
+do_set_format_cleanup (void *cleanup_set_format)
+{
+ struct cleanup_set_format_struct *cleanup_struct = cleanup_set_format;
+
+ varobj_set_display_format(cleanup_struct->var,
+ cleanup_struct->format);
+
+ xfree(cleanup_struct);
+}
+
+static struct cleanup *
+make_cleanup_set_format (struct varobj *var,
+ enum varobj_display_formats format)
+{
+ struct cleanup_set_format_struct *cleanup_struct;
+
+ cleanup_struct = XMALLOC (struct cleanup_set_format_struct);
+ cleanup_struct->var = var;
+ cleanup_struct->format = format;
+
+ return make_cleanup (do_set_format_cleanup, cleanup_struct);
+}
+
/* This returns the type of the variable. It also skips past typedefs
to return the real type of the variable.
next prev parent reply other threads:[~2008-01-23 17:04 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-22 20:38 Marc Khouzam
2008-01-23 3:04 ` Nick Roberts
2008-01-23 14:30 ` Marc Khouzam
2008-01-23 14:42 ` Daniel Jacobowitz
2008-01-23 17:04 ` Marc Khouzam [this message]
2008-01-23 22:09 ` Nick Roberts
2008-01-24 21:36 ` Marc Khouzam
2008-01-25 9:59 ` Eli Zaretskii
2008-01-29 21:45 ` Daniel Jacobowitz
2008-02-01 19:23 ` Marc Khouzam
2008-02-02 10:31 ` Eli Zaretskii
2008-02-03 19:43 ` Marc Khouzam
2008-02-03 20:01 ` Eli Zaretskii
2008-02-04 14:17 ` Marc Khouzam
2008-02-04 21:00 ` Eli Zaretskii
2008-02-02 11:20 ` Vladimir Prus
2008-02-03 19:55 ` Marc Khouzam
2008-02-03 20:42 ` Joel Brobecker
2008-02-03 21:41 ` Daniel Jacobowitz
2008-02-03 21:46 ` Daniel Jacobowitz
2008-02-04 17:00 ` Marc Khouzam
2008-02-04 17:02 ` Marc Khouzam
2008-02-04 21:40 ` Nick Roberts
2008-02-04 21:53 ` Nick Roberts
2008-02-05 14:47 ` Marc Khouzam
2008-02-05 20:43 ` Nick Roberts
2008-02-05 20:55 ` Marc Khouzam
2008-02-05 21:18 ` Nick Roberts
2008-02-04 17:11 ` Marc Khouzam
2008-01-23 3:48 ` Daniel Jacobowitz
2008-01-23 14:44 ` Marc Khouzam
2008-01-28 14:41 Marc Khouzam
2008-01-28 14:48 ` Daniel Jacobowitz
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=6D19CA8D71C89C43A057926FE0D4ADAA04290E59@ecamlmw720.eamcs.ericsson.se \
--to=marc.khouzam@ericsson.com \
--cc=drow@false.org \
--cc=gdb-patches@sourceware.org \
--cc=nickrob@snap.net.nz \
/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