From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23407 invoked by alias); 3 Jul 2005 19:56:46 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 23316 invoked by uid 22791); 3 Jul 2005 19:56:35 -0000 Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sun, 03 Jul 2005 19:56:35 +0000 Received: from drow by nevyn.them.org with local (Exim 4.51) id 1DpAZq-0005zN-BJ; Sun, 03 Jul 2005 15:56:30 -0400 Date: Sun, 03 Jul 2005 19:56:00 -0000 From: Daniel Jacobowitz To: Eli Zaretskii Cc: Nick Roberts , Bob Rossi , gdb-patches@sources.redhat.com Subject: Re: [PATCH: gdb/mi + doco] -var-update Message-ID: <20050703195630.GM13811@nevyn.them.org> Mail-Followup-To: Eli Zaretskii , Nick Roberts , Bob Rossi , gdb-patches@sources.redhat.com References: <16929.8147.933720.246602@farnswood.snap.net.nz> <16955.41017.161288.832646@farnswood.snap.net.nz> <20050401024942.GA2179@white> <17013.35649.62745.226730@farnswood.snap.net.nz> <20050502040526.GA10023@nevyn.them.org> <17013.54662.20554.239976@farnswood.snap.net.nz> <20050617034329.GH17013@nevyn.them.org> <20050617140410.GA24575@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.8i X-SW-Source: 2005-07/txt/msg00030.txt.bz2 Nick, I apologize for the delay, I was trying to keep this one moving... here goes again. On Sat, Jun 18, 2005 at 11:53:30AM +0200, Eli Zaretskii wrote: > "all" simply doesn't sound as an opposite of "no" or "none". > > > especially since --simple-values would be a reasonable extension here > > also. > > If we extend the -var-* commands like that, I wouldn't object to using > "--all-values" in them. Personally, I think --no-values and --all-values are a reasonable pair. But in any case, we all seem agreed that --no-values, --simple-values, and --all-values are a reasonable triplet. Nick, here's a patch based on yours which adds -var-list-children --simple-values and -var-update --simple-values/--all-values. I like it; I think --simple-values is useful (since for anything other than simple values, an IDE is likely to want to print each member individually...). I didn't revise the documentation because your last posted patch didn't include the current manual diff. I also didn't write any testcases. Both of these need to be done before the patch goes in. Tested on i686-pc-linux-gnu, both the testsuite and by hand for -var-update. No incompatible changes, option consistency, and behavior consistency. I don't think I can do any better than this :-) Nick, Eli, are you both OK with this version of the code changes? -- Daniel Jacobowitz CodeSourcery, LLC 2005-07-03 Nick Roberts Daniel Jacobowitz * mi/mi-cmds.h (mi_no_values, mi_simple_values, mi_all_values): New declarations. * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Use string constants instead of literals for MI command options. * mi/mi-cmd-var.c (mi_no_values, mi_simple_values, mi_all_values): New variables. (mi_parse_values_option, mi_print_value_p): New functions. (mi_cmd_var_list_children): Use mi_parse_values_option and mi_print_value_p. (mi_cmd_var_update): Support a PRINT_VALUES option. Update calls to varobj_update_one. (varobj_update_one): Take a print_values argument. Call mi_print_value_p. Index: mi/mi-cmd-stack.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v retrieving revision 1.27 diff -u -p -r1.27 mi-cmd-stack.c --- mi/mi-cmd-stack.c 19 Jun 2005 03:11:47 -0000 1.27 +++ mi/mi-cmd-stack.c 3 Jul 2005 19:51:35 -0000 @@ -136,16 +136,18 @@ mi_cmd_stack_list_locals (char *command, frame = get_selected_frame (NULL); if (strcmp (argv[0], "0") == 0 - || strcmp (argv[0], "--no-values") == 0) + || strcmp (argv[0], mi_no_values) == 0) print_values = PRINT_NO_VALUES; else if (strcmp (argv[0], "1") == 0 - || strcmp (argv[0], "--all-values") == 0) + || strcmp (argv[0], mi_all_values) == 0) print_values = PRINT_ALL_VALUES; else if (strcmp (argv[0], "2") == 0 - || strcmp (argv[0], "--simple-values") == 0) + || strcmp (argv[0], mi_simple_values) == 0) print_values = PRINT_SIMPLE_VALUES; else - error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\", 2 or \"--simple-values\"")); + error (_("Unknown value for PRINT_VALUES: must be: \ +0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), + mi_no_values, mi_all_values, mi_simple_values); list_args_or_locals (1, print_values, frame); return MI_CMD_DONE; } Index: mi/mi-cmd-var.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v retrieving revision 1.21 diff -u -p -r1.21 mi-cmd-var.c --- mi/mi-cmd-var.c 11 Feb 2005 04:06:11 -0000 1.21 +++ mi/mi-cmd-var.c 3 Jul 2005 19:51:35 -0000 @@ -30,9 +30,14 @@ #include #include "gdb_string.h" +const char mi_no_values[] = "--no-values"; +const char mi_simple_values[] = "--simple-values"; +const char mi_all_values[] = "--all-values"; + extern int varobjdebug; /* defined in varobj.c */ -static int varobj_update_one (struct varobj *var); +static int varobj_update_one (struct varobj *var, + enum print_values print_values); /* VAROBJ operations */ @@ -247,6 +252,49 @@ mi_cmd_var_info_num_children (char *comm return MI_CMD_DONE; } +/* Parse a string argument into a print_values value. */ + +static enum print_values +mi_parse_values_option (const char *arg) +{ + if (strcmp (arg, "0") == 0 + || strcmp (arg, mi_no_values) == 0) + return PRINT_NO_VALUES; + else if (strcmp (arg, "1") == 0 + || strcmp (arg, mi_all_values) == 0) + return PRINT_ALL_VALUES; + else if (strcmp (arg, "2") == 0 + || strcmp (arg, mi_simple_values) == 0) + return PRINT_SIMPLE_VALUES; + else + error (_("Unknown value for PRINT_VALUES\n\ +Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), + mi_no_values, mi_simple_values, mi_all_values); +} + +/* Return 1 if given the argument PRINT_VALUES we should display + a value of type TYPE. */ + +static int +mi_print_value_p (struct type *type, enum print_values print_values) +{ + if (print_values == PRINT_NO_VALUES) + return 0; + + if (print_values == PRINT_ALL_VALUES) + return 1; + + /* For PRINT_SIMPLE_VALUES, only print the value if it has a type + and that type is not a compound type. */ + + if (type == NULL) + return 0; + type = check_typedef (type); + return (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_STRUCT + && TYPE_CODE (type) != TYPE_CODE_UNION); +} + enum mi_cmd_result mi_cmd_var_list_children (char *command, char **argv, int argc) { @@ -258,27 +306,23 @@ mi_cmd_var_list_children (char *command, char *type; enum print_values print_values; - if (argc != 1 && argc != 2) + if (argc > 2) error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME")); /* Get varobj handle, if a valid var obj name was specified */ - if (argc == 1) var = varobj_get_handle (argv[0]); - else var = varobj_get_handle (argv[1]); + if (argc == 1) + var = varobj_get_handle (argv[0]); + else + var = varobj_get_handle (argv[1]); if (var == NULL) error (_("Variable object not found")); numchild = varobj_list_children (var, &childlist); ui_out_field_int (uiout, "numchild", numchild); if (argc == 2) - if (strcmp (argv[0], "0") == 0 - || strcmp (argv[0], "--no-values") == 0) - print_values = PRINT_NO_VALUES; - else if (strcmp (argv[0], "1") == 0 - || strcmp (argv[0], "--all-values") == 0) - print_values = PRINT_ALL_VALUES; - else - error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\"")); - else print_values = PRINT_NO_VALUES; + print_values = mi_parse_values_option (argv[0]); + else + print_values = PRINT_NO_VALUES; if (numchild <= 0) return MI_CMD_DONE; @@ -295,9 +339,9 @@ mi_cmd_var_list_children (char *command, ui_out_field_string (uiout, "name", varobj_get_objname (*cc)); ui_out_field_string (uiout, "exp", varobj_get_expression (*cc)); ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc)); - if (print_values) - ui_out_field_string (uiout, "value", varobj_get_value (*cc)); type = varobj_get_type (*cc); + if (mi_print_value_p (type, print_values)) + ui_out_field_string (uiout, "value", varobj_get_value (*cc)); /* C++ pseudo-variables (public, private, protected) do not have a type */ if (type) ui_out_field_string (uiout, "type", varobj_get_type (*cc)); @@ -426,11 +470,20 @@ mi_cmd_var_update (char *command, char * struct cleanup *cleanup; char *name; int nv; + enum print_values print_values; - if (argc != 1) - error (_("mi_cmd_var_update: Usage: NAME.")); + if (argc != 1 && argc != 2) + error (_("mi_cmd_var_update: Usage: [PRINT_VALUES] NAME.")); - name = argv[0]; + if (argc == 1) + name = argv[0]; + else + name = (argv[1]); + + if (argc == 2) + print_values = mi_parse_values_option (argv[0]); + else + print_values = PRINT_NO_VALUES; /* Check if the parameter is a "*" which means that we want to update all variables */ @@ -450,7 +503,7 @@ mi_cmd_var_update (char *command, char * cr = rootlist; while (*cr != NULL) { - varobj_update_one (*cr); + varobj_update_one (*cr, print_values); cr++; } xfree (rootlist); @@ -467,7 +520,7 @@ mi_cmd_var_update (char *command, char * cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); else cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist"); - varobj_update_one (var); + varobj_update_one (var, print_values); do_cleanups (cleanup); } return MI_CMD_DONE; @@ -478,7 +531,7 @@ mi_cmd_var_update (char *command, char * scope), and 1 if it succeeds. */ static int -varobj_update_one (struct varobj *var) +varobj_update_one (struct varobj *var, enum print_values print_values) { struct varobj **changelist; struct varobj **cc; @@ -524,6 +577,8 @@ varobj_update_one (struct varobj *var) if (mi_version (uiout) > 1) cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); ui_out_field_string (uiout, "name", varobj_get_objname (*cc)); + if (mi_print_value_p (varobj_get_type (*cc), print_values)) + ui_out_field_string (uiout, "value", varobj_get_value (*cc)); ui_out_field_string (uiout, "in_scope", "true"); ui_out_field_string (uiout, "type_changed", "false"); if (mi_version (uiout) > 1) Index: mi/mi-cmds.h =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v retrieving revision 1.16 diff -u -p -r1.16 mi-cmds.h --- mi/mi-cmds.h 19 Jun 2005 03:12:15 -0000 1.16 +++ mi/mi-cmds.h 3 Jul 2005 19:51:35 -0000 @@ -50,6 +50,10 @@ enum print_values { PRINT_SIMPLE_VALUES }; +extern const char mi_no_values[]; +extern const char mi_simple_values[]; +extern const char mi_all_values[]; + typedef enum mi_cmd_result (mi_cmd_argv_ftype) (char *command, char **argv, int argc); /* Older MI commands have this interface. Retained until all old