870
968
return rootcount;
971
/* Assign a new value to a variable object. If INITIAL is non-zero,
972
this is the first assignement after the variable object was just
973
created, or changed type. In that case, just assign the value
975
Otherwise, assign the value and if type_changeable returns non-zero,
976
find if the new value is different from the current value.
977
Return 1 if so, and 0 if the values are equal.
979
The VALUE parameter should not be released -- the function will
980
take care of releasing it when needed. */
982
install_new_value (struct varobj *var, struct value *value, int initial)
987
int intentionally_not_fetched = 0;
989
/* We need to know the varobj's type to decide if the value should
990
be fetched or not. C++ fake children (public/protected/private) don't have
992
gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
993
changeable = varobj_value_is_changeable_p (var);
994
need_to_fetch = changeable;
996
/* We are not interested in the address of references, and given
997
that in C++ a reference is not rebindable, it cannot
998
meaningfully change. So, get hold of the real value. */
1001
value = coerce_ref (value);
1002
release_value (value);
1005
if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION)
1006
/* For unions, we need to fetch the value implicitly because
1007
of implementation of union member fetch. When gdb
1008
creates a value for a field and the value of the enclosing
1009
structure is not lazy, it immediately copies the necessary
1010
bytes from the enclosing values. If the enclosing value is
1011
lazy, the call to value_fetch_lazy on the field will read
1012
the data from memory. For unions, that means we'll read the
1013
same memory more than once, which is not desirable. So
1017
/* The new value might be lazy. If the type is changeable,
1018
that is we'll be comparing values of this type, fetch the
1019
value now. Otherwise, on the next update the old value
1020
will be lazy, which means we've lost that old value. */
1021
if (need_to_fetch && value && value_lazy (value))
1023
struct varobj *parent = var->parent;
1024
int frozen = var->frozen;
1025
for (; !frozen && parent; parent = parent->parent)
1026
frozen |= parent->frozen;
1028
if (frozen && initial)
1030
/* For variables that are frozen, or are children of frozen
1031
variables, we don't do fetch on initial assignment.
1032
For non-initial assignemnt we do the fetch, since it means we're
1033
explicitly asked to compare the new value with the old one. */
1034
intentionally_not_fetched = 1;
1036
else if (!gdb_value_fetch_lazy (value))
1038
/* Set the value to NULL, so that for the next -var-update,
1039
we don't try to compare the new value with this value,
1040
that we couldn't even read. */
1045
/* If the type is changeable, compare the old and the new values.
1046
If this is the initial assignment, we don't have any old value
1048
if (initial && changeable)
1049
var->print_value = value_get_print_value (value, var->format);
1050
else if (changeable)
1052
/* If the value of the varobj was changed by -var-set-value, then the
1053
value in the varobj and in the target is the same. However, that value
1054
is different from the value that the varobj had after the previous
1055
-var-update. So need to the varobj as changed. */
1058
xfree (var->print_value);
1059
var->print_value = value_get_print_value (value, var->format);
1064
/* Try to compare the values. That requires that both
1065
values are non-lazy. */
1066
if (var->not_fetched && value_lazy (var->value))
1068
/* This is a frozen varobj and the value was never read.
1069
Presumably, UI shows some "never read" indicator.
1070
Now that we've fetched the real value, we need to report
1071
this varobj as changed so that UI can show the real
1075
else if (var->value == NULL && value == NULL)
1078
else if (var->value == NULL || value == NULL)
1080
xfree (var->print_value);
1081
var->print_value = value_get_print_value (value, var->format);
1087
gdb_assert (!value_lazy (var->value));
1088
gdb_assert (!value_lazy (value));
1089
print_value = value_get_print_value (value, var->format);
1091
gdb_assert (var->print_value != NULL && print_value != NULL);
1092
if (strcmp (var->print_value, print_value) != 0)
1094
xfree (var->print_value);
1095
var->print_value = print_value;
1099
xfree (print_value);
1104
/* We must always keep the new value, since children depend on it. */
1105
if (var->value != NULL && var->value != value)
1106
value_free (var->value);
1108
if (value && value_lazy (value) && intentionally_not_fetched)
1109
var->not_fetched = 1;
1111
var->not_fetched = 0;
1114
gdb_assert (!var->value || value_type (var->value));
873
1119
/* Update the values for a variable and its children. This is a
874
1120
two-pronged attack. First, re-parse the value for the root's
875
1121
expression to see if it's changed. Then go all the way
876
1122
through its children, reconstructing them and noting if they've
879
-1 if there was an error updating the varobj
880
-2 if the type changed
881
Otherwise it is the number of children + parent changed
1125
< 0 for error values, see varobj.h.
1126
Otherwise it is the number of children + parent changed.
883
Only root variables can be updated...
1128
The EXPLICIT parameter specifies if this call is result
1129
of MI request to update this specific variable, or
1130
result of implicit -var-update *. For implicit request, we don't
1131
update frozen variables.
885
1133
NOTE: This function may delete the caller's varobj. If it
886
returns -2, then it has done this and VARP will be modified
887
to point to the new varobj. */
1134
returns TYPE_CHANGED, then it has done this and VARP will be modified
1135
to point to the new varobj. */
890
varobj_update (struct varobj **varp, struct varobj ***changelist)
1138
varobj_update (struct varobj **varp, struct varobj ***changelist,
892
1141
int changed = 0;
1142
int type_changed = 0;
897
1145
struct varobj *v;
898
1146
struct varobj **cv;
899
1147
struct varobj **templist = NULL;
900
1148
struct value *new;
901
struct vstack *stack = NULL;
902
struct vstack *result = NULL;
1149
VEC (varobj_p) *stack = NULL;
1150
VEC (varobj_p) *result = NULL;
903
1151
struct frame_id old_fid;
904
1152
struct frame_info *fi;
906
/* sanity check: have we been passed a pointer? */
907
if (changelist == NULL)
910
/* Only root variables can be updated... */
911
if ((*varp)->root->rootvar != *varp)
915
/* Save the selected stack frame, since we will need to change it
916
in order to evaluate expressions. */
917
old_fid = get_frame_id (deprecated_selected_frame);
919
/* Update the root variable. value_of_root can return NULL
920
if the variable is no longer around, i.e. we stepped out of
921
the frame in which a local existed. We are letting the
922
value_of_root variable dispose of the varobj if the type
925
new = value_of_root (varp, &type_changed);
932
/* Initialize a stack for temporary results */
933
vpush (&result, NULL);
935
/* If this is a "use_selected_frame" varobj, and its type has changed,
936
them note that it's changed. */
939
vpush (&result, *varp);
942
/* If values are not equal, note that it's changed.
943
There a couple of exceptions here, though.
944
We don't want some types to be reported as "changed". */
945
else if (type_changeable (*varp) &&
946
((*varp)->updated || !my_value_equal ((*varp)->value, new, &error)))
948
vpush (&result, *varp);
949
(*varp)->updated = 0;
951
/* Its value is going to be updated to NEW. */
952
(*varp)->error = error;
955
/* We must always keep around the new value for this root
956
variable expression, or we lose the updated children! */
957
value_free ((*varp)->value);
958
(*varp)->value = new;
960
/* Initialize a stack */
961
vpush (&stack, NULL);
963
/* Push the root's children */
964
if ((*varp)->children != NULL)
966
struct varobj_child *c;
967
for (c = (*varp)->children; c != NULL; c = c->next)
968
vpush (&stack, c->child);
971
/* Walk through the children, reconstructing them all. */
975
/* Push any children */
976
if (v->children != NULL)
978
struct varobj_child *c;
979
for (c = v->children; c != NULL; c = c->next)
980
vpush (&stack, c->child);
983
/* Update this variable */
984
new = value_of_child (v->parent, v->index);
985
if (type_changeable (v) &&
986
(v->updated || !my_value_equal (v->value, new, &error)))
988
/* Note that it's changed */
993
/* Its value is going to be updated to NEW. */
996
/* We must always keep new values, since children depend on it. */
997
if (v->value != NULL)
998
value_free (v->value);
1001
/* Get next child */
1005
/* Alloc (changed + 1) list entries */
1006
/* FIXME: add a cleanup for the allocated list(s)
1007
because one day the select_frame called below can longjump */
1154
/* sanity check: have we been passed a pointer? */
1155
gdb_assert (changelist);
1157
/* Frozen means frozen -- we don't check for any change in
1158
this varobj, including its going out of scope, or
1159
changing type. One use case for frozen varobjs is
1160
retaining previously evaluated expressions, and we don't
1161
want them to be reevaluated at all. */
1162
if (!explicit && (*varp)->frozen)
1165
if (!(*varp)->root->is_valid)
1168
if ((*varp)->root->rootvar == *varp)
1170
/* Save the selected stack frame, since we will need to change it
1171
in order to evaluate expressions. */
1172
old_fid = get_frame_id (deprecated_safe_get_selected_frame ());
1174
/* Update the root variable. value_of_root can return NULL
1175
if the variable is no longer around, i.e. we stepped out of
1176
the frame in which a local existed. We are letting the
1177
value_of_root variable dispose of the varobj if the type
1180
new = value_of_root (varp, &type_changed);
1182
/* Restore selected frame. */
1183
fi = frame_find_by_id (old_fid);
1187
/* If this is a "use_selected_frame" varobj, and its type has changed,
1188
them note that it's changed. */
1190
VEC_safe_push (varobj_p, result, *varp);
1192
if (install_new_value ((*varp), new, type_changed))
1194
/* If type_changed is 1, install_new_value will never return
1195
non-zero, so we'll never report the same variable twice. */
1196
gdb_assert (!type_changed);
1197
VEC_safe_push (varobj_p, result, *varp);
1202
/* This means the varobj itself is out of scope.
1204
VEC_free (varobj_p, result);
1205
return NOT_IN_SCOPE;
1209
VEC_safe_push (varobj_p, stack, *varp);
1211
/* Walk through the children, reconstructing them all. */
1212
while (!VEC_empty (varobj_p, stack))
1214
v = VEC_pop (varobj_p, stack);
1216
/* Push any children. Use reverse order so that the first
1217
child is popped from the work stack first, and so
1218
will be added to result first. This does not
1219
affect correctness, just "nicer". */
1220
for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
1222
varobj_p c = VEC_index (varobj_p, v->children, i);
1223
/* Child may be NULL if explicitly deleted by -var-delete. */
1224
if (c != NULL && !c->frozen)
1225
VEC_safe_push (varobj_p, stack, c);
1228
/* Update this variable, unless it's a root, which is already
1230
if (v->root->rootvar != v)
1232
new = value_of_child (v->parent, v->index);
1233
if (install_new_value (v, new, 0 /* type not changed */))
1235
/* Note that it's changed */
1236
VEC_safe_push (varobj_p, result, v);
1242
/* Alloc (changed + 1) list entries. */
1243
changed = VEC_length (varobj_p, result);
1008
1244
*changelist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1011
templist = xmalloc ((changed + 1) * sizeof (struct varobj *));
1017
/* Copy from result stack to list */
1019
*cv = vpop (&result);
1020
while ((*cv != NULL) && (vleft > 0))
1024
*cv = vpop (&result);
1027
warning (_("varobj_update: assertion failed - vleft <> 0"));
1031
/* Now we revert the order. */
1032
for (i = 0; i < changed; i++)
1033
*(*changelist + i) = *(templist + changed - 1 - i);
1034
*(*changelist + changed) = NULL;
1037
/* Restore selected frame */
1038
fi = frame_find_by_id (old_fid);
1247
for (i = 0; i < changed; ++i)
1249
*cv = VEC_index (varobj_p, result, i);
1250
gdb_assert (*cv != NULL);
1255
VEC_free (varobj_p, stack);
1256
VEC_free (varobj_p, result);
1042
1258
if (type_changed)
1259
return TYPE_CHANGED;
1045
1261
return changed;
1238
/* Does a child with the name NAME exist in VAR? If so, return its data.
1239
If not, return NULL. */
1240
static struct varobj *
1241
child_exists (struct varobj *var, char *name)
1243
struct varobj_child *vc;
1245
for (vc = var->children; vc != NULL; vc = vc->next)
1247
if (strcmp (vc->child->name, name) == 0)
1254
1453
/* Create and install a child of the parent of the given name */
1255
1454
static struct varobj *
1256
1455
create_child (struct varobj *parent, int index, char *name)
1258
1457
struct varobj *child;
1259
1458
char *childs_name;
1459
struct value *value;
1261
1461
child = new_variable ();
1263
1463
/* name is allocated by name_of_child */
1264
1464
child->name = name;
1265
1465
child->index = index;
1266
child->value = value_of_child (parent, index);
1267
if ((!CPLUS_FAKE_CHILD (child) && child->value == NULL) || parent->error)
1466
value = value_of_child (parent, index);
1269
1467
child->parent = parent;
1270
1468
child->root = parent->root;
1271
1469
childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
1272
1470
child->obj_name = childs_name;
1273
1471
install_variable (child);
1275
/* Save a pointer to this child in the parent */
1276
save_child_in_parent (parent, child);
1278
/* Note the type of this child */
1279
child->type = type_of_child (child);
1473
/* Compute the type of the child. Must do this before
1474
calling install_new_value. */
1476
/* If the child had no evaluation errors, var->value
1477
will be non-NULL and contain a valid type. */
1478
child->type = value_type (value);
1480
/* Otherwise, we must compute the type. */
1481
child->type = (*child->root->lang->type_of_child) (child->parent,
1483
install_new_value (child, value, 1);
1284
/* FIXME: This should be a generic add to list */
1285
/* Save CHILD in the PARENT's data. */
1287
save_child_in_parent (struct varobj *parent, struct varobj *child)
1289
struct varobj_child *vc;
1291
/* Insert the child at the top */
1292
vc = parent->children;
1294
(struct varobj_child *) xmalloc (sizeof (struct varobj_child));
1296
parent->children->next = vc;
1297
parent->children->child = child;
1300
/* FIXME: This should be a generic remove from list */
1301
/* Remove the CHILD from the PARENT's list of children. */
1303
remove_child_from_parent (struct varobj *parent, struct varobj *child)
1305
struct varobj_child *vc, *prev;
1307
/* Find the child in the parent's list */
1309
for (vc = parent->children; vc != NULL;)
1311
if (vc->child == child)
1318
parent->children = vc->next;
1320
prev->next = vc->next;
1817
1991
return savestring (parent->name, strlen (parent->name));
1994
/* Return the value of element TYPE_INDEX of a structure
1995
value VALUE. VALUE's type should be a structure,
1996
or union, or a typedef to struct/union.
1998
Returns NULL if getting the value fails. Never throws. */
1999
static struct value *
2000
value_struct_element_index (struct value *value, int type_index)
2002
struct value *result = NULL;
2003
volatile struct gdb_exception e;
2005
struct type *type = value_type (value);
2006
type = check_typedef (type);
2008
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
2009
|| TYPE_CODE (type) == TYPE_CODE_UNION);
2011
TRY_CATCH (e, RETURN_MASK_ERROR)
2013
if (TYPE_FIELD_STATIC (type, type_index))
2014
result = value_static_field (type, type_index);
2016
result = value_primitive_field (value, 0, type_index, type);
2028
/* Obtain the information about child INDEX of the variable
2030
If CNAME is not null, sets *CNAME to the name of the child relative
2032
If CVALUE is not null, sets *CVALUE to the value of the child.
2033
If CTYPE is not null, sets *CTYPE to the type of the child.
2035
If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
2036
information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
2039
c_describe_child (struct varobj *parent, int index,
2040
char **cname, struct value **cvalue, struct type **ctype,
2041
char **cfull_expression)
2043
struct value *value = parent->value;
2044
struct type *type = get_value_type (parent);
2045
char *parent_expression = NULL;
2054
if (cfull_expression)
2056
*cfull_expression = NULL;
2057
parent_expression = varobj_get_path_expr (parent);
2059
adjust_value_for_child_access (&value, &type, &was_ptr);
2061
switch (TYPE_CODE (type))
2063
case TYPE_CODE_ARRAY:
2065
*cname = xstrprintf ("%d", index
2066
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2068
if (cvalue && value)
2070
int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
2071
struct value *indval =
2072
value_from_longest (builtin_type_int, (LONGEST) real_index);
2073
gdb_value_subscript (value, indval, cvalue);
2077
*ctype = get_target_type (type);
2079
if (cfull_expression)
2080
*cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
2082
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
2087
case TYPE_CODE_STRUCT:
2088
case TYPE_CODE_UNION:
2091
char *string = TYPE_FIELD_NAME (type, index);
2092
*cname = savestring (string, strlen (string));
2095
if (cvalue && value)
2097
/* For C, varobj index is the same as type index. */
2098
*cvalue = value_struct_element_index (value, index);
2102
*ctype = TYPE_FIELD_TYPE (type, index);
2104
if (cfull_expression)
2106
char *join = was_ptr ? "->" : ".";
2107
*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
2108
TYPE_FIELD_NAME (type, index));
2115
*cname = xstrprintf ("*%s", parent->name);
2117
if (cvalue && value)
2118
gdb_value_ind (value, cvalue);
2120
/* Don't use get_target_type because it calls
2121
check_typedef and here, we want to show the true
2122
declared type of the variable. */
2124
*ctype = TYPE_TARGET_TYPE (type);
2126
if (cfull_expression)
2127
*cfull_expression = xstrprintf ("*(%s)", parent_expression);
2132
/* This should not happen */
2134
*cname = xstrdup ("???");
2135
if (cfull_expression)
2136
*cfull_expression = xstrdup ("???");
2137
/* Don't set value and type, we don't know then. */
1821
2142
c_name_of_child (struct varobj *parent, int index)
1824
struct type *target;
1828
type = get_type (parent);
1829
target = get_target_type (type);
1831
switch (TYPE_CODE (type))
1833
case TYPE_CODE_ARRAY:
1834
name = xstrprintf ("%d", index
1835
+ TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
1838
case TYPE_CODE_STRUCT:
1839
case TYPE_CODE_UNION:
1840
string = TYPE_FIELD_NAME (type, index);
1841
name = savestring (string, strlen (string));
1845
switch (TYPE_CODE (target))
1847
case TYPE_CODE_STRUCT:
1848
case TYPE_CODE_UNION:
1849
string = TYPE_FIELD_NAME (target, index);
1850
name = savestring (string, strlen (string));
1854
name = xstrprintf ("*%s", parent->name);
1860
/* This should not happen */
1861
name = xstrdup ("???");
2145
c_describe_child (parent, index, &name, NULL, NULL, NULL);
2150
c_path_expr_of_child (struct varobj *child)
2152
c_describe_child (child->parent, child->index, NULL, NULL, NULL,
2154
return child->path_expr;
1867
2157
static struct value *
1868
2158
c_value_of_root (struct varobj **var_handle)
1870
struct value *new_val;
2160
struct value *new_val = NULL;
1871
2161
struct varobj *var = *var_handle;
1872
2162
struct frame_info *fi;
1873
2163
int within_scope;
1875
2165
/* Only root variables can be updated... */
1876
if (var->root->rootvar != var)
2166
if (!is_root_p (var))
1877
2167
/* Not a root var */
1881
2171
/* Determine whether the variable is still around. */
1882
if (var->root->valid_block == NULL)
2172
if (var->root->valid_block == NULL || var->root->use_selected_frame)
1883
2173
within_scope = 1;
1886
reinit_frame_cache ();
1887
2176
fi = frame_find_by_id (var->root->frame);
1888
2177
within_scope = fi != NULL;
1889
2178
/* FIXME: select_frame could fail */
2181
CORE_ADDR pc = get_frame_pc (fi);
2182
if (pc < BLOCK_START (var->root->valid_block) ||
2183
pc >= BLOCK_END (var->root->valid_block))
1894
2190
if (within_scope)
1896
2192
/* We need to catch errors here, because if evaluate
1897
expression fails we just want to make val->error = 1 and
1899
if (gdb_evaluate_expression (var->root->exp, &new_val))
1901
if (value_lazy (new_val))
1903
/* We need to catch errors because if
1904
value_fetch_lazy fails we still want to continue
1905
(after making val->error = 1) */
1906
/* FIXME: Shouldn't be using value_contents()? The
1907
comment on value_fetch_lazy() says it is only called
1908
from the macro... */
1909
if (!gdb_value_fetch_lazy (new_val))
1918
release_value (new_val);
2193
expression fails we want to just return NULL. */
2194
gdb_evaluate_expression (var->root->exp, &new_val);
1919
2195
return new_val;
1925
2201
static struct value *
1926
2202
c_value_of_child (struct varobj *parent, int index)
1928
struct value *value;
1930
struct value *indval;
1931
struct type *type, *target;
1935
type = get_type (parent);
1936
target = get_target_type (type);
1937
name = name_of_child (parent, index);
1938
temp = parent->value;
1943
switch (TYPE_CODE (type))
1945
case TYPE_CODE_ARRAY:
1946
real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
1948
/* This breaks if the array lives in a (vector) register. */
1949
value = value_slice (temp, real_index, 1);
1950
temp = value_coerce_array (value);
1951
gdb_value_ind (temp, &value);
1953
indval = value_from_longest (builtin_type_int, (LONGEST) real_index);
1954
gdb_value_subscript (temp, indval, &value);
1958
case TYPE_CODE_STRUCT:
1959
case TYPE_CODE_UNION:
1960
gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1965
switch (TYPE_CODE (target))
1967
case TYPE_CODE_STRUCT:
1968
case TYPE_CODE_UNION:
1969
gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
1974
gdb_value_ind (temp, &value);
1985
release_value (value);
2204
struct value *value = NULL;
2205
c_describe_child (parent, index, NULL, &value, NULL, NULL);
1991
2210
static struct type *
1992
2211
c_type_of_child (struct varobj *parent, int index)
1995
char *name = name_of_child (parent, index);
1997
switch (TYPE_CODE (parent->type))
1999
case TYPE_CODE_ARRAY:
2000
type = get_target_type (parent->type);
2003
case TYPE_CODE_STRUCT:
2004
case TYPE_CODE_UNION:
2005
type = lookup_struct_elt_type (parent->type, name, 0);
2009
switch (TYPE_CODE (get_target_type (parent->type)))
2011
case TYPE_CODE_STRUCT:
2012
case TYPE_CODE_UNION:
2013
type = lookup_struct_elt_type (parent->type, name, 0);
2017
type = get_target_type (parent->type);
2023
/* This should not happen as only the above types have children */
2024
warning (_("Child of parent whose type does not allow children"));
2025
/* FIXME: Can we still go on? */
2213
struct type *type = NULL;
2214
c_describe_child (parent, index, NULL, NULL, &type, NULL);
2035
2219
c_variable_editable (struct varobj *var)
2037
switch (TYPE_CODE (get_type (var)))
2221
switch (TYPE_CODE (get_value_type (var)))
2039
2223
case TYPE_CODE_STRUCT:
2040
2224
case TYPE_CODE_UNION:
2041
2225
case TYPE_CODE_ARRAY:
2042
2226
case TYPE_CODE_FUNC:
2043
case TYPE_CODE_MEMBER:
2044
2227
case TYPE_CODE_METHOD:
2225
2447
have the access control we are looking for to properly
2226
2448
find the indexed field. */
2227
2449
int type_index = TYPE_N_BASECLASSES (type);
2450
enum accessibility acc = public_field;
2228
2451
if (strcmp (parent->name, "private") == 0)
2232
if (TYPE_VPTR_BASETYPE (type) == type
2233
&& type_index == TYPE_VPTR_FIELDNO (type))
2235
else if (TYPE_FIELD_PRIVATE (type, type_index))
2452
acc = private_field;
2241
2453
else if (strcmp (parent->name, "protected") == 0)
2245
if (TYPE_VPTR_BASETYPE (type) == type
2246
&& type_index == TYPE_VPTR_FIELDNO (type))
2248
else if (TYPE_FIELD_PROTECTED (type, type_index))
2258
if (TYPE_VPTR_BASETYPE (type) == type
2259
&& type_index == TYPE_VPTR_FIELDNO (type))
2261
else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
2262
!TYPE_FIELD_PROTECTED (type, type_index))
2269
name = TYPE_FIELD_NAME (type, type_index);
2454
acc = protected_field;
2458
if (TYPE_VPTR_BASETYPE (type) == type
2459
&& type_index == TYPE_VPTR_FIELDNO (type))
2461
else if (match_accessibility (type, type_index, acc))
2468
*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
2470
if (cvalue && value)
2471
*cvalue = value_struct_element_index (value, type_index);
2474
*ctype = TYPE_FIELD_TYPE (type, type_index);
2476
if (cfull_expression)
2477
*cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression,
2479
TYPE_FIELD_NAME (type, type_index));
2271
2481
else if (index < TYPE_N_BASECLASSES (type))
2272
/* We are looking up the name of a base class */
2273
name = TYPE_FIELD_NAME (type, index);
2483
/* This is a baseclass. */
2485
*cname = xstrdup (TYPE_FIELD_NAME (type, index));
2487
if (cvalue && value)
2489
*cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
2490
release_value (*cvalue);
2495
*ctype = TYPE_FIELD_TYPE (type, index);
2498
if (cfull_expression)
2500
char *ptr = was_ptr ? "*" : "";
2501
/* Cast the parent to the base' type. Note that in gdb,
2504
will create an lvalue, for all appearences, so we don't
2505
need to use more fancy:
2508
*cfull_expression = xstrprintf ("(%s(%s%s) %s)",
2510
TYPE_FIELD_NAME (type, index),
2517
char *access = NULL;
2276
2518
int children[3];
2277
cplus_class_num_children(type, children);
2519
cplus_class_num_children (type, children);
2279
2521
/* Everything beyond the baseclasses can
2280
2522
only be "public", "private", or "protected"
2338
2592
static struct value *
2339
2593
cplus_value_of_child (struct varobj *parent, int index)
2342
struct value *value;
2344
if (CPLUS_FAKE_CHILD (parent))
2345
type = get_type_deref (parent->parent);
2347
type = get_type_deref (parent);
2351
if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
2352
((TYPE_CODE (type)) == TYPE_CODE_UNION))
2354
if (CPLUS_FAKE_CHILD (parent))
2357
struct value *temp = parent->parent->value;
2362
name = name_of_child (parent, index);
2363
gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
2366
release_value (value);
2370
else if (index >= TYPE_N_BASECLASSES (type))
2372
/* public, private, or protected */
2378
if (parent->value != NULL)
2380
struct value *temp = NULL;
2382
/* No special processing for references is needed --
2383
value_cast below handles references. */
2384
if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR)
2386
if (!gdb_value_ind (parent->value, &temp))
2390
temp = parent->value;
2394
value = value_cast (TYPE_FIELD_TYPE (type, index), temp);
2395
release_value (value);
2399
/* We failed to evaluate the parent's value, so don't even
2400
bother trying to evaluate this child. */
2408
return c_value_of_child (parent, index);
2595
struct value *value = NULL;
2596
cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
2413
2600
static struct type *
2414
2601
cplus_type_of_child (struct varobj *parent, int index)
2416
struct type *type, *t;
2418
if (CPLUS_FAKE_CHILD (parent))
2420
/* Looking for the type of a child of public, private, or protected. */
2421
t = get_type_deref (parent->parent);
2424
t = get_type_deref (parent);
2427
switch (TYPE_CODE (t))
2429
case TYPE_CODE_STRUCT:
2430
case TYPE_CODE_UNION:
2431
if (CPLUS_FAKE_CHILD (parent))
2433
char *name = cplus_name_of_child (parent, index);
2434
type = lookup_struct_elt_type (t, name, 0);
2437
else if (index < TYPE_N_BASECLASSES (t))
2438
type = TYPE_FIELD_TYPE (t, index);
2451
return c_type_of_child (parent, index);
2603
struct type *type = NULL;
2604
cplus_describe_child (parent, index, NULL, NULL, &type, NULL);