From e3998113f9b66cbd0806424ac4700d2aaf8d0f77 Mon Sep 17 00:00:00 2001 From: Matthieu Longo Date: Wed, 28 Jan 2026 13:09:51 +0000 Subject: 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 --- gdb/python/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gdb/python/python.c') 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; } -- cgit v1.2.3