diff options
| author | Matthieu Longo <matthieu.longo@arm.com> | 2026-01-28 13:09:51 +0000 |
|---|---|---|
| committer | Matthieu Longo <matthieu.longo@arm.com> | 2026-04-08 11:49:30 +0100 |
| commit | e3998113f9b66cbd0806424ac4700d2aaf8d0f77 (patch) | |
| tree | acd149091afe5c465484e366064417be130ac3ec /gdb/python/python.c | |
| parent | b1cc575c428b342446143512e8b3d438b09e7c22 (diff) | |
| download | binutils-e3998113f9b66cbd0806424ac4700d2aaf8d0f77.tar.gz binutils-e3998113f9b66cbd0806424ac4700d2aaf8d0f77.tar.bz2 binutils-e3998113f9b66cbd0806424ac4700d2aaf8d0f77.zip | |
gdb: add new helpers for retrieving a type's fully qualified name
Py_TYPE (self)->tp_name is the traditional idiomatic way to get a Python
type's fully qualified name. However, in the context of the Python
limited API, PyTypeObject is opaque, so the 'tp_name' attribute is no
longer accessible. Additionally, retrieving the type of a Python object
requires Py_TYPE, which is only available as part of the stable API
starting with Python 3.14.
This patch increases minimal Python limited API version from 3.11 to 3.14.
It also introduces two new helpers to retrieve a type's fully qualified
name: gdb_py_tp_name() and gdbpy_py_obj_tp_name(), which extract the fully
qualified name from a PyTypeObject and a PyObject, respectively. Ifdefery
allows these wrappers to select the appropriate API depending on the Python
version and whether the Python limited API is enabled. For any Python
version less than 3.13, gdb_py_tp_name() fallbacks using __qualname__
instead. However, the result may differ slightly in some cases, e.g. the
module name may be missing.
Finally, this patch adapts the existing code to use these wrappers, and
adjusts some test expectations to use the fully qualified name (or
__qualname__ for versions <= 3.13) where it was not previously used.
Note that the corner case where the module name would be missing does not
appear in the testsuite.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/python.c')
| -rw-r--r-- | gdb/python/python.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c index 6e13ab5bb3f..4182c699cb5 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1579,7 +1579,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw) PyErr_Format (PyExc_TypeError, _("'style' argument must be gdb.Style or None, not %s."), - Py_TYPE (style_obj)->tp_name); + gdbpy_py_obj_tp_name (style_obj)); return nullptr; } |
