+2019-06-04 Christian Biesinger <cbiesinger@google.com>
+
+ Add objfile property to gdb.Type.
+ * gdb/NEWS: Mention Python API addition.
+ * gdb/python/py-type.c (typy_get_objfile): New method.
+
2019-06-03 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* NEWS: Mention the new set|show style [title|highlight].
'array_indexes', 'symbols', 'unions', 'deref_refs', 'actual_objects',
'static_members', 'max_elements', 'repeat_threshold', and 'format'.
+ ** gdb.Type has a new property 'objfile' which returns the objfile the
+ type was defined in.
+
* New built-in convenience variables $_shell_exitcode and $_shell_exitsignal
provide the exitcode or exit status of the shell commands launched by
GDB commands such as "shell", "pipe" and "make".
+2019-06-04 Christian Biesinger <cbiesinger@google.com>
+
+ * gdb/doc/python.texi: Document new gdb.Type.objfile property.
+
2019-06-03 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.texinfo (Help): Document the new -v apropos flag.
@code{None} is returned.
@end defvar
+@defvar Type.objfile
+The @code{gdb.Objfile} that this type was defined in, or @code{None} if
+there is no associated objfile.
+@end defvar
+
The following methods are provided:
@defun Type.fields ()
return PyString_FromString (tagname);
}
+/* Return the type's objfile, or None. */
+static PyObject *
+typy_get_objfile (PyObject *self, void *closure)
+{
+ struct type *type = ((type_object *) self)->type;
+ struct objfile *objfile = TYPE_OBJFILE (type);
+
+ if (objfile == nullptr)
+ Py_RETURN_NONE;
+ return objfile_to_objfile_object (objfile).release ();
+}
+
/* Return the type, stripped of typedefs. */
static PyObject *
typy_strip_typedefs (PyObject *self, PyObject *args)
"The size of this type, in bytes.", NULL },
{ "tag", typy_get_tag, NULL,
"The tag name for this type, or None.", NULL },
+ { "objfile", typy_get_objfile, NULL,
+ "The objfile this type was defined in, or None.", NULL },
{ NULL }
};
+2019-06-04 Christian Biesinger <cbiesinger@google.com>
+
+ * gdb/testsuite/gdb.python/py-type.exp: Test for new
+ gdb.Type.objfile property.
+
2019-06-03 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* lib/gdb.exp (help_list_trailer): New regexp variable
gdb_py_test_silent_cmd "print (st)" "print value (st)" 1
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1
gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1
+ gdb_test "python print (st.type.objfile.filename == gdb.current_progspace ().filename)" "True" \
+ "check type.objfile"
gdb_test "python print (len(fields))" "2" "check number of fields (st)"
gdb_test "python print (fields\[0\].name)" "a" "check structure field a name"
gdb_test "python print (fields\[1\].name)" "b" "check structure field b name"
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+ gdb_test "python print (gdb.lookup_type ('char').objfile)" "None"
+
gdb_test "python print(gdb.lookup_type('char').array(1, 0))" \
"char \\\[0\\\]"