aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorSiva Chandra <sivachandra@chromium.org>2013-12-27 12:20:59 -0800
committerSiva Chandra <sivachandra@chromium.org>2014-01-13 17:35:56 -0800
commitb5b08fb4ffa53ec088f8ad865bee0fd6edb2906f (patch)
tree6235384f2a58a63987bc6d661390350c178730fa /gdb/valops.c
parent13aaf454542c1028a033ac836d7a0d47c63a7029 (diff)
downloadgdb-b5b08fb4ffa53ec088f8ad865bee0fd6edb2906f.zip
gdb-b5b08fb4ffa53ec088f8ad865bee0fd6edb2906f.tar.gz
gdb-b5b08fb4ffa53ec088f8ad865bee0fd6edb2906f.tar.bz2
Use bitpos and type to lookup a gdb.Field object when its name is 'None'.
PR python/15464 PR python/16113 * valops.c (value_struct_elt_bitpos): New function * py-type.c (convert_field): Set 'name' attribute of a gdb.Field object to 'None' if the field name is an empty string (""). * python/py-value.c (valpy_getitem): Use 'bitpos' and 'type' attribute to look for a field when 'name' is 'None'. (get_field_type): New function testsuite/ * gdb.python/py-type.c: Enhance test case. * gdb.python/py-value-cc.cc: Likewise * gdb.python/py-type.exp: Add new tests. * gdb.python/py-value-cc.exp: Likewise
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index 5382c49..deb01cb 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2246,6 +2246,51 @@ value_struct_elt (struct value **argp, struct value **args,
return v;
}
+/* Given *ARGP, a value of type structure or union, or a pointer/reference
+ to a structure or union, extract and return its component (field) of
+ type FTYPE at the specified BITPOS.
+ Throw an exception on error. */
+
+struct value *
+value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
+ const char *err)
+{
+ struct type *t;
+ struct value *v;
+ int i;
+ int nbases;
+
+ *argp = coerce_array (*argp);
+
+ t = check_typedef (value_type (*argp));
+
+ while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+ {
+ *argp = value_ind (*argp);
+ if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
+ *argp = coerce_array (*argp);
+ t = check_typedef (value_type (*argp));
+ }
+
+ if (TYPE_CODE (t) != TYPE_CODE_STRUCT
+ && TYPE_CODE (t) != TYPE_CODE_UNION)
+ error (_("Attempt to extract a component of a value that is not a %s."),
+ err);
+
+ for (i = TYPE_N_BASECLASSES (t); i < TYPE_NFIELDS (t); i++)
+ {
+ if (!field_is_static (&TYPE_FIELD (t, i))
+ && bitpos == TYPE_FIELD_BITPOS (t, i)
+ && types_equal (ftype, TYPE_FIELD_TYPE (t, i)))
+ return value_primitive_field (*argp, 0, i, t);
+ }
+
+ error (_("No field with matching bitpos and type."));
+
+ /* Never hit. */
+ return NULL;
+}
+
/* Search through the methods of an object (and its bases) to find a
specified method. Return the pointer to the fn_field list of
overloaded instances.