enum mi_cmd_result mi_cmd_var_list_children (char *command, char **argv, int argc) { struct varobj *var; struct varobj **childlist; struct varobj **cc; struct cleanup *cleanup_children; int numchild; char *type; enum print_values print_values; if (argc != 1 && 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 (var == NULL) error (_("Variable object not found")); numchild = varobj_list_children (var, &childlist); ui_out_field_int (uiout, "numchild", numchild); if (argc == 2) print_values = mi_parse_values_option (argv[0]); else print_values = PRINT_NO_VALUES; if (numchild <= 0) return MI_CMD_DONE; 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"); cc = childlist; while (*cc != NULL) { struct cleanup *cleanup_child; cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); 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 (mi_print_value_p (varobj_get_gdb_type (*cc), print_values)) ui_out_field_string (uiout, "value", varobj_get_value (*cc)); type = varobj_get_type (*cc); /* C++ pseudo-variables (public, private, protected) do not have a type */ if (type) ui_out_field_string (uiout, "type", type); do_cleanups (cleanup_child); cc++; } do_cleanups (cleanup_children); xfree (childlist); return MI_CMD_DONE; }
void mi_cmd_var_list_children (char *command, char **argv, int argc) { struct ui_out *uiout = current_uiout; struct varobj *var; VEC(varobj_p) *children; struct varobj *child; enum print_values print_values; int ix; int from, to; char *display_hint; if (argc < 1 || argc > 4) error (_("-var-list-children: Usage: " "[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]); else var = varobj_get_handle (argv[1]); 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_print_values (argv[0]); else print_values = PRINT_NO_VALUES; display_hint = varobj_get_display_hint (var); if (display_hint) { ui_out_field_string (uiout, "displayhint", display_hint); xfree (display_hint); } if (from < to) { 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); } ui_out_field_int (uiout, "has_more", varobj_has_more (var, to)); }