int is_explicit)
{
struct ui_out *uiout = current_uiout;
- VEC (varobj_update_result) *changes;
- varobj_update_result *r;
- int i;
-
- changes = varobj_update (&var, is_explicit);
+
+ std::vector<varobj_update_result> changes = varobj_update (&var, is_explicit);
- for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
+ for (const varobj_update_result &r : changes)
{
int from, to;
gdb::optional<ui_out_emit_tuple> tuple_emitter;
if (mi_version (uiout) > 1)
tuple_emitter.emplace (uiout, nullptr);
- uiout->field_string ("name", varobj_get_objname (r->varobj));
+ uiout->field_string ("name", varobj_get_objname (r.varobj));
- switch (r->status)
+ switch (r.status)
{
case VAROBJ_IN_SCOPE:
- if (mi_print_value_p (r->varobj, print_values))
+ if (mi_print_value_p (r.varobj, print_values))
{
- std::string val = varobj_get_value (r->varobj);
+ std::string val = varobj_get_value (r.varobj);
uiout->field_string ("value", val.c_str ());
}
break;
}
- if (r->status != VAROBJ_INVALID)
+ if (r.status != VAROBJ_INVALID)
{
- if (r->type_changed)
+ if (r.type_changed)
uiout->field_string ("type_changed", "true");
else
uiout->field_string ("type_changed", "false");
}
- if (r->type_changed)
+ if (r.type_changed)
{
- std::string type_name = varobj_get_type (r->varobj);
+ std::string type_name = varobj_get_type (r.varobj);
uiout->field_string ("new_type", type_name.c_str ());
}
- if (r->type_changed || r->children_changed)
+ if (r.type_changed || r.children_changed)
uiout->field_int ("new_num_children",
- varobj_get_num_children (r->varobj));
+ varobj_get_num_children (r.varobj));
gdb::unique_xmalloc_ptr<char> display_hint
- = varobj_get_display_hint (r->varobj);
+ = varobj_get_display_hint (r.varobj);
if (display_hint)
uiout->field_string ("displayhint", display_hint.get ());
- if (varobj_is_dynamic_p (r->varobj))
+ if (varobj_is_dynamic_p (r.varobj))
uiout->field_int ("dynamic", 1);
- varobj_get_child_range (r->varobj, &from, &to);
- uiout->field_int ("has_more", varobj_has_more (r->varobj, to));
+ varobj_get_child_range (r.varobj, &from, &to);
+ uiout->field_int ("has_more", varobj_has_more (r.varobj, to));
- if (r->newobj)
+ if (!r.newobj.empty ())
{
- int j;
- varobj_p child;
-
ui_out_emit_list list_emitter (uiout, "new_children");
- for (j = 0; VEC_iterate (varobj_p, r->newobj, j, child); ++j)
+
+ for (varobj *child : r.newobj)
{
ui_out_emit_tuple tuple_emitter (uiout, NULL);
print_varobj (child, print_values, 1 /* print_expression */);
}
-
- VEC_free (varobj_p, r->newobj);
- r->newobj = NULL; /* Paranoia. */
}
}
- VEC_free (varobj_update_result, changes);
}
void
static void
install_dynamic_child (struct varobj *var,
- VEC (varobj_p) **changed,
- VEC (varobj_p) **type_changed,
- VEC (varobj_p) **newobj,
- VEC (varobj_p) **unchanged,
+ std::vector<varobj *> *changed,
+ std::vector<varobj *> *type_changed,
+ std::vector<varobj *> *newobj,
+ std::vector<varobj *> *unchanged,
int *cchanged,
int index,
struct varobj_item *item)
/* There's no child yet. */
struct varobj *child = varobj_add_child (var, item);
- if (newobj)
+ if (newobj != NULL)
{
- VEC_safe_push (varobj_p, *newobj, child);
+ newobj->push_back (child);
*cchanged = 1;
}
}
if (type_updated)
{
- if (type_changed)
- VEC_safe_push (varobj_p, *type_changed, existing);
+ if (type_changed != NULL)
+ type_changed->push_back (existing);
}
if (install_new_value (existing, item->value, 0))
{
- if (!type_updated && changed)
- VEC_safe_push (varobj_p, *changed, existing);
+ if (!type_updated && changed != NULL)
+ changed->push_back (existing);
}
- else if (!type_updated && unchanged)
- VEC_safe_push (varobj_p, *unchanged, existing);
+ else if (!type_updated && unchanged != NULL)
+ unchanged->push_back (existing);
}
}
static int
update_dynamic_varobj_children (struct varobj *var,
- VEC (varobj_p) **changed,
- VEC (varobj_p) **type_changed,
- VEC (varobj_p) **newobj,
- VEC (varobj_p) **unchanged,
+ std::vector<varobj *> *changed,
+ std::vector<varobj *> *type_changed,
+ std::vector<varobj *> *newobj,
+ std::vector<varobj *> *unchanged,
int *cchanged,
int update_children,
int from,
returns TYPE_CHANGED, then it has done this and VARP will be modified
to point to the new varobj. */
-VEC(varobj_update_result) *
+std::vector<varobj_update_result>
varobj_update (struct varobj **varp, int is_explicit)
{
int type_changed = 0;
- int i;
struct value *newobj;
- VEC (varobj_update_result) *stack = NULL;
- VEC (varobj_update_result) *result = NULL;
+ std::vector<varobj_update_result> stack;
+ std::vector<varobj_update_result> result;
/* Frozen means frozen -- we don't check for any change in
this varobj, including its going out of scope, or
if (!(*varp)->root->is_valid)
{
- varobj_update_result r = {0};
-
- r.varobj = *varp;
- r.status = VAROBJ_INVALID;
- VEC_safe_push (varobj_update_result, result, &r);
+ result.emplace_back (*varp, VAROBJ_INVALID);
return result;
}
if ((*varp)->root->rootvar == *varp)
{
- varobj_update_result r = {0};
-
- r.varobj = *varp;
- r.status = VAROBJ_IN_SCOPE;
+ varobj_update_result r (*varp);
/* Update the root variable. value_of_root can return NULL
if the variable is no longer around, i.e. we stepped out of
if (r.status == VAROBJ_NOT_IN_SCOPE)
{
if (r.type_changed || r.changed)
- VEC_safe_push (varobj_update_result, result, &r);
+ result.push_back (std::move (r));
+
return result;
}
-
- VEC_safe_push (varobj_update_result, stack, &r);
- }
- else
- {
- varobj_update_result r = {0};
- r.varobj = *varp;
- VEC_safe_push (varobj_update_result, stack, &r);
+ stack.push_back (std::move (r));
}
+ else
+ stack.emplace_back (*varp);
/* Walk through the children, reconstructing them all. */
- while (!VEC_empty (varobj_update_result, stack))
+ while (!stack.empty ())
{
- varobj_update_result r = *(VEC_last (varobj_update_result, stack));
+ varobj_update_result r = std::move (stack.back ());
+ stack.pop_back ();
struct varobj *v = r.varobj;
- VEC_pop (varobj_update_result, stack);
-
/* Update this variable, unless it's a root, which is already
updated. */
if (!r.value_installed)
for which -var-list-children was never invoked. */
if (varobj_is_dynamic_p (v))
{
- VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
- VEC (varobj_p) *newobj = 0;
- int i, children_changed = 0;
+ std::vector<varobj *> changed, type_changed, unchanged, newobj;
+ int children_changed = 0;
if (v->frozen)
continue;
}
if (r.changed)
- VEC_safe_push (varobj_update_result, result, &r);
+ result.push_back (std::move (r));
continue;
}
&unchanged, &children_changed, 1,
v->from, v->to))
{
- if (children_changed || newobj)
+ if (children_changed || !newobj.empty ())
{
r.children_changed = 1;
- r.newobj = newobj;
+ r.newobj = std::move (newobj);
}
/* Push in reverse order so that the first child is
popped from the work stack first, and so will be
added to result first. This does not affect
correctness, just "nicer". */
- for (i = VEC_length (varobj_p, type_changed) - 1; i >= 0; --i)
+ for (int i = type_changed.size () - 1; i >= 0; --i)
{
- varobj_p tmp = VEC_index (varobj_p, type_changed, i);
- varobj_update_result r = {0};
+ varobj_update_result r (type_changed[i]);
/* Type may change only if value was changed. */
- r.varobj = tmp;
r.changed = 1;
r.type_changed = 1;
r.value_installed = 1;
- VEC_safe_push (varobj_update_result, stack, &r);
+
+ stack.push_back (std::move (r));
}
- for (i = VEC_length (varobj_p, changed) - 1; i >= 0; --i)
+ for (int i = changed.size () - 1; i >= 0; --i)
{
- varobj_p tmp = VEC_index (varobj_p, changed, i);
- varobj_update_result r = {0};
+ varobj_update_result r (changed[i]);
- r.varobj = tmp;
r.changed = 1;
r.value_installed = 1;
- VEC_safe_push (varobj_update_result, stack, &r);
+
+ stack.push_back (std::move (r));
}
- for (i = VEC_length (varobj_p, unchanged) - 1; i >= 0; --i)
- {
- varobj_p tmp = VEC_index (varobj_p, unchanged, i);
-
- if (!tmp->frozen)
- {
- varobj_update_result r = {0};
-
- r.varobj = tmp;
- r.value_installed = 1;
- VEC_safe_push (varobj_update_result, stack, &r);
- }
- }
- if (r.changed || r.children_changed)
- VEC_safe_push (varobj_update_result, result, &r);
+ for (int i = unchanged.size () - 1; i >= 0; --i)
+ {
+ if (!unchanged[i]->frozen)
+ {
+ varobj_update_result r (unchanged[i]);
- /* Free CHANGED, TYPE_CHANGED and UNCHANGED, but not NEW,
- because NEW has been put into the result vector. */
- VEC_free (varobj_p, changed);
- VEC_free (varobj_p, type_changed);
- VEC_free (varobj_p, unchanged);
+ r.value_installed = 1;
+
+ stack.push_back (std::move (r));
+ }
+ }
+ if (r.changed || r.children_changed)
+ result.push_back (std::move (r));
continue;
}
child is popped from the work stack first, and so
will be added to result first. This does not
affect correctness, just "nicer". */
- for (i = v->children.size () - 1; i >= 0; --i)
+ for (int i = v->children.size () - 1; i >= 0; --i)
{
varobj *c = v->children[i];
/* Child may be NULL if explicitly deleted by -var-delete. */
if (c != NULL && !c->frozen)
- {
- varobj_update_result r = {0};
-
- r.varobj = c;
- VEC_safe_push (varobj_update_result, stack, &r);
- }
+ stack.emplace_back (c);
}
if (r.changed || r.type_changed)
- VEC_safe_push (varobj_update_result, result, &r);
+ result.push_back (std::move (r));
}
- VEC_free (varobj_update_result, stack);
-
return result;
}
-\f
/* Helper functions */