aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Biesinger via gdb-patches <gdb-patches@sourceware.org>2019-05-23 16:37:29 -0500
committerTom Tromey <tromey@adacore.com>2019-06-04 09:46:06 -0600
commite1f2e1a2dadbaeffe0a8a6da7aab7effc6b046d2 (patch)
treec9b8498d0f320163e8edef62c5e2c5619028b27d
parenta9d96ab97edabea31bed089bfd4caca80838e31c (diff)
downloadgdb-e1f2e1a2dadbaeffe0a8a6da7aab7effc6b046d2.zip
gdb-e1f2e1a2dadbaeffe0a8a6da7aab7effc6b046d2.tar.gz
gdb-e1f2e1a2dadbaeffe0a8a6da7aab7effc6b046d2.tar.bz2
Add an objfile getter to gdb.Type
This allows users of the Python API to find the objfile where a type was defined. gdb/ChangeLog: gdb/ChangeLog 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. gdb/doc/ChangeLog 2019-06-04 Christian Biesinger <cbiesinger@google.com> * gdb/doc/python.texi: Document new gdb.Type.objfile property. gdb/testsuite/ChangeLog 2019-06-04 Christian Biesinger <cbiesinger@google.com> * gdb/testsuite/gdb.python/py-type.exp: Test for new gdb.Type.objfile property.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/NEWS3
-rw-r--r--gdb/doc/ChangeLog4
-rw-r--r--gdb/doc/python.texi5
-rw-r--r--gdb/python/py-type.c14
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-type.exp4
7 files changed, 41 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c17836e..933f232 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+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].
diff --git a/gdb/NEWS b/gdb/NEWS
index 41f4f7a..ded1fce 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -27,6 +27,9 @@
'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".
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 59de4e6..ea98096 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+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.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 98e52bb..f769ad0 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1087,6 +1087,11 @@ languages have this concept. If this type has no tag name, then
@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 ()
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 22cc658..7b99bea 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -413,6 +413,18 @@ typy_get_tag (PyObject *self, void *closure)
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)
@@ -1419,6 +1431,8 @@ static gdb_PyGetSetDef type_object_getset[] =
"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 }
};
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 75f87f5..af451fa 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index 734f9b4..da4d4a7 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -98,6 +98,8 @@ proc test_fields {lang} {
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"
@@ -269,6 +271,8 @@ if { [build_inferior "${binfile}" "c"] == 0 } {
# 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\\\]"