+2021-05-04 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * python.texi (Types In Python): Re-organize Type.fields doc.
+ Mention handling of array types. Correct doc for when calling
+ the method on another type.
+
2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.texinfo (Initialization Files): Use @env when referencing
The following methods are provided:
@defun Type.fields ()
-For structure and union types, this method returns the fields. Range
-types have two fields, the minimum and maximum values. Enum types
-have one field per enum constant. Function and method types have one
-field per parameter. The base types of C@t{++} classes are also
-represented as fields. If the type has no fields, or does not fit
-into one of these categories, an empty sequence will be returned.
+
+Return the fields of this type. The behavior depends on the type code:
+
+@itemize @bullet
+
+@item
+For structure and union types, this method returns the fields.
+
+@item
+Range types have two fields, the minimum and maximum values.
+
+@item
+Enum types have one field per enum constant.
+
+@item
+Function and method types have one field per parameter. The base types of
+C@t{++} classes are also represented as fields.
+
+@item
+Array types have one field representing the array's range.
+
+@item
+If the type does not fit into one of these categories, a @code{TypeError}
+is raised.
+
+@end itemize
Each field is a @code{gdb.Field} object, with some pre-defined attributes:
@table @code
+2021-05-04 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * gdb.python/py-type.exp (test_fields): Test calling fields on
+ an int type.
+
2021-05-04 Simon Marchi <simon.marchi@efficios.com>
* gdb.python/flexible-array-member.exp: Adjust expected range
gdb_test "python print (len (gdb.parse_and_eval ('a_function').type.fields ()))" "2"
gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[0\].type)" "int"
gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[1\].type)" "char"
+
+ # Test calling `fields` on a non-aggregate type.
+ gdb_test "python gdb.lookup_type('int').fields()" "TypeError: Type is not a structure, union, enum, or function type.*"
}
}