diff options
author | Tom Tromey <tromey@redhat.com> | 2009-09-15 18:51:26 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2009-09-15 18:51:26 +0000 |
commit | 0cc7d26fe4e30614f7ca3d3abd607d938b56dbf0 (patch) | |
tree | dd150a090dac11d841608d5b437e7f04c6733593 /gdb/mi/mi-cmd-var.c | |
parent | 1acf546ea5a0a65be516aefe252bcf7f2daaccb3 (diff) | |
download | gdb-0cc7d26fe4e30614f7ca3d3abd607d938b56dbf0.zip gdb-0cc7d26fe4e30614f7ca3d3abd607d938b56dbf0.tar.gz gdb-0cc7d26fe4e30614f7ca3d3abd607d938b56dbf0.tar.bz2 |
gdb
* varobj.h (varobj_update_result_t) <new>: New field.
(varobj_get_child_range, varobj_set_child_range): Declare.
(varobj_list_children): Update.
(varobj_enable_pretty_printing, varobj_has_more)
(varobj_pretty_printed_p): Declare.
* varobj.c (pretty_printing): New global.
(varobj_enable_pretty_printing): New function.
(struct varobj_root) <from, to, constructor, child_iter,
saved_item>: New fields.
(varobj_create): Don't call install_default_visualizer.
(instantiate_pretty_printer): Don't use value_copy.
(varobj_has_more): New function.
(restrict_range): New function.
(install_dynamic_child): Likewise.
(dynamic_varobj_has_child_method): Likewise.
(update_dynamic_varobj_children): Remove 'new_and_unchanged'
argument; add 'new', 'unchanged', 'from', and 'to' arguments.
Rewrite.
(varobj_get_num_children): Call update_dynamic_varobj_children.
(varobj_list_children): Add 'from' and 'to' arguments. Ignore
result of update_dynamic_varobj_children. Don't call
install_default_visualizer. Restrict result range.
(varobj_add_child): Don't call install_default_visualizer.
(varobj_pretty_printed_p): New function.
(install_visualizer): Rewrite. Move earlier in file.
(install_default_visualizer): Likewise.
(construct_visualizer): New function.
(install_new_value_visualizer): Likewise.
(install_new_value): Don't call release_value. Special case
pretty-printed objects. Use value_incref. Rearrange "changed"
logic.
(varobj_get_child_range): New function.
(varobj_set_child_range): Likewise.
(varobj_set_visualizer): Rewrite.
(varobj_update): Rewrite pretty-printing logic.
(new_variable): Initialize new fields.
(free_variable): Destroy new fields.
(value_of_root): Copy 'from' and 'to'.
(my_value_of_variable): Handle pretty-printers.
(value_get_print_value): Rework pretty-printing logic.
(cplus_describe_child): Don't use release_value.
* mi/mi-cmds.h (mi_cmd_enable_pretty_printing)
(mi_cmd_var_set_update_range): Declare.
* mi/mi-cmds.c (mi_cmds): Add enable-pretty-printing and
var-set-update-range.
* mi/mi-cmd-var.c (print_varobj): Update. Emit "dynamic"
attribute.
(mi_cmd_var_create): Emit "has_more" attribute.
(mi_cmd_var_set_format): Plug memory leak.
(mi_print_value_p): Replace 'type' argument with 'var'. Handle
pretty-printed varobjs.
(mi_cmd_var_list_children): Accept 'from' and 'to' arguments.
Emit "has_more" attribute.
(mi_cmd_var_evaluate_expression): Plug memory leak.
(mi_cmd_var_assign): Likewise.
(varobj_update_one): Likewise. Emit "dynamic", "has_more", and
"new_children" attributes.
(mi_cmd_enable_pretty_printing): New function.
(mi_cmd_var_set_update_range): Likewise.
gdb/doc
* gdb.texinfo (GDB/MI Variable Objects): Document
-enable-pretty-printing, -var-set-update-range, dynamic varobjs.
Expand -var-update documentation.
gdb/testsuite
* lib/mi-support.exp (mi_create_varobj): Update.
(mi_create_floating_varobj): Likewise.
(mi_create_dynamic_varobj): New proc.
(mi_varobj_update): Update.
(mi_varobj_update_with_type_change): Likewise.
(mi_varobj_update_kv_helper): New proc.
(mi_varobj_update_dynamic_helper): Rewrite.
(mi_varobj_update_dynamic): New proc.
(mi_list_varobj_children): Update.
(mi_list_varobj_children_range): Add 'from' and 'to' arguments.
* gdb.python/python-prettyprint.py (pp_outer): New class.
(pp_nullstr): Likewise.
(lookup_function): Register new printers.
* gdb.python/python-prettyprint.c (struct substruct): New type.
(struct outerstruct): Likewise.
(substruct_test): New function.
(struct nullstr): New type.
(string_1, string_2): New globals.
(main): Add new tests.
* gdb.python/python-mi.exp: Added regression tests.
* gdb.mi/mi2-var-display.exp: Update.
* gdb.mi/mi2-var-cmd.exp: Update.
* gdb.mi/mi2-var-child.exp: Update.
* gdb.mi/mi2-var-block.exp: Update.
* gdb.mi/mi-var-invalidate.exp: Update.
* gdb.mi/mi-var-display.exp: Update.
* gdb.mi/mi-var-cmd.exp: Update.
* gdb.mi/mi-var-child.exp: Update.
* gdb.mi/mi-var-block.exp: Update.
* gdb.mi/mi-break.exp: Update.
* gdb.mi/gdb701.exp: Update.
Diffstat (limited to 'gdb/mi/mi-cmd-var.c')
-rw-r--r-- | gdb/mi/mi-cmd-var.c | 183 |
1 files changed, 136 insertions, 47 deletions
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index 0cf03d9..0baaa83 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -41,7 +41,7 @@ static void varobj_update_one (struct varobj *var, enum print_values print_values, int explicit); -static int mi_print_value_p (struct type *type, enum print_values print_values); +static int mi_print_value_p (struct varobj *var, enum print_values print_values); /* Print variable object VAR. The PRINT_VALUES parameter controls if the value should be printed. The PRINT_EXPRESSION parameter @@ -53,14 +53,19 @@ print_varobj (struct varobj *var, enum print_values print_values, struct type *gdb_type; char *type; int thread_id; + char *display_hint; ui_out_field_string (uiout, "name", varobj_get_objname (var)); if (print_expression) ui_out_field_string (uiout, "exp", varobj_get_expression (var)); ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); - if (mi_print_value_p (varobj_get_gdb_type (var), print_values)) - ui_out_field_string (uiout, "value", varobj_get_value (var)); + if (mi_print_value_p (var, print_values)) + { + char *val = varobj_get_value (var); + ui_out_field_string (uiout, "value", val); + xfree (val); + } type = varobj_get_type (var); if (type != NULL) @@ -75,6 +80,16 @@ print_varobj (struct varobj *var, enum print_values print_values, if (varobj_get_frozen (var)) ui_out_field_int (uiout, "frozen", 1); + + display_hint = varobj_get_display_hint (var); + if (display_hint) + { + ui_out_field_string (uiout, "displayhint", display_hint); + xfree (display_hint); + } + + if (varobj_pretty_printed_p (var)) + ui_out_field_int (uiout, "dynamic", 1); } /* VAROBJ operations */ @@ -138,6 +153,8 @@ mi_cmd_var_create (char *command, char **argv, int argc) print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */); + ui_out_field_int (uiout, "has_more", varobj_has_more (var, 0)); + do_cleanups (old_cleanups); } @@ -223,6 +240,7 @@ mi_cmd_var_set_format (char *command, char **argv, int argc) { enum varobj_display_formats format; struct varobj *var; + char *val; if (argc != 2) error (_("mi_cmd_var_set_format: Usage: NAME FORMAT.")); @@ -239,7 +257,9 @@ mi_cmd_var_set_format (char *command, char **argv, int argc) ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); /* Report the value in the new format */ - ui_out_field_string (uiout, "value", varobj_get_value (var)); + val = varobj_get_value (var); + ui_out_field_string (uiout, "value", val); + xfree (val); } void @@ -337,11 +357,12 @@ Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), } /* Return 1 if given the argument PRINT_VALUES we should display - a value of type TYPE. */ + the varobj VAR. */ static int -mi_print_value_p (struct type *type, enum print_values print_values) +mi_print_value_p (struct varobj *var, enum print_values print_values) { + struct type *type; if (print_values == PRINT_NO_VALUES) return 0; @@ -349,6 +370,10 @@ mi_print_value_p (struct type *type, enum print_values print_values) if (print_values == PRINT_ALL_VALUES) return 1; + if (varobj_pretty_printed_p (var)) + return 1; + + type = varobj_get_gdb_type (var); if (type == NULL) return 1; else @@ -369,24 +394,35 @@ 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]); - children = varobj_list_children (var); - ui_out_field_int (uiout, "numchild", VEC_length (varobj_p, children)); - if (argc == 2) + if (argc > 2) + { + from = atoi (argv[argc - 2]); + to = atoi (argv[argc - 1]); + } + else + { + from = -1; + to = -1; + } + + children = varobj_list_children (var, &from, &to); + ui_out_field_int (uiout, "numchild", to - from); + if (argc == 2 || argc == 4) print_values = mi_parse_values_option (argv[0]); else print_values = PRINT_NO_VALUES; @@ -398,21 +434,28 @@ mi_cmd_var_list_children (char *command, char **argv, int argc) xfree (display_hint); } - if (VEC_length (varobj_p, children) == 0) - return; - - 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 = 0; 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", varobj_has_more (var, to)); } void @@ -538,16 +581,24 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) var = varobj_get_handle (argv[optind]); if (formatFound) - ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format)); + { + char *val = varobj_get_formatted_value (var, format); + ui_out_field_string (uiout, "value", val); + xfree (val); + } else - ui_out_field_string (uiout, "value", varobj_get_value (var)); + { + char *val = varobj_get_value (var); + ui_out_field_string (uiout, "value", val); + xfree (val); + } } void mi_cmd_var_assign (char *command, char **argv, int argc) { struct varobj *var; - char *expression; + char *expression, *val; if (argc != 2) error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION.")); @@ -563,7 +614,9 @@ mi_cmd_var_assign (char *command, char **argv, int argc) if (!varobj_set_value (var, expression)) error (_("mi_cmd_var_assign: Could not assign expression to variable object")); - ui_out_field_string (uiout, "value", varobj_get_value (var)); + val = varobj_get_value (var); + ui_out_field_string (uiout, "value", val); + xfree (val); } /* Type used for parameters passing to mi_cmd_var_update_iter. */ @@ -670,6 +723,7 @@ varobj_update_one (struct varobj *var, enum print_values print_values, for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i) { char *display_hint; + int from, to; if (mi_version (uiout) > 1) cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); @@ -678,8 +732,12 @@ varobj_update_one (struct varobj *var, enum print_values print_values, switch (r->status) { case VAROBJ_IN_SCOPE: - if (mi_print_value_p (varobj_get_gdb_type (r->varobj), print_values)) - ui_out_field_string (uiout, "value", varobj_get_value (r->varobj)); + if (mi_print_value_p (r->varobj, print_values)) + { + char *val = varobj_get_value (r->varobj); + ui_out_field_string (uiout, "value", val); + xfree (val); + } ui_out_field_string (uiout, "in_scope", "true"); break; case VAROBJ_NOT_IN_SCOPE: @@ -699,11 +757,11 @@ varobj_update_one (struct varobj *var, enum print_values print_values, } if (r->type_changed) - { - ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj)); - ui_out_field_int (uiout, "new_num_children", - varobj_get_num_children (r->varobj)); - } + ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj)); + + if (r->type_changed || r->children_changed) + ui_out_field_int (uiout, "new_num_children", + varobj_get_num_children (r->varobj)); display_hint = varobj_get_display_hint (var); if (display_hint) @@ -712,28 +770,59 @@ varobj_update_one (struct varobj *var, enum print_values print_values, xfree (display_hint); } - if (r->children_changed) - { - int ix; - struct varobj *child; - struct cleanup *cleanup = - make_cleanup_ui_out_list_begin_end (uiout, "children"); + if (varobj_pretty_printed_p (var)) + ui_out_field_int (uiout, "dynamic", 1); - VEC (varobj_p)* children = varobj_list_children (r->varobj); + varobj_get_child_range (r->varobj, &from, &to); + ui_out_field_int (uiout, "has_more", + varobj_has_more (r->varobj, to)); - for (ix = 0; VEC_iterate (varobj_p, children, ix, child); ++ix) + if (r->new) + { + int j; + varobj_p child; + struct cleanup *cleanup; + + cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children"); + for (j = 0; VEC_iterate (varobj_p, r->new, j, child); ++j) { struct cleanup *cleanup_child; cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); - print_varobj (child, print_values, 1 /* print expression */); + print_varobj (child, print_values, 1 /* print_expression */); do_cleanups (cleanup_child); } do_cleanups (cleanup); + VEC_free (varobj_p, r->new); + r->new = NULL; /* Paranoia. */ } - + if (mi_version (uiout) > 1) do_cleanups (cleanup); } VEC_free (varobj_update_result, changes); } + +void +mi_cmd_enable_pretty_printing (char *command, char **argv, int argc) +{ + if (argc != 0) + error (_("mi_cmd_enable_pretty_printing: no arguments allowed")); + varobj_enable_pretty_printing (); +} + +void +mi_cmd_var_set_update_range (char *command, char **argv, int argc) +{ + struct varobj *var; + int from, to; + + if (argc != 3) + error (_("mi_cmd_var_set_update_range: Usage: VAROBJ FROM TO")); + + var = varobj_get_handle (argv[0]); + from = atoi (argv[1]); + to = atoi (argv[2]); + + varobj_set_child_range (var, from, to); +} |