From: Matthieu Longo <matthieu.longo@arm.com>
To: <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Andrew Burgess <aburgess@redhat.com>,
Matthieu Longo <matthieu.longo@arm.com>
Subject: [PATCH v2 2/2] gdb: add experimental option --enable-py-limited-api
Date: Tue, 14 Oct 2025 17:44:58 +0100 [thread overview]
Message-ID: <20251014164458.2000229-3-matthieu.longo@arm.com> (raw)
In-Reply-To: <20251014164458.2000229-1-matthieu.longo@arm.com>
Today, GDB links against the Python library using the unstable API. This
approach causes portability issues of the generated GDB artifact. Indeed
the built artifact is tighly coupled with the specific version of Python
that it was compiled with. Using a slighly minor version of Python can
cause unpredictable crashes at runtime due to ABI instability between
the Python versions, even minor ones.
The solution would consist in restricting the usage of Python functions
to the limited C API controlled via Py_LIMITED_API that must be defined
before the inclusion of <Python.h>.
This patch does not aim at porting the whole GDB codebase to the Python
limited C API, but rather enabling a development mode where developers
can experiment with the Python limited C API, and fix issues.
This development mode is accessible with the configure option
--enable-py-limited-api which is set by default to 'no'.
Note: the version of the Python limited API is currently set to 3.11
because of PyBuffer_FillInfo and PyBuffer_Release. This choice is not
frozen, and could be reviewed later on depending on newly discovered
issues during the migration.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830
---
gdb/config.in | 3 +++
gdb/configure | 34 ++++++++++++++++++++++++++++++++--
gdb/configure.ac | 16 ++++++++++++++++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/gdb/config.in b/gdb/config.in
index efc3100cb9e..2a2dcb809dd 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -710,6 +710,9 @@
/* Define if the python directory should be relocated when GDB is moved. */
#undef PYTHON_PATH_RELOCATABLE
+/* Define if GDB should be built against the Python limited C API. */
+#undef Py_LIMITED_API
+
/* Relocated directory for source files. */
#undef RELOC_SRCDIR
diff --git a/gdb/configure b/gdb/configure
index b7a2079d206..04bb60f9f1f 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -957,6 +957,7 @@ with_libexpat_prefix
with_libexpat_type
with_python
with_python_libdir
+enable_py_limited_api
with_guile
enable_gdb_compile
enable_source_highlight
@@ -1662,6 +1663,8 @@ Optional Features:
--enable-gdbtk enable gdbtk graphical user interface (GUI)
--enable-profiling enable profiling of GDB
--enable-codesign=CERT sign gdb with 'codesign -s CERT'
+ --enable-py-limited-api enable build against the Python limited C API,
+ default 'no'
--enable-gdb-compile enable support for the compile subsystem, default
'yes'
--enable-source-highlight
@@ -11888,7 +11891,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11891 "configure"
+#line 11894 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11994,7 +11997,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11997 "configure"
+#line 12000 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -28726,6 +28729,33 @@ else
fi
+# Check whether to build GDB against Python limited C API.
+# Check whether --enable-py-limited-api was given.
+if test "${enable_py_limited_api+set}" = set; then :
+ enableval=$enable_py_limited_api;
+ case $enableval in
+ yes | no)
+ ;;
+ *)
+ as_fn_error $? "bad value $enableval for --enable-py-limited-api" "$LINENO" 5
+ ;;
+ esac
+
+else
+ enable_py_limited_api=no
+fi
+
+
+if test "$enable_py_limited_api" == yes; then
+ # The minimal Python limited API version is currently set to 3.11 for the
+ # support of PyBuffer_FillInfo and PyBuffer_Release.
+ # The choice of the minimal version for the Python limited API won't be frozen
+ # until the end of the migration.
+
+$as_echo "#define Py_LIMITED_API 0x030b0000" >>confdefs.h
+
+fi
+
# -------------------- #
# Check for libguile. #
# -------------------- #
diff --git a/gdb/configure.ac b/gdb/configure.ac
index a88b6ebffe5..5e5a3a01d06 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1070,6 +1070,22 @@ AC_SUBST(PYTHON_CPPFLAGS)
AC_SUBST(PYTHON_LIBS)
AM_CONDITIONAL(HAVE_PYTHON, test "${have_libpython}" != no)
+# Check whether to build GDB against Python limited C API.
+AC_ARG_ENABLE([py-limited-api],
+ [AS_HELP_STRING([--enable-py-limited-api],
+ [enable build against the Python limited C API, default 'no'])],
+ [GDB_CHECK_YES_NO_VAL([$enableval], [--enable-py-limited-api])],
+ [enable_py_limited_api=no])
+
+if test "$enable_py_limited_api" == yes; then
+ # The minimal Python limited API version is currently set to 3.11 for the
+ # support of PyBuffer_FillInfo and PyBuffer_Release.
+ # The choice of the minimal version for the Python limited API won't be frozen
+ # until the end of the migration.
+ AC_DEFINE(Py_LIMITED_API, 0x030b0000,
+ [Define if GDB should be built against the Python limited C API.])
+fi
+
# -------------------- #
# Check for libguile. #
# -------------------- #
--
2.51.0
next prev parent reply other threads:[~2025-10-14 16:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 16:44 [PATCH v2 0/2] Add " Matthieu Longo
2025-10-14 16:44 ` [PATCH v2 1/2] gdb: make Python conftest compatible with Python limited C API Matthieu Longo
2025-10-14 16:44 ` Matthieu Longo [this message]
2025-10-20 15:23 ` [PATCH] Drop bashism from configure script Kévin Le Gouguec
2025-10-20 15:31 ` Tom Tromey
2025-10-20 15:46 ` Kévin Le Gouguec
2025-10-14 17:22 ` [PATCH v2 0/2] Add experimental option --enable-py-limited-api Eli Zaretskii
2025-10-15 9:03 ` Matthieu Longo
2025-10-15 14:01 ` Tom Tromey
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=20251014164458.2000229-3-matthieu.longo@arm.com \
--to=matthieu.longo@arm.com \
--cc=aburgess@redhat.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