From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20366 invoked by alias); 10 Jul 2009 18:45:19 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 20344 invoked by uid 22791); 10 Jul 2009 18:45:15 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_37,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org To: Project Archer Subject: [python] change varobj child listing From: Tom Tromey Reply-To: tromey@redhat.com Date: Fri, 10 Jul 2009 18:45:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2009-q3/txt/msg00037.txt.bz2 This implements the -var-list-children changes requested by Volodya, to the best of my understanding. Basically, -var-set-child-range is gone, and now -var-list-children takes an optional child range. Also, -var-list-children and -var-update will emit a `has_more' attribute if the varobj has more children after the final selected child. Tom b/gdb/ChangeLog: 2009-07-10 Tom Tromey * varobj.c (update_dynamic_varobj_children): Fetch one extra child. * mi/mi-cmds.h (mi_cmd_var_set_child_range): Remove. * mi/mi-cmds.c (mi_cmds): Remove var-set-child-range. * mi/mi-cmd-var.c (mi_cmd_var_set_child_range): Remove. (mi_cmd_var_list_children): Accept 'from' and 'to' arguments. Emit 'has_more' attribute. (varobj_update_one): Emit 'has_more' attribute. b/gdb/doc/ChangeLog: 2009-07-10 Tom Tromey * gdb.texinfo (GDB/MI Variable Objects) <-var-list-children>: Mention from and to arguments, has_more attribute. <-var-set-child-range>: Remove. b/gdb/testsuite/ChangeLog: 2009-07-10 Tom Tromey * gdb.mi/mi-var-display.exp: Update. * gdb.mi/mi2-var-display.exp: Update. * gdb.mi/gdb701.exp: Update. * lib/mi-support.exp (mi_varobj_update_dynamic): Handle "has_more". (mi_list_varobj_children): Update. (mi_list_varobj_children_range): Add 'from' and 'to' parameters. * gdb.python/python-mi.exp: Update for changes to -var-list-children. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 7ac503f..b93bd75 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -23754,7 +23754,7 @@ Returns the number of children of a variable object @var{name}: @subsubheading Synopsis @smallexample - -var-list-children [@var{print-values}] @var{name} + -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}] @end smallexample @anchor{-var-list-children} @@ -23767,6 +23767,18 @@ values; and if it is 2 or @code{--simple-values} print the name and value for simple data types and just the name for arrays, structures and unions. +@var{from} and @var{to}, if specified, indicate the range of children +to report. If @var{from} or @var{to} is less than zero, the range is +reset and all children will be reported. Otherwise, children starting +at @var{from} (zero-based) and ending just before @var{to} will be +reported. The selected range is sticky; future calls to +@code{-var-update} or @code{-var-list-children} will use any +previously set range. + +The result may include a @code{has_more} attribute. This is an +integer attribute which is nonzero if there are children remaining +after the end of the selected range. + @subsubheading Example @smallexample @@ -24074,46 +24086,6 @@ can be used to instantiate this class for a varobj: ^done @end smallexample -@subheading The @code{-var-set-child-range} command -@findex -var-set-child-range -@anchor{-var-set-child-range} - -@subsubheading Synopsis - -@smallexample - -var-set-child-range @var{name} @var{from} @var{to} -@end smallexample - -Select a sub-range of the children of the variable object @var{name}; -future calls to @code{-var-list-children} will only report the -selected range of children. This allows an MI consumer to avoid -inefficiencies if the varobj has very many children. - -If either @var{from} or @var{to} is less than zero, then sub-range -selection is disabled, and @code{-var-list-children} will report all -children. - -Otherwise, @var{from} and @var{to} are indexes into the array of -children. Children starting at @var{from} and stopping jsut before -@var{to} will be reported. - -@subsubheading Example - -@smallexample -(gdb) - -var-list-children n - ^done,numchild=3,children=[@{name="a",numchild=0,type="int"@}, - @{name="b",numchild=0,type="int"@}, - @{name="c",numchild=0,type="int"@}] -(gdb) - -var-set-child-range n 1 2 -(gdb) - -var-list-children n - ^done,numchild=3,children=[@{name="b",numchild=0,type="int"@}, - @{name="c",numchild=0,type="int"@}] -@end smallexample - - @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @node GDB/MI Data Manipulation @section @sc{gdb/mi} Data Manipulation diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index cb081c0..61e7ee5 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -259,25 +259,6 @@ mi_cmd_var_set_visualizer (char *command, char **argv, int argc) } void -mi_cmd_var_set_child_range (char *command, char **argv, int argc) -{ - struct varobj *var; - int from, to; - - if (argc != 3) - error (_("-var-set-child-range: NAME FROM TO")); - - var = varobj_get_handle (argv[0]); - if (var == NULL) - error (_("Variable object not found")); - - from = atoi (argv[1]); - to = atoi (argv[2]); - - varobj_set_child_range (var, from, to); -} - -void mi_cmd_var_set_frozen (char *command, char **argv, int argc) { struct varobj *var; @@ -388,32 +369,38 @@ mi_cmd_var_list_children (char *command, char **argv, int argc) struct varobj *var; VEC(varobj_p) *children; struct varobj *child; - struct cleanup *cleanup_children; int numchild; enum print_values print_values; int ix; int from, to; char *display_hint; - if (argc != 1 && argc != 2) - error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME")); + if (argc < 1 || argc > 4) + error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME [FROM TO]")); /* Get varobj handle, if a valid var obj name was specified */ - if (argc == 1) + if (argc == 1 || argc == 3) var = varobj_get_handle (argv[0]); else var = varobj_get_handle (argv[1]); + if (argc > 2) + { + from = atoi (argv[argc - 2]); + to = atoi (argv[argc - 1]); + varobj_set_child_range (var, from, to); + } + children = varobj_list_children (var); ui_out_field_int (uiout, "numchild", VEC_length (varobj_p, children)); - if (argc == 2) + if (argc == 2 || argc == 4) print_values = mi_parse_values_option (argv[0]); else print_values = PRINT_NO_VALUES; + /* Re-fetch the child range, because varobj_get_child_range computes + the real start and end indices for us. */ varobj_get_child_range (var, children, &from, &to); - if (from >= to) - return; display_hint = varobj_get_display_hint (var); if (display_hint) @@ -422,18 +409,29 @@ mi_cmd_var_list_children (char *command, char **argv, int argc) xfree (display_hint); } - if (mi_version (uiout) == 1) - cleanup_children = make_cleanup_ui_out_tuple_begin_end (uiout, "children"); - else - cleanup_children = make_cleanup_ui_out_list_begin_end (uiout, "children"); - for (ix = from; ix < to && VEC_iterate (varobj_p, children, ix, child); ++ix) + if (from < to) { - struct cleanup *cleanup_child; - cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); - print_varobj (child, print_values, 1 /* print expression */); - do_cleanups (cleanup_child); + struct cleanup *cleanup_children; + if (mi_version (uiout) == 1) + cleanup_children + = make_cleanup_ui_out_tuple_begin_end (uiout, "children"); + else + cleanup_children + = make_cleanup_ui_out_list_begin_end (uiout, "children"); + for (ix = from; + ix < to && VEC_iterate (varobj_p, children, ix, child); + ++ix) + { + struct cleanup *cleanup_child; + cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); + print_varobj (child, print_values, 1 /* print expression */); + do_cleanups (cleanup_child); + } + do_cleanups (cleanup_children); } - do_cleanups (cleanup_children); + + ui_out_field_int (uiout, "has_more", + VEC_length (varobj_p, children) > to); } void @@ -743,6 +741,9 @@ varobj_update_one (struct varobj *var, enum print_values print_values, } do_cleanups (cleanup); + + ui_out_field_int (uiout, "has_more", + VEC_length (varobj_p, children) > to); } if (mi_version (uiout) > 1) diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 79ff3ad..4911146 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -109,7 +109,6 @@ struct mi_cmd mi_cmds[] = { "var-info-num-children", { NULL, 0 }, mi_cmd_var_info_num_children}, { "var-info-type", { NULL, 0 }, mi_cmd_var_info_type}, { "var-list-children", { NULL, 0 }, mi_cmd_var_list_children}, - { "var-set-child-range", { NULL, 0 }, mi_cmd_var_set_child_range }, { "var-set-format", { NULL, 0 }, mi_cmd_var_set_format}, { "var-set-frozen", { NULL, 0 }, mi_cmd_var_set_frozen}, { "var-set-visualizer", { NULL, 0 }, mi_cmd_var_set_visualizer}, diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index 84f6d85..afcba1e 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -93,7 +93,6 @@ extern mi_cmd_argv_ftype mi_cmd_var_info_num_children; extern mi_cmd_argv_ftype mi_cmd_var_info_type; extern mi_cmd_argv_ftype mi_cmd_var_list_children; extern mi_cmd_argv_ftype mi_cmd_var_set_format; -extern mi_cmd_argv_ftype mi_cmd_var_set_child_range; extern mi_cmd_argv_ftype mi_cmd_var_set_frozen; extern mi_cmd_argv_ftype mi_cmd_var_set_visualizer; extern mi_cmd_argv_ftype mi_cmd_var_show_attributes; diff --git a/gdb/testsuite/gdb.mi/gdb701.exp b/gdb/testsuite/gdb.mi/gdb701.exp index d4acdc2..244c731 100644 --- a/gdb/testsuite/gdb.mi/gdb701.exp +++ b/gdb/testsuite/gdb.mi/gdb701.exp @@ -54,7 +54,7 @@ mi_gdb_test "-var-list-children fooPtr" \ foreach i [list x y z] { mi_gdb_test "-var-list-children fooPtr.$i" \ - "(&\".*\"\r\n)*\\^done,numchild=\"0\"" \ + "(&\".*\"\r\n)*\\^done,numchild=\"0\",has_more=\"0\"" \ "list children of fooPtr.$i" } diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp index 59be6b2..584967c 100644 --- a/gdb/testsuite/gdb.mi/mi-var-display.exp +++ b/gdb/testsuite/gdb.mi/mi-var-display.exp @@ -558,7 +558,7 @@ mi_gdb_test "-var-info-num-children e" \ # Test: c_variable-7.55 # Desc: children of e mi_gdb_test "-var-list-children e" \ - "\\^done,numchild=\"0\"" \ + "\\^done,numchild=\"0\",has_more=\"0\"" \ "get children of e" # Test: c_variable-7.60 @@ -600,7 +600,7 @@ mi_gdb_test "-var-info-num-children anone" \ # Test: c_variable-7.75 # Desc: children of anone mi_gdb_test "-var-list-children anone" \ - "\\^done,numchild=\"0\"" \ + "\\^done,numchild=\"0\",has_more=\"0\"" \ "get children of anone" diff --git a/gdb/testsuite/gdb.mi/mi2-var-display.exp b/gdb/testsuite/gdb.mi/mi2-var-display.exp index 9c98694..7b2ed98 100644 --- a/gdb/testsuite/gdb.mi/mi2-var-display.exp +++ b/gdb/testsuite/gdb.mi/mi2-var-display.exp @@ -557,7 +557,7 @@ mi_gdb_test "-var-info-num-children e" \ # Test: c_variable-7.55 # Desc: children of e mi_gdb_test "-var-list-children e" \ - "\\^done,numchild=\"0\"" \ + "\\^done,numchild=\"0\",has_more=\"0\"" \ "get children of e" # Test: c_variable-7.60 @@ -599,7 +599,7 @@ mi_gdb_test "-var-info-num-children anone" \ # Test: c_variable-7.75 # Desc: children of anone mi_gdb_test "-var-list-children anone" \ - "\\^done,numchild=\"0\"" \ + "\\^done,numchild=\"0\",has_more=\"0\"" \ "get children of anone" diff --git a/gdb/testsuite/gdb.python/python-mi.exp b/gdb/testsuite/gdb.python/python-mi.exp index 8c6167c..8153f84 100644 --- a/gdb/testsuite/gdb.python/python-mi.exp +++ b/gdb/testsuite/gdb.python/python-mi.exp @@ -92,27 +92,11 @@ mi_varobj_update_dynamic container { { {container.\[1\]} {\[1\]} 0 int } } "varobj update after choosing via expression" -mi_gdb_test "-var-set-child-range container 1 2" \ - "\\^done" \ - "select child range" - -mi_gdb_test "-var-update container" \ - "\\^done,changelist=\\\[\\\]" \ - "varobj update after selecting child range" - -mi_list_varobj_children_range container 2 { +mi_list_varobj_children_range container 1 2 2 { { {container.\[1\]} {\[1\]} 0 int } } "list varobj children after selecting child range" -mi_gdb_test "-var-set-child-range container -1 -1" \ - "\\^done" \ - "reset child range" - -mi_gdb_test "-var-update container" \ - "\\^done,changelist=\\\[\\\]" \ - "varobj update after resetting child range" - -mi_list_varobj_children container { +mi_list_varobj_children_range container -1 -1 2 { { {container.\[0\]} {\[0\]} 0 int } { {container.\[1\]} {\[1\]} 0 int } } "list varobj children after resetting child range" diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 9b4c464..33f277a 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1258,7 +1258,7 @@ proc mi_varobj_update_dynamic {name children testname} { set er "\\^done,changelist=\\\[" append er "{name=\"$name\",in_scope=\"true\",type_changed=\"false\"" - append er ",children=\\\[$children_exp_j.*\\\]}\\\]" + append er ",children=\\\[$children_exp_j.*\\\],has_more=\".\"}\\\]" verbose -log "Expecting: $er" mi_gdb_test "-var-update $name" $er $testname @@ -1328,14 +1328,13 @@ proc mi_child_regexp {children add_child} { # have no value. # proc mi_list_varobj_children { varname children testname } { - mi_list_varobj_children_range $varname [llength $children] $children \ + mi_list_varobj_children_range $varname "" "" [llength $children] $children \ $testname } -# Like mi_list_varobj_children, but assumes that a subrange has been -# selected with -var-set-child-range. NUMCHILDREN is the total number -# of children. -proc mi_list_varobj_children_range {varname numchildren children testname} { +# Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is +# the total number of children. +proc mi_list_varobj_children_range {varname from to numchildren children testname} { set options "" if {[llength $varname] == 2} { set options [lindex $varname 1] @@ -1351,9 +1350,18 @@ proc mi_list_varobj_children_range {varname numchildren children testname} { set expected "\\^done,numchild=\"0\"" } + if {"$to" == ""} { + append expected ",has_more=\"0\"" + } elseif {$to >= 0 && $numchildren > $to} { + append expected ",has_more=\"1\"" + } else { + append expected ",has_more=\"0\"" + } + verbose -log "Expecting: $expected" - mi_gdb_test "-var-list-children $options $varname" $expected $testname + mi_gdb_test "-var-list-children $options $varname $from $to" \ + $expected $testname } # Verifies that variable object VARNAME has NUMBER children, diff --git a/gdb/varobj.c b/gdb/varobj.c index 1412d43..a774cdf 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -879,7 +879,9 @@ update_dynamic_varobj_children (struct varobj *var, } make_cleanup_py_decref (iterator); - for (i = 0; var->to < 0 || i < var->to; ++i) + /* We ask for one extra child, so that MI can report whether there + are more children. */ + for (i = 0; var->to < 0 || i < var->to + 1; ++i) { PyObject *item = PyIter_Next (iterator); PyObject *py_v;