From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7284 invoked by alias); 21 Jan 2014 20:45:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7273 invoked by uid 89); 21 Jan 2014 20:45:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2014 20:45:41 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0LKjdAI029671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 21 Jan 2014 15:45:39 -0500 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0LKjcVc017054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 21 Jan 2014 15:45:39 -0500 Message-ID: <52DEDC72.5040709@redhat.com> Date: Tue, 21 Jan 2014 20:45:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 07/11] MI option --available-children-only References: <1385258996-26047-1-git-send-email-yao@codesourcery.com> <1385258996-26047-8-git-send-email-yao@codesourcery.com> In-Reply-To: <1385258996-26047-8-git-send-email-yao@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00820.txt.bz2 On 11/23/2013 06:09 PM, Yao Qi wrote: > This patch adds option --available-children-only to three MI commands, > parse it, and set corresponding field of 'struct varobj_dynamic'. I've already mentioned my preference for allowing --available-children-only for -var-create and adding a new command to flip it on/off, so unless another maintainer agrees, we'll agree to leave this alone. Two minor nits below. Keith > gdb: > > 2013-11-24 Pedro Alves > Yao Qi > > * mi/mi-cmd-var.c (mi_cmd_var_create): Use mi_getopt to parse > options. Handle "--available-children-only". > (mi_cmd_var_info_num_children): Likewise. > (mi_cmd_var_list_children): Likewise. > * varobj.c (struct varobj_dynamic) : > New. > (new_variable, new_root_variable): Update declaration. > (varobj_is_dynamic_p): Return true if available-children-only > is true. > (varobj_create): Add new argument "available_children_only". > Callers update. > (varobj_get_num_children): Handle "available_children_only" > (varobj_set_available_children_only): New function. > (varobj_list_children): Handle "available_children_only". > (install_new_value): Likewise. > (varobj_update): Likewise. > (new_variable): Add new argument "available_children_only". > (new_root_variable): Likewise. > (varobj_invalidate_iter): Likewise. > * varobj.h (varobj_create): Update declaration. > (varobj_set_available_children_only): Declare. > --- > gdb/mi/mi-cmd-var.c | 128 ++++++++++++++++++++++++++++++++++++++++++++------- > gdb/varobj.c | 51 +++++++++++++++----- > gdb/varobj.h | 11 ++++- > 3 files changed, 160 insertions(+), 30 deletions(-) > > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c > index 2201630..552a527 100644 > --- a/gdb/mi/mi-cmd-var.c > +++ b/gdb/mi/mi-cmd-var.c > @@ -105,19 +105,50 @@ mi_cmd_var_create (char *command, char **argv, int argc) > char *expr; > struct cleanup *old_cleanups; > enum varobj_type var_type; > + int available_children_only = 0; > + int oind = 0; > + enum opt > + { > + AVAILABLE_CHILDREN_ONLY, > + }; > + static const struct mi_opt opts[] = > + { > + {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0}, > + { 0, 0, 0 } > + }; > > - if (argc != 3) > - error (_("-var-create: Usage: NAME FRAME EXPRESSION.")); > + /* Parse arguments. In this instance we are just looking for > + --available_children_only. */ > + while (1) > + { > + char *oarg; > + int opt = mi_getopt ("-var-create", argc, argv, > + opts, &oind, &oarg); > + if (opt < 0) > + break; > + switch ((enum opt) opt) > + { > + case AVAILABLE_CHILDREN_ONLY: > + available_children_only = 1; > + break; > + } > + } > > - name = xstrdup (argv[0]); > + > + if (argc - oind != 3) > + error (_("Usage: -var-create [--available-children-only] " > + "NAME FRAME EXPRESSION")); > + > + > + name = xstrdup (argv[oind]); > /* Add cleanup for name. Must be free_current_contents as name can > be reallocated. */ > old_cleanups = make_cleanup (free_current_contents, &name); > > - frame = xstrdup (argv[1]); > + frame = xstrdup (argv[oind + 1]); > make_cleanup (xfree, frame); > > - expr = xstrdup (argv[2]); > + expr = xstrdup (argv[oind + 2]); > make_cleanup (xfree, expr); > > if (strcmp (name, "-") == 0) > @@ -143,7 +174,8 @@ mi_cmd_var_create (char *command, char **argv, int argc) > "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n", > name, frame, hex_string (frameaddr), expr); > > - var = varobj_create (name, expr, frameaddr, var_type); > + var = varobj_create (name, expr, frameaddr, var_type, > + available_children_only); > > if (var == NULL) > error (_("-var-create: unable to create variable object")); > @@ -328,12 +360,43 @@ mi_cmd_var_info_num_children (char *command, char **argv, int argc) > { > struct ui_out *uiout = current_uiout; > struct varobj *var; > + int available_children_only = 0; > + int oind = 0; > + enum opt > + { > + AVAILABLE_CHILDREN_ONLY, > + }; > + static const struct mi_opt opts[] = > + { > + {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0}, > + { 0, 0, 0 } > + }; > > - if (argc != 1) > - error (_("-var-info-num-children: Usage: NAME.")); > + /* Parse arguments. In this instance we are just looking for > + --available_children_only. */ > + while (1) > + { > + char *oarg; > + int opt = mi_getopt ("-var-info-num-children", argc, argv, > + opts, &oind, &oarg); > + if (opt < 0) > + break; > + switch ((enum opt) opt) > + { > + case AVAILABLE_CHILDREN_ONLY: > + available_children_only = 1; > + break; > + } > + } > + > + if (argc - oind != 1) > + error (_("-var-info-num-children: Usage: " > + "[--available-children-only] NAME.")); This statement spans multiple lines and should be enclosed in braces ("{}"). > > /* Get varobj handle, if a valid var obj name was specified. */ > - var = varobj_get_handle (argv[0]); > + var = varobj_get_handle (argv[oind]); > + > + varobj_set_available_children_only (var, available_children_only); > > ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); > } > @@ -381,18 +444,47 @@ mi_cmd_var_list_children (char *command, char **argv, int argc) > int ix; > int from, to; > char *display_hint; > + int available_children_only = 0; > + int oind = 0; > + enum opt > + { > + AVAILABLE_CHILDREN_ONLY, > + }; > + static const struct mi_opt opts[] = > + { > + {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0}, > + { 0, 0, 0 } > + }; > + > + /* Parse arguments. In this instance we are just looking for > + --available_children_only. */ > + while (1) > + { > + char *oarg; > + int opt = mi_getopt_allow_unknown ("-var-list-children", argc, argv, > + opts, &oind, &oarg); > + > + if (opt < 0) > + break; > + switch ((enum opt) opt) > + { > + case AVAILABLE_CHILDREN_ONLY: > + available_children_only = 1; > + break; > + } > + } > > - if (argc < 1 || argc > 4) > - error (_("-var-list-children: Usage: " > + if (argc - oind < 1 || argc - oind > 4) > + error (_("-var-list-children: Usage: [--available-children-only] " > "[PRINT_VALUES] NAME [FROM TO]")); > > /* Get varobj handle, if a valid var obj name was specified. */ > - if (argc == 1 || argc == 3) > - var = varobj_get_handle (argv[0]); > + if (argc - oind == 1 || argc - oind == 3) > + var = varobj_get_handle (argv[oind]); > else > - var = varobj_get_handle (argv[1]); > + var = varobj_get_handle (argv[oind + 1]); > > - if (argc > 2) > + if (argc - oind > 2) > { > from = atoi (argv[argc - 2]); > to = atoi (argv[argc - 1]); > @@ -403,10 +495,12 @@ mi_cmd_var_list_children (char *command, char **argv, int argc) > to = -1; > } > > + varobj_set_available_children_only (var, available_children_only); > + > children = varobj_list_children (var, &from, &to); > ui_out_field_int (uiout, "numchild", to - from); > - if (argc == 2 || argc == 4) > - print_values = mi_parse_print_values (argv[0]); > + if (argc - oind == 2 || argc - oind == 4) > + print_values = mi_parse_print_values (argv[oind]); > else > print_values = PRINT_NO_VALUES; > > diff --git a/gdb/varobj.c b/gdb/varobj.c > index 0e0be6c..1fd9fd2 100644 > --- a/gdb/varobj.c > +++ b/gdb/varobj.c > @@ -119,6 +119,10 @@ struct varobj_dynamic > can avoid that. */ > int children_requested; > > + /* True if this varobj only includes available/collected objects in > + its list of children. */ > + int available_children_only; > + > /* The pretty-printer constructor. If NULL, then the default > pretty-printer will be looked up. If None, then no > pretty-printer will be installed. */ > @@ -175,9 +179,9 @@ create_child_with_value (struct varobj *parent, int index, > > /* Utility routines */ > > -static struct varobj *new_variable (void); > +static struct varobj *new_variable (int available_children_only); > > -static struct varobj *new_root_variable (void); > +static struct varobj *new_root_variable (int available_children_only); > > static void free_variable (struct varobj *var); > > @@ -285,14 +289,14 @@ find_frame_addr_in_frame_chain (CORE_ADDR frame_addr) > } > > struct varobj * > -varobj_create (char *objname, > - char *expression, CORE_ADDR frame, enum varobj_type type) > +varobj_create (char *objname, char *expression, CORE_ADDR frame, > + enum varobj_type type, int available_children_only) > { > struct varobj *var; > struct cleanup *old_chain; > > /* Fill out a varobj structure for the (root) variable being constructed. */ > - var = new_root_variable (); > + var = new_root_variable (available_children_only); > old_chain = make_cleanup_free_variable (var); > > if (expression != NULL) > @@ -911,6 +915,23 @@ varobj_get_num_children (struct varobj *var) > return var->num_children >= 0 ? var->num_children : 0; > } > Missing comment to describe below function. ["See description in varobj.h."] > +void > +varobj_set_available_children_only (struct varobj *var, int available_only) > +{ > + if (var->dynamic->available_children_only != available_only) > + { > + /* If there are any children now, wipe them. */ > + varobj_delete (var, NULL, /* children only */ 1); > + var->num_children = -1; > + var->dynamic->available_children_only = available_only; > + > + /* We're starting over, so get rid of any iterator. */ > + varobj_iter_delete (var->dynamic->child_iter); > + var->dynamic->child_iter = NULL; > + varobj_clear_saved_item (var->dynamic); > + } > +} > + > /* Creates a list of the immediate children of a variable object; > the return code is the number of such children or -1 on error. */ > > @@ -1071,7 +1092,8 @@ varobj_get_attributes (struct varobj *var) > int > varobj_is_dynamic_p (struct varobj *var) > { > - return var->dynamic->pretty_printer != NULL; > + return (var->dynamic->pretty_printer != NULL > + || var->dynamic->available_children_only); > } > > char * > @@ -2049,7 +2071,7 @@ create_child_with_value (struct varobj *parent, int index, > struct varobj *child; > char *childs_name; > > - child = new_variable (); > + child = new_variable (parent->dynamic->available_children_only); > > /* NAME is allocated by caller. */ > child->name = item->name; > @@ -2086,8 +2108,9 @@ create_child_with_value (struct varobj *parent, int index, > */ > > /* Allocate memory and initialize a new variable. */ > + > static struct varobj * > -new_variable (void) > +new_variable (int available_children_only) > { > struct varobj *var; > > @@ -2116,15 +2139,17 @@ new_variable (void) > var->dynamic->pretty_printer = 0; > var->dynamic->child_iter = 0; > var->dynamic->saved_item = 0; > + var->dynamic->available_children_only = available_children_only; > > return var; > } > > /* Allocate memory and initialize a new root variable. */ > + > static struct varobj * > -new_root_variable (void) > +new_root_variable (int available_children_only) > { > - struct varobj *var = new_variable (); > + struct varobj *var = new_variable (available_children_only); > > var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root)); > var->root->lang_ops = NULL; > @@ -2396,7 +2421,8 @@ value_of_root (struct varobj **var_handle, int *type_changed) > char *old_type, *new_type; > > tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0, > - USE_SELECTED_FRAME); > + USE_SELECTED_FRAME, > + var->dynamic->available_children_only); > if (tmp_var == NULL) > { > return NULL; > @@ -2756,7 +2782,8 @@ varobj_invalidate_iter (struct varobj *var, void *unused) > /* Try to create a varobj with same expression. If we succeed > replace the old varobj, otherwise invalidate it. */ > tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0, > - USE_CURRENT_FRAME); > + USE_CURRENT_FRAME, > + var->dynamic->available_children_only); > if (tmp_var != NULL) > { > tmp_var->obj_name = xstrdup (var->obj_name); > diff --git a/gdb/varobj.h b/gdb/varobj.h > index 60ace6f..9beec79 100644 > --- a/gdb/varobj.h > +++ b/gdb/varobj.h > @@ -225,7 +225,8 @@ const struct lang_varobj_ops ada_varobj_ops; > > extern struct varobj *varobj_create (char *objname, > char *expression, CORE_ADDR frame, > - enum varobj_type type); > + enum varobj_type type, > + int available_children_only); > > extern char *varobj_gen_name (void); > > @@ -310,6 +311,14 @@ extern int varobj_is_dynamic_p (struct varobj *var); > > extern struct cleanup *varobj_ensure_python_env (struct varobj *var); > > +/* Marks the varobj VAR as listing available children only or not, > + depending on the boolean AVAILABLE_ONLY. If the > + available-only-ness of the varobj changes compared to its present > + state with this call, the varobj's current list of children is > + deleted. */ > +extern void varobj_set_available_children_only (struct varobj *var, > + int available_only); > + > extern int varobj_default_value_is_changeable_p (struct varobj *var); > extern int varobj_value_is_changeable_p (struct varobj *var); > >