From: Matthieu Longo <matthieu.longo@arm.com>
To: <gdb-patches@sourceware.org>, Tom Tromey <tom@tromey.com>
Cc: Matthieu Longo <matthieu.longo@arm.com>
Subject: [PATCH v1 4/4] gdb/python: work around missing symbols not yet part of Python limited API
Date: Thu, 9 Apr 2026 11:51:55 +0100 [thread overview]
Message-ID: <20260409105155.1416274-5-matthieu.longo@arm.com> (raw)
In-Reply-To: <20260409105155.1416274-1-matthieu.longo@arm.com>
Most Python API usages in GDB can be migrated to the limited API, except
the following:
- PEP-741's configuration structures and functions, which use opaque
types. They were originally intended to be part of the Python limited
API, but some Python core maintainers opposed their inclusion at the
time.
- PyOS_ReadlineFunctionPointer, a global variable storing a function
used to override PyOS_StdioReadline(). The signature has remained
unchanged for a long time.
- PyRun_InteractiveLoop, used to read and execute Python statements when
embedding an interactive interpreter. Its signature has also remained
stable for a long time.
Since no limited API alternatives exist for these, and given their long
history of ABI stability, one approach is to expose them in a GDB header
and rely on their continued stability. While this is not without risk,
it seems acceptable given the arguments above. This would remove the
remaining obstacles preventing GDB from being agnostic to the Python
version available at runtime.
That said, issues should be opened on CPython issue tracker to request
that these functions be included in the limited API in future versions.
Last but not least, GDB does not need to officially support the Python
limited API. The '--enable-py-limited-api' option can remain experimental,
with appropriate forewarnings about its limitations and guarantees.
This patch adds a new header, python-limited-api-missing.h, which
exposes symbols not yet part of the Python limited API.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830
---
gdb/python/python-internal.h | 3 ++
gdb/python/python-limited-api-missing.h | 62 +++++++++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 gdb/python/python-limited-api-missing.h
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ca70ca57fd2..e85bc51f2fc 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -57,6 +57,9 @@
double quotes. On case-insensitive filesystems, this prevents us
from including our python/python.h header file. */
#include <Python.h>
+#ifdef Py_LIMITED_API
+#include "python-limited-api-missing.h"
+#endif
#include <frameobject.h>
#include "py-ref.h"
#include "py-obj-type.h"
diff --git a/gdb/python/python-limited-api-missing.h b/gdb/python/python-limited-api-missing.h
new file mode 100644
index 00000000000..07882ca1cf2
--- /dev/null
+++ b/gdb/python/python-limited-api-missing.h
@@ -0,0 +1,62 @@
+/* Gdb/Python header exposing missing symbols in the Python limited API.
+ Note: this is a workaround solution until those existing symbols below,
+ or new symbols are exposed in the limited API.
+
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDB_PYTHON_LIMITED_API_MISSING_H
+#define GDB_PYTHON_LIMITED_API_MISSING_H
+
+#ifdef Py_LIMITED_API
+extern "C"
+{
+
+/* Symbols belonging to the configuration API introduced in PEP-741, and
+ required in gdb_PyInitializer. */
+
+typedef struct PyInitConfig PyInitConfig;
+
+PyAPI_FUNC(PyInitConfig*) PyInitConfig_Create (void);
+PyAPI_FUNC(void) PyInitConfig_Free (PyInitConfig *config);
+
+PyAPI_FUNC(int) PyInitConfig_SetInt (PyInitConfig *config,
+ const char *name,
+ int64_t value);
+PyAPI_FUNC(int) PyInitConfig_SetStr (PyInitConfig *config,
+ const char *name,
+ const char *value);
+
+PyAPI_FUNC(int) PyInitConfig_GetError (PyInitConfig* config,
+ const char **err_msg);
+PyAPI_FUNC(int) PyInitConfig_GetExitCode (PyInitConfig* config,
+ int *exitcode);
+
+PyAPI_FUNC(int) Py_InitializeFromInitConfig (PyInitConfig *config);
+
+/* Handler for GDB's readline support. */
+
+PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
+
+/* Utils from Python's high level layer API. */
+
+PyAPI_FUNC(int) PyRun_InteractiveLoop (FILE *f, const char *p);
+
+}
+#endif /* Py_LIMITED_API */
+
+#endif /* GDB_PYTHON_LIMITED_API_MISSING_H */
--
2.53.0
next prev parent reply other threads:[~2026-04-09 10:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 10:51 [PATCH v1 0/4] gdb/python: more fixes again for Python limited C API support Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 1/4] gdb/python: add gdbpy_borrowed_ref Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 2/4] gdb/python: eval_python_command returns both exit code and result Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 3/4] gdb/python: migrate Python initialization to use the new config API (PEP 741) Matthieu Longo
2026-04-09 10:51 ` Matthieu Longo [this message]
2026-04-15 9:18 ` [PATCH v1 0/4] gdb/python: more fixes again for Python limited C API support Matthieu Longo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260409105155.1416274-5-matthieu.longo@arm.com \
--to=matthieu.longo@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox