From be973afe9ced35af898717ac2389bbd0fb053fcd Mon Sep 17 00:00:00 2001 From: WizardHowl Date: Thu, 27 Jul 2023 02:50:52 +0000 Subject: [PATCH 1/3] gdb: initialize the data_head variable to eliminate Signed-off-by: WizardHowl --- ...he-data_head-variable-to-eliminate-c.patch | 45 +++++++++++++++++++ gdb.spec | 6 ++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gdb-initialize-the-data_head-variable-to-eliminate-c.patch diff --git a/gdb-initialize-the-data_head-variable-to-eliminate-c.patch b/gdb-initialize-the-data_head-variable-to-eliminate-c.patch new file mode 100644 index 0000000..1861a3f --- /dev/null +++ b/gdb-initialize-the-data_head-variable-to-eliminate-c.patch @@ -0,0 +1,45 @@ +From 44ca285b73b68f6a8fa3e89004b510d6b7d98e91 Mon Sep 17 00:00:00 2001 +From: Enze Li +Date: Sat, 11 Jun 2022 18:36:48 +0800 +Subject: [PATCH] gdb: initialize the data_head variable to eliminate + compilation warnings +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +On a machine with gcc 12, I get this warning: + + CXX nat/linux-btrace.o +In function ‘btrace_error linux_read_bts(btrace_data_bts*, btrace_target_info*, btrace_read_type)’, + inlined from ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-btrace.c:935:29: +../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used uninitialized [-Wmaybe-uninitialized] + 865 | pevent->last_head = data_head; + | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ +../gdb/nat/linux-btrace.c: In function ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’: +../gdb/nat/linux-btrace.c:792:9: note: ‘data_head’ was declared here + 792 | __u64 data_head, data_tail; + | ^~~~~~~~~ + +Fix this by initializing the 'data_head' variable. + +Tested by rebuilding on x86_64 openSUSE Tumbleweed with gcc 12. +--- + gdb/nat/linux-btrace.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c +index b0d6dcd7cf1..c31fb5ffe43 100644 +--- a/gdb/nat/linux-btrace.c ++++ b/gdb/nat/linux-btrace.c +@@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts *btrace, + struct perf_event_buffer *pevent; + const uint8_t *begin, *end, *start; + size_t buffer_size, size; +- __u64 data_head, data_tail; ++ __u64 data_head = 0, data_tail; + unsigned int retries = 5; + + pevent = &tinfo->variant.bts.bts; +-- +2.33.0 + diff --git a/gdb.spec b/gdb.spec index 743822c..c48e428 100644 --- a/gdb.spec +++ b/gdb.spec @@ -1,6 +1,6 @@ Name: gdb Version: 12.1 -Release: 3 +Release: 4 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL-1.3 Source: https://ftp.gnu.org/gnu/gdb/gdb-%{version}.tar.xz @@ -88,6 +88,7 @@ Patch76: gdb-sw22395-constify-target_desc.patch Patch77: 0001-set-entry-point-when-text-segment-is-missing.patch Patch78: 0002-Add-support-for-readline-8.2.patch +Patch79: gdb-initialize-the-data_head-variable-to-eliminate-c.patch %global gdb_src gdb-%{version} %global gdb_build build-%{_target_platform} @@ -363,6 +364,9 @@ rm -f $RPM_BUILD_ROOT%{_datadir}/gdb/python/gdb/command/backtrace.py %{_infodir}/ctf-spec.info.gz %changelog +* Thu Jul 27 2023 Wenyu Liu - 12.1-4 +- initialize the data_head variable to eliminate compilation warnings + * Tue Feb 14 2023 Wenyu Liu - 12.1-3 - Rectify the spec file. -- Gitee From 2eb8f50a82f89b5a1629c621c54cb7d9298d0595 Mon Sep 17 00:00:00 2001 From: WizardHowl Date: Thu, 27 Jul 2023 13:00:35 +0000 Subject: [PATCH 2/3] Handle Python 3.11 deprecation of PySys_SetPath and Py_SetProgramName Reference:https://sourceware.org/bugzilla/show_bug.cgi?id=28668 https://sourceware.org/bugzilla/show_bug.cgi?id=29287 Confilict:gdb/python/python.c Signed-off-by: WizardHowl --- ...11-deprecation-of-PySys_SetPath-and-.patch | 256 +++ gdb-Make-import-gdb.events-work.patch | 192 +++ gdb-Use-bool-for-evregpy_no_listeners_p.patch | 40 + gdb-python-remove-Python-2-support.patch | 1375 +++++++++++++++++ gdb.spec | 9 +- 5 files changed, 1871 insertions(+), 1 deletion(-) create mode 100644 gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch create mode 100644 gdb-Make-import-gdb.events-work.patch create mode 100644 gdb-Use-bool-for-evregpy_no_listeners_p.patch create mode 100644 gdb-python-remove-Python-2-support.patch diff --git a/gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch b/gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch new file mode 100644 index 0000000..11f4a8a --- /dev/null +++ b/gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch @@ -0,0 +1,256 @@ +From eb6d8345fb21aa4eba9b02289645f3265c02175b Mon Sep 17 00:00:00 2001 +From: Kevin Buettner +Date: Thu, 30 Jun 2022 15:40:29 -0700 +Subject: [PATCH] Handle Python 3.11 deprecation of PySys_SetPath and + Py_SetProgramName + +Python 3.11 deprecates PySys_SetPath and Py_SetProgramName. The +PyConfig API replaces these and other functions. This commit uses the +PyConfig API to provide equivalent functionality while also preserving +support for older versions of Python, i.e. those before Python 3.8. + +A beta version of Python 3.11 is available in Fedora Rawhide. Both +Fedora 35 and Fedora 36 use Python 3.10, while Fedora 34 still used +Python 3.9. I've tested these changes on Fedora 34, Fedora 36, and +rawhide, though complete testing was not possible on rawhide due to +a kernel bug. That being the case, I decided to enable the newer +PyConfig API by testing PY_VERSION_HEX against 0x030a0000. This +corresponds to Python 3.10. + +We could try to use the PyConfig API for Python versions as early as 3.8, +but I'm reluctant to do this as there may have been PyConfig related +bugs in earlier versions which have since been fixed. Recent linux +distributions should have support for Python 3.10. This should be +more than adequate for testing the new Python initialization code in +GDB. + +Information about the PyConfig API as well as the motivation behind +deprecating the old interface can be found at these links: + +https://github.com/python/cpython/issues/88279 +https://peps.python.org/pep-0587/ +https://docs.python.org/3.11/c-api/init_config.html + +The v2 commit also addresses several problems that Simon found in +the v1 version. + +In v1, I had used Py_DontWriteBytecodeFlag in the new initialization +code, but Simon pointed out that this global configuration variable +will be deprecated in Python 3.12. This version of the patch no longer +uses Py_DontWriteBytecodeFlag in the new initialization code. +Additionally, both Py_DontWriteBytecodeFlag and Py_IgnoreEnvironmentFlag +will no longer be used when building GDB against Python 3.10 or higher. +While it's true that both of these global configuration variables are +deprecated in Python 3.12, it makes sense to disable their use for +gdb builds against 3.10 and higher since those are the versions for +which the PyConfig API is now being used by GDB. (The PyConfig API +includes different mechanisms for making the same settings afforded +by use of the soon-to-be deprecated global configuration variables.) + +Simon also noted that PyConfig_Clear() would not have be called for +one of the failure paths. I've fixed that problem and also made the +rest of the "bail out" code more direct. In particular, +PyConfig_Clear() will always be called, both for success and failure. + +The v3 patch addresses some rebase conflicts related to module +initialization . Commit 3acd9a692dd ("Make 'import gdb.events' work") +uses PyImport_ExtendInittab instead of PyImport_AppendInittab. That +commit also initializes a struct for each module to import. Both the +initialization and the call to were moved ahead of the ifdefs to avoid +having to replicate (at least some of) the code three times in various +portions of the ifdefs. + +Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28668 +Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29287 +--- + gdb/python/python-internal.h | 5 ++ + gdb/python/python.c | 99 +++++++++++++++++++++++++++++------- + 2 files changed, 86 insertions(+), 18 deletions(-) + +diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h +index 84f45ca..70808c9 100644 +--- a/gdb/python/python-internal.h ++++ b/gdb/python/python-internal.h +@@ -199,6 +199,10 @@ gdb_PySys_GetObject (const char *name) + + #define PySys_GetObject gdb_PySys_GetObject + ++/* PySys_SetPath was deprecated in Python 3.11. Disable the deprecated ++ code for Python 3.10 and newer. */ ++#if PY_VERSION_HEX < 0x030a0000 ++ + /* PySys_SetPath's 'path' parameter was missing the 'const' qualifier + before Python 3.6. Hence, we wrap it in a function to avoid errors + when compiled with -Werror. */ +@@ -212,6 +216,7 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path) + } + + #define PySys_SetPath gdb_PySys_SetPath ++#endif + + /* Wrap PyGetSetDef to allow convenient construction with string + literals. Unfortunately, PyGetSetDef's 'name' and 'doc' members +diff --git a/gdb/python/python.c b/gdb/python/python.c +index e3f2550..97f421d 100644 +--- a/gdb/python/python.c ++++ b/gdb/python/python.c +@@ -1709,8 +1709,14 @@ set_python_ignore_environment (const char *args, int from_tty, + struct cmd_list_element *c) + { + #ifdef HAVE_PYTHON ++ /* Py_IgnoreEnvironmentFlag is deprecated in Python 3.12. Disable ++ its usage in Python 3.10 and above since the PyConfig mechanism ++ is now (also) used in 3.10 and higher. See do_start_initialization() ++ in this file. */ ++#if PY_VERSION_HEX < 0x030a0000 + Py_IgnoreEnvironmentFlag = python_ignore_environment ? 1 : 0; + #endif ++#endif + } + + /* When this is turned on before Python is initialised then Python will +@@ -1738,6 +1744,24 @@ show_python_dont_write_bytecode (struct ui_file *file, int from_tty, + value); + } + ++/* Return value to assign to PyConfig.write_bytecode or, when ++ negated (via !), Py_DontWriteBytecodeFlag. Py_DontWriteBytecodeFlag ++ is deprecated in Python 3.12. */ ++ ++static int ++python_write_bytecode () ++{ ++ int wbc = 0; ++ ++ if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO) ++ wbc = (!python_ignore_environment ++ && getenv ("PYTHONDONTWRITEBYTECODE") != nullptr) ? 0 : 1; ++ else ++ wbc = python_dont_write_bytecode == AUTO_BOOLEAN_TRUE ? 0 : 1; ++ ++ return wbc; ++} ++ + /* Implement 'set python dont-write-bytecode'. This sets Python's internal + flag no matter when the command is issued, however, if this is used + after Py_Initialize has been called then many modules could already +@@ -1748,13 +1772,13 @@ set_python_dont_write_bytecode (const char *args, int from_tty, + struct cmd_list_element *c) + { + #ifdef HAVE_PYTHON +- if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO) +- Py_DontWriteBytecodeFlag +- = (!python_ignore_environment +- && getenv ("PYTHONDONTWRITEBYTECODE") != nullptr) ? 1 : 0; +- else +- Py_DontWriteBytecodeFlag +- = python_dont_write_bytecode == AUTO_BOOLEAN_TRUE ? 1 : 0; ++ /* Py_DontWriteBytecodeFlag is deprecated in Python 3.12. Disable ++ its usage in Python 3.10 and above since the PyConfig mechanism ++ is now (also) used in 3.10 and higher. See do_start_initialization() ++ in this file. */ ++#if PY_VERSION_HEX < 0x030a0000 ++ Py_DontWriteBytecodeFlag = !python_write_bytecode (); ++#endif + #endif /* HAVE_PYTHON */ + } + +@@ -1856,6 +1880,18 @@ gdbpy_gdb_exiting (int exit_code) + static bool + do_start_initialization () + { ++ /* Define all internal modules. These are all imported (and thus ++ created) during initialization. */ ++ struct _inittab mods[] = ++ { ++ { "_gdb", init__gdb_module }, ++ { "_gdbevents", gdbpy_events_mod_func }, ++ { nullptr, nullptr } ++ }; ++ ++ if (PyImport_ExtendInittab (mods) < 0) ++ return false; ++ + #ifdef WITH_PYTHON_PATH + /* Work around problem where python gets confused about where it is, + and then can't find its libraries, etc. +@@ -1887,25 +1923,41 @@ do_start_initialization () + } + setlocale (LC_ALL, oldloc.c_str ()); + ++ /* Py_SetProgramName was deprecated in Python 3.11. Use PyConfig ++ mechanisms for Python 3.10 and newer. */ ++#if PY_VERSION_HEX < 0x030a0000 + /* Note that Py_SetProgramName expects the string it is passed to + remain alive for the duration of the program's execution, so + it is not freed after this call. */ + Py_SetProgramName (progname_copy); +-#endif ++ Py_Initialize (); ++#else ++ PyConfig config; + +- /* Define all internal modules. These are all imported (and thus +- created) during initialization. */ +- struct _inittab mods[3] = +- { +- { "_gdb", init__gdb_module }, +- { "_gdbevents", gdbpy_events_mod_func }, +- { nullptr, nullptr } +- }; ++ PyConfig_InitPythonConfig (&config); ++ PyStatus status = PyConfig_SetString (&config, &config.program_name, ++ progname_copy); ++ if (PyStatus_Exception (status)) ++ goto init_done; + +- if (PyImport_ExtendInittab (mods) < 0) +- return false; ++ config.write_bytecode = python_write_bytecode (); ++ config.use_environment = !python_ignore_environment; + ++ status = PyConfig_Read (&config); ++ if (PyStatus_Exception (status)) ++ goto init_done; ++ ++ status = Py_InitializeFromConfig (&config); ++ ++init_done: ++ PyConfig_Clear (&config); ++ if (PyStatus_Exception (status)) ++ return false; ++#endif ++#else + Py_Initialize (); ++#endif ++ + #if PY_VERSION_HEX < 0x03090000 + /* PyEval_InitThreads became deprecated in Python 3.9 and will + be removed in Python 3.11. Prior to Python 3.7, this call was +@@ -2210,12 +2262,23 @@ do_initialize (const struct extension_language_defn *extlang) + + sys_path = PySys_GetObject ("path"); + ++ /* PySys_SetPath was deprecated in Python 3.11. Disable this ++ deprecated code for Python 3.10 and newer. Also note that this ++ ifdef eliminates potential initialization of sys.path via ++ PySys_SetPath. My (kevinb's) understanding of PEP 587 suggests ++ that it's not necessary due to module_search_paths being ++ initialized to an empty list following any of the PyConfig ++ initialization functions. If it does turn out that some kind of ++ initialization is still needed, it should be added to the ++ PyConfig-based initialization in do_start_initialize(). */ ++#if PY_VERSION_HEX < 0x030a0000 + /* If sys.path is not defined yet, define it first. */ + if (!(sys_path && PyList_Check (sys_path))) + { + PySys_SetPath (L""); + sys_path = PySys_GetObject ("path"); + } ++#endif + if (sys_path && PyList_Check (sys_path)) + { + gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ())); +-- +2.33.0 + diff --git a/gdb-Make-import-gdb.events-work.patch b/gdb-Make-import-gdb.events-work.patch new file mode 100644 index 0000000..15614dd --- /dev/null +++ b/gdb-Make-import-gdb.events-work.patch @@ -0,0 +1,192 @@ +From 139266420fbff31e3309235ac8e1836d19a065c7 Mon Sep 17 00:00:00 2001 +From: Tom Tromey +Date: Fri, 3 Jun 2022 07:59:49 -0600 +Subject: [PATCH] Make 'import gdb.events' work + +Pierre-Marie noticed that, while gdb.events is a Python module, it +can't be imported. This patch changes how this module is created, so +that it can be imported, while also ensuring that the module is always +visible, just as it was in the past. + +This new approach required one non-obvious change -- when running +gdb.base/warning.exp, where --data-directory is intentionally not +found, the event registries can now be nullptr. Consequently, this +patch probably also requires + + https://sourceware.org/pipermail/gdb-patches/2022-June/189796.html + +Note that this patch obsoletes + + https://sourceware.org/pipermail/gdb-patches/2022-June/189797.html +--- + gdb/python/lib/gdb/__init__.py | 5 +++++ + gdb/python/py-evtregistry.c | 4 +++- + gdb/python/py-evts.c | 28 ++++++++++++-------------- + gdb/python/python-internal.h | 4 ++-- + gdb/python/python.c | 16 +++++++++++---- + gdb/testsuite/gdb.python/py-events.exp | 2 ++ + 6 files changed, 37 insertions(+), 22 deletions(-) + +diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py +index a52f6b4..17ee6a1 100644 +--- a/gdb/python/lib/gdb/__init__.py ++++ b/gdb/python/lib/gdb/__init__.py +@@ -27,6 +27,11 @@ else: + + from _gdb import * + ++# Historically, gdb.events was always available, so ensure it's ++# still available without an explicit import. ++import _gdbevents as events ++sys.modules['gdb.events'] = events ++ + + class _GdbFile(object): + # These two are needed in Python 3 +diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c +index ef96c48..f3a7f0c 100644 +--- a/gdb/python/py-evtregistry.c ++++ b/gdb/python/py-evtregistry.c +@@ -118,7 +118,9 @@ gdbpy_initialize_eventregistry (void) + bool + evregpy_no_listeners_p (eventregistry_object *registry) + { +- return PyList_Size (registry->callbacks) == 0; ++ /* REGISTRY can be nullptr if gdb failed to find the data directory ++ at startup. */ ++ return registry == nullptr || PyList_Size (registry->callbacks) == 0; + } + + static PyMethodDef eventregistry_object_methods[] = +diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c +index 23a5d75..ca9326a 100644 +--- a/gdb/python/py-evts.c ++++ b/gdb/python/py-evts.c +@@ -23,7 +23,7 @@ + static struct PyModuleDef EventModuleDef = + { + PyModuleDef_HEAD_INIT, +- "gdb.events", ++ "_gdbevents", + NULL, + -1, + NULL, +@@ -33,7 +33,8 @@ static struct PyModuleDef EventModuleDef = + NULL + }; + +-/* Initialize python events. */ ++/* Helper function to add a single event registry to the events ++ module. */ + + static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION + add_new_registry (eventregistry_object **registryp, const char *name) +@@ -48,24 +49,21 @@ add_new_registry (eventregistry_object **registryp, const char *name) + (PyObject *)(*registryp)); + } + +-int +-gdbpy_initialize_py_events (void) ++/* Create and populate the _gdbevents module. Note that this is ++ always created, see the base gdb __init__.py. */ ++ ++PyMODINIT_FUNC ++gdbpy_events_mod_func () + { + gdb_py_events.module = PyModule_Create (&EventModuleDef); ++ if (gdb_py_events.module == nullptr) ++ return nullptr; + +- if (!gdb_py_events.module) +- return -1; +- +-#define GDB_PY_DEFINE_EVENT(name) \ ++#define GDB_PY_DEFINE_EVENT(name) \ + if (add_new_registry (&gdb_py_events.name, #name) < 0) \ +- return -1; ++ return nullptr; + #include "py-all-events.def" + #undef GDB_PY_DEFINE_EVENT + +- if (gdb_pymodule_addobject (gdb_module, +- "events", +- (PyObject *) gdb_py_events.module) < 0) +- return -1; +- +- return 0; ++ return gdb_py_events.module; + } +diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h +index e3a3fc4..84f45ca 100644 +--- a/gdb/python/python-internal.h ++++ b/gdb/python/python-internal.h +@@ -536,8 +536,6 @@ int gdbpy_initialize_eventregistry (void) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; + int gdbpy_initialize_event (void) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; +-int gdbpy_initialize_py_events (void) +- CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; + int gdbpy_initialize_arch (void) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; + int gdbpy_initialize_registers () +@@ -556,6 +554,8 @@ int gdbpy_initialize_micommands (void) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; + void gdbpy_finalize_micommands (); + ++PyMODINIT_FUNC gdbpy_events_mod_func (); ++ + /* A wrapper for PyErr_Fetch that handles reference counting for the + caller. */ + class gdbpy_err_fetch +diff --git a/gdb/python/python.c b/gdb/python/python.c +index e97bca7..e3f2550 100644 +--- a/gdb/python/python.c ++++ b/gdb/python/python.c +@@ -1891,11 +1891,20 @@ do_start_initialization () + remain alive for the duration of the program's execution, so + it is not freed after this call. */ + Py_SetProgramName (progname_copy); +- +- /* Define _gdb as a built-in module. */ +- PyImport_AppendInittab ("_gdb", init__gdb_module); + #endif + ++ /* Define all internal modules. These are all imported (and thus ++ created) during initialization. */ ++ struct _inittab mods[3] = ++ { ++ { "_gdb", init__gdb_module }, ++ { "_gdbevents", gdbpy_events_mod_func }, ++ { nullptr, nullptr } ++ }; ++ ++ if (PyImport_ExtendInittab (mods) < 0) ++ return false; ++ + Py_Initialize (); + #if PY_VERSION_HEX < 0x03090000 + /* PyEval_InitThreads became deprecated in Python 3.9 and will +@@ -1962,7 +1971,6 @@ do_start_initialization () + || gdbpy_initialize_thread () < 0 + || gdbpy_initialize_inferior () < 0 + || gdbpy_initialize_eventregistry () < 0 +- || gdbpy_initialize_py_events () < 0 + || gdbpy_initialize_event () < 0 + || gdbpy_initialize_arch () < 0 + || gdbpy_initialize_registers () < 0 +diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp +index 2fdd216..4feeb02 100644 +--- a/gdb/testsuite/gdb.python/py-events.exp ++++ b/gdb/testsuite/gdb.python/py-events.exp +@@ -42,6 +42,8 @@ clean_restart ${testfile} + + if { [skip_python_tests] } { continue } + ++gdb_test_no_output "python import gdb.events" ++ + set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-events.py] + gdb_test_no_output "source ${pyfile}" "load python file" + +-- +2.33.0 + diff --git a/gdb-Use-bool-for-evregpy_no_listeners_p.patch b/gdb-Use-bool-for-evregpy_no_listeners_p.patch new file mode 100644 index 0000000..743f959 --- /dev/null +++ b/gdb-Use-bool-for-evregpy_no_listeners_p.patch @@ -0,0 +1,40 @@ +From 907de931f547bd0d6178ee04bdb6496cd66dbdd7 Mon Sep 17 00:00:00 2001 +From: Tom Tromey +Date: Fri, 3 Jun 2022 10:35:30 -0600 +Subject: [PATCH] Use bool for evregpy_no_listeners_p + +I noticed that evregpy_no_listeners_p should return a bool. This +patch makes this change. I'm checking it in. +--- + gdb/python/py-events.h | 2 +- + gdb/python/py-evtregistry.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h +index bd4a75c..1680b58 100644 +--- a/gdb/python/py-events.h ++++ b/gdb/python/py-events.h +@@ -52,6 +52,6 @@ struct events_object + extern events_object gdb_py_events; + + extern eventregistry_object *create_eventregistry_object (void); +-extern int evregpy_no_listeners_p (eventregistry_object *registry); ++extern bool evregpy_no_listeners_p (eventregistry_object *registry); + + #endif /* PYTHON_PY_EVENTS_H */ +diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c +index 003fe44..ef96c48 100644 +--- a/gdb/python/py-evtregistry.c ++++ b/gdb/python/py-evtregistry.c +@@ -115,7 +115,7 @@ gdbpy_initialize_eventregistry (void) + /* Return the number of listeners currently connected to this + registry. */ + +-int ++bool + evregpy_no_listeners_p (eventregistry_object *registry) + { + return PyList_Size (registry->callbacks) == 0; +-- +2.33.0 + diff --git a/gdb-python-remove-Python-2-support.patch b/gdb-python-remove-Python-2-support.patch new file mode 100644 index 0000000..6aa3698 --- /dev/null +++ b/gdb-python-remove-Python-2-support.patch @@ -0,0 +1,1375 @@ +From 18a8874936fb0701086108c4dddf26c3072b6bb0 Mon Sep 17 00:00:00 2001 +From: Simon Marchi +Date: Thu, 23 Dec 2021 20:20:46 -0500 +Subject: [PATCH] gdb/python: remove Python 2 support + +New in this version: + + - Add a PY_MAJOR_VERSION check in configure.ac / AC_TRY_LIBPYTHON. If + the user passes --with-python=python2, this will cause a configure + failure saying that GDB only supports Python 3. + +Support for Python 2 is a maintenance burden for any patches touching +Python support. Among others, the differences between Python 2 and 3 +string and integer types are subtle. It requires a lot of effort and +thinking to get something that behaves correctly on both. And that's if +the author and reviewer of the patch even remember to test with Python +2. + +See this thread for an example: + + https://sourceware.org/pipermail/gdb-patches/2021-December/184260.html + +So, remove Python 2 support. Update the documentation to state that GDB +can be built against Python 3 (as opposed to Python 2 or 3). + +Update all the spots that use: + + - sys.version_info + - IS_PY3K + - PY_MAJOR_VERSION + - gdb_py_is_py3k + +... to only keep the Python 3 portions and drop the use of some +now-removed compatibility macros. + +I did not update the configure script more than just removing the +explicit references to Python 2. We could maybe do more there, like +check the Python version and reject it if that version is not +supported. Otherwise (with this patch), things will only fail at +compile time, so it won't really be clear to the user that they are +trying to use an unsupported Python version. But I'm a bit lost in the +configure code that checks for Python, so I kept that for later. + +Change-Id: I75b0f79c148afbe3c07ac664cfa9cade052c0c62 +--- + gdb/NEWS | 3 + + gdb/README | 2 +- + gdb/configure | 78 +------------------ + gdb/configure.ac | 18 ++--- + gdb/doc/python.texi | 2 - + gdb/python/lib/gdb/__init__.py | 2 +- + gdb/python/lib/gdb/command/explore.py | 22 +++--- + gdb/python/lib/gdb/printer/bound_registers.py | 7 +- + gdb/python/lib/gdb/printing.py | 9 +-- + gdb/python/lib/gdb/xmethod.py | 8 +- + gdb/python/py-arch.c | 6 -- + gdb/python/py-evts.c | 6 -- + gdb/python/py-framefilter.c | 6 +- + gdb/python/py-membuf.c | 73 +---------------- + gdb/python/py-param.c | 8 -- + gdb/python/py-record-btrace.c | 17 +--- + gdb/python/py-type.c | 13 ---- + gdb/python/py-utils.c | 47 +---------- + gdb/python/py-value.c | 66 ---------------- + gdb/python/python-internal.h | 10 --- + gdb/python/python.c | 19 ----- + gdb/testsuite/gdb.python/py-inferior.exp | 6 +- + .../py-mi-var-info-path-expression.py | 12 +-- + gdb/testsuite/gdb.python/py-record-btrace.exp | 6 +- + gdb/testsuite/gdb.python/py-send-packet.py | 58 ++++---------- + gdb/testsuite/gdb.python/py-shared.exp | 7 +- + gdb/testsuite/gdb.python/py-value.exp | 40 +--------- + gdb/testsuite/lib/gdb.exp | 12 --- + 28 files changed, 61 insertions(+), 502 deletions(-) + +diff --git a/gdb/NEWS b/gdb/NEWS +index 501ace1..c80bf39 100644 +--- a/gdb/NEWS ++++ b/gdb/NEWS +@@ -180,6 +180,9 @@ GNU/Linux/LoongArch loongarch*-*-linux* + + S+core score-*-* + ++* Remove support for building against Python 2, it is now only possible to ++ build GDB against Python 3. ++ + * Python API + + ** New function gdb.add_history(), which takes a gdb.Value object +diff --git a/gdb/README b/gdb/README +index e65c5ea..bd5a88f 100644 +--- a/gdb/README ++++ b/gdb/README +@@ -506,7 +506,7 @@ more obscure GDB `configure' options are not listed here. + GDB scripting much more powerful than the restricted CLI + scripting language. If your host does not have Python installed, + you can find it on `http://www.python.org/download/'. The oldest +- version of Python supported by GDB is 2.6. The optional argument ++ version of Python supported by GDB is 3.2. The optional argument + PYTHON is used to find the Python headers and libraries. It can + be either the name of a Python executable, or the name of the + directory in which Python is installed. +diff --git a/gdb/configure b/gdb/configure +index ac372e3..1e955a5 100755 +--- a/gdb/configure ++++ b/gdb/configure +@@ -11764,81 +11764,12 @@ $as_echo_n "checking for python... " >&6; } + int + main () + { +-Py_Initialize (); +- ; +- return 0; +-} +-_ACEOF +-if ac_fn_c_try_link "$LINENO"; then : +- have_libpython=yes +- found_usable_python=yes +- PYTHON_CPPFLAGS=$new_CPPFLAGS +- PYTHON_LIBS=$new_LIBS +-fi +-rm -f core conftest.err conftest.$ac_objext \ +- conftest$ac_exeext conftest.$ac_ext +- CPPFLAGS=$save_CPPFLAGS +- LIBS=$save_LIBS +- { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 +-$as_echo "${found_usable_python}" >&6; } +- +- elif test "${have_python_config}" != failed; then +- if test "${have_libpython}" = no; then +- +- +- new_CPPFLAGS=${python_includes} +- new_LIBS="-lpython2.7 ${python_libs}" +- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python" >&5 +-$as_echo_n "checking for python... " >&6; } +- save_CPPFLAGS=$CPPFLAGS +- save_LIBS=$LIBS +- CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" +- LIBS="$new_LIBS $LIBS" +- found_usable_python=no +- cat confdefs.h - <<_ACEOF >conftest.$ac_ext +-/* end confdefs.h. */ +-#include "Python.h" +-int +-main () +-{ +-Py_Initialize (); +- ; +- return 0; +-} +-_ACEOF +-if ac_fn_c_try_link "$LINENO"; then : +- have_libpython=yes +- found_usable_python=yes +- PYTHON_CPPFLAGS=$new_CPPFLAGS +- PYTHON_LIBS=$new_LIBS +-fi +-rm -f core conftest.err conftest.$ac_objext \ +- conftest$ac_exeext conftest.$ac_ext +- CPPFLAGS=$save_CPPFLAGS +- LIBS=$save_LIBS +- { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 +-$as_echo "${found_usable_python}" >&6; } + +- fi +- if test "${have_libpython}" = no; then ++ #if PY_MAJOR_VERSION != 3 ++ # error "We only support Python 3" ++ #endif ++ Py_Initialize (); + +- +- new_CPPFLAGS=${python_includes} +- new_LIBS="-lpython2.6 ${python_libs}" +- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python" >&5 +-$as_echo_n "checking for python... " >&6; } +- save_CPPFLAGS=$CPPFLAGS +- save_LIBS=$LIBS +- CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" +- LIBS="$new_LIBS $LIBS" +- found_usable_python=no +- cat confdefs.h - <<_ACEOF >conftest.$ac_ext +-/* end confdefs.h. */ +-#include "Python.h" +-int +-main () +-{ +-Py_Initialize (); + ; + return 0; + } +@@ -11856,7 +11787,6 @@ rm -f core conftest.err conftest.$ac_objext \ + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 + $as_echo "${found_usable_python}" >&6; } + +- fi + fi + + if test "${have_libpython}" = no; then +diff --git a/gdb/configure.ac b/gdb/configure.ac +index f7d6c61..771a54b 100644 +--- a/gdb/configure.ac ++++ b/gdb/configure.ac +@@ -912,7 +912,12 @@ AC_DEFUN([AC_TRY_LIBPYTHON], + LIBS="$new_LIBS $LIBS" + found_usable_python=no + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "Python.h"]], +- [[Py_Initialize ();]])], ++ [[ ++ #if PY_MAJOR_VERSION != 3 ++ # error "We only support Python 3" ++ #endif ++ Py_Initialize (); ++ ]])], + [have_libpython_var=yes + found_usable_python=yes + PYTHON_CPPFLAGS=$new_CPPFLAGS +@@ -928,7 +933,6 @@ dnl no - Don't include python support. + dnl yes - Include python support, error if it's missing. + dnl If we find python in $PATH, use it to fetch configure options, + dnl otherwise assume the compiler can find it with no help from us. +-dnl Python 2.7 and 2.6 are tried in turn. + dnl auto - Same as "yes", but if python is missing from the system, + dnl fall back to "no". + dnl /path/to/python/exec-prefix - +@@ -937,7 +941,6 @@ dnl If /path/to/python/exec-prefix/bin/python exists, use it to find + dnl the compilation parameters. Otherwise use + dnl -I/path/to/python/exec-prefix/include, + dnl -L/path/to/python/exec-prefix/lib. +-dnl Python 2.7 and 2.6 are tried in turn. + dnl NOTE: This case is historical. It is what was done for 7.0/7.1 + dnl but is deprecated. + dnl /path/to/python/executable - +@@ -1072,15 +1075,6 @@ else + if test "${have_python_config}" = yes; then + AC_TRY_LIBPYTHON(have_libpython, + ${python_includes}, ${python_libs}) +- elif test "${have_python_config}" != failed; then +- if test "${have_libpython}" = no; then +- AC_TRY_LIBPYTHON(have_libpython, +- ${python_includes}, "-lpython2.7 ${python_libs}") +- fi +- if test "${have_libpython}" = no; then +- AC_TRY_LIBPYTHON(have_libpython, +- ${python_includes}, "-lpython2.6 ${python_libs}") +- fi + fi + + if test "${have_libpython}" = no; then +diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi +index 918418b..220f90e 100644 +--- a/gdb/doc/python.texi ++++ b/gdb/doc/python.texi +@@ -18,8 +18,6 @@ + You can extend @value{GDBN} using the @uref{http://www.python.org/, + Python programming language}. This feature is available only if + @value{GDBN} was configured using @option{--with-python}. +-@value{GDBN} can be built against either Python 2 or Python 3; which +-one you have depends on this configure-time option. + + @cindex python directory + Python scripts used by @value{GDBN} should be installed in +diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py +index 5f63bce..a52f6b4 100644 +--- a/gdb/python/lib/gdb/__init__.py ++++ b/gdb/python/lib/gdb/__init__.py +@@ -22,7 +22,7 @@ from contextlib import contextmanager + # Python 3 moved "reload" + if sys.version_info >= (3, 4): + from importlib import reload +-elif sys.version_info[0] > 2: ++else: + from imp import reload + + from _gdb import * +diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py +index ea49c38..c03bef3 100644 +--- a/gdb/python/lib/gdb/command/explore.py ++++ b/gdb/python/lib/gdb/command/explore.py +@@ -19,10 +19,6 @@ + import gdb + import sys + +-if sys.version_info[0] > 2: +- # Python 3 renamed raw_input to input +- raw_input = input +- + + class Explorer(object): + """Internal class which invokes other explorers.""" +@@ -172,7 +168,7 @@ class Explorer(object): + so that the exploration session can shift back to the parent value. + Useful when exploring values. + """ +- raw_input("\nPress enter to return to parent value: ") ++ input("\nPress enter to return to parent value: ") + + @staticmethod + def return_to_enclosing_type(): +@@ -187,7 +183,7 @@ class Explorer(object): + so that the exploration session can shift back to the enclosing type. + Useful when exploring types. + """ +- raw_input("\nPress enter to return to enclosing type: ") ++ input("\nPress enter to return to enclosing type: ") + + + class ScalarExplorer(object): +@@ -244,7 +240,7 @@ class PointerExplorer(object): + "'%s' is a pointer to a value of type '%s'" + % (expr, str(value.type.target())) + ) +- option = raw_input( ++ option = input( + "Continue exploring it as a pointer to a single " "value [y/n]: " + ) + if option == "y": +@@ -264,13 +260,13 @@ class PointerExplorer(object): + ) + return False + +- option = raw_input("Continue exploring it as a pointer to an " "array [y/n]: ") ++ option = input("Continue exploring it as a pointer to an " "array [y/n]: ") + if option == "y": + while True: + index = 0 + try: + index = int( +- raw_input( ++ input( + "Enter the index of the element you " + "want to explore in '%s': " % expr + ) +@@ -338,7 +334,7 @@ class ArrayExplorer(object): + index = 0 + try: + index = int( +- raw_input( ++ input( + "Enter the index of the element you want to " + "explore in '%s': " % expr + ) +@@ -354,7 +350,7 @@ class ArrayExplorer(object): + str(element) + except gdb.MemoryError: + print("Cannot read value at index %d." % index) +- raw_input("Press enter to continue... ") ++ input("Press enter to continue... ") + return True + + Explorer.explore_expr( +@@ -474,7 +470,7 @@ class CompoundExplorer(object): + print("") + + if has_explorable_fields: +- choice = raw_input("Enter the field number of choice: ") ++ choice = input("Enter the field number of choice: ") + if choice in choice_to_compound_field_map: + Explorer.explore_expr( + choice_to_compound_field_map[choice][0], +@@ -550,7 +546,7 @@ class CompoundExplorer(object): + print("") + + if len(choice_to_compound_field_map) > 0: +- choice = raw_input("Enter the field number of choice: ") ++ choice = input("Enter the field number of choice: ") + if choice in choice_to_compound_field_map: + if is_child: + new_name = "%s '%s' of %s" % ( +diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py +index f8ce9ea..7cb6e8f 100644 +--- a/gdb/python/lib/gdb/printer/bound_registers.py ++++ b/gdb/python/lib/gdb/printer/bound_registers.py +@@ -18,11 +18,6 @@ import sys + + import gdb.printing + +-if sys.version_info[0] > 2: +- # Python 3 removed basestring and long +- basestring = str +- long = int +- + + class MpxBound128Printer: + """Adds size field to a mpx __gdb_builtin_type_bound128 type.""" +@@ -33,7 +28,7 @@ class MpxBound128Printer: + def to_string(self): + upper = self.val["ubound"] + lower = self.val["lbound"] +- size = (long)((upper) - (lower)) ++ size = upper - lower + if size > -1: + size = size + 1 + result = "{lbound = %s, ubound = %s} : size %s" % (lower, upper, size) +diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py +index 93d61f1..e208e88 100644 +--- a/gdb/python/lib/gdb/printing.py ++++ b/gdb/python/lib/gdb/printing.py +@@ -21,11 +21,6 @@ import gdb.types + import re + import sys + +-if sys.version_info[0] > 2: +- # Python 3 removed basestring and long +- basestring = str +- long = int +- + + class PrettyPrinter(object): + """A basic pretty-printer. +@@ -132,7 +127,7 @@ def register_pretty_printer(obj, printer, replace=False): + # Printers implemented as functions are old-style. In order to not risk + # breaking anything we do not check __name__ here. + if hasattr(printer, "name"): +- if not isinstance(printer.name, basestring): ++ if not isinstance(printer.name, str): + raise TypeError("printer name is not a string") + # If printer provides a name, make sure it doesn't contain ";". + # Semicolon is used by the info/enable/disable pretty-printer commands +@@ -232,7 +227,7 @@ class _EnumInstance: + + def to_string(self): + flag_list = [] +- v = long(self.val) ++ v = int(self.val) + any_found = False + for (e_name, e_value) in self.enumerators: + if v & e_value != 0: +diff --git a/gdb/python/lib/gdb/xmethod.py b/gdb/python/lib/gdb/xmethod.py +index 4c3a522..c69ea99 100644 +--- a/gdb/python/lib/gdb/xmethod.py ++++ b/gdb/python/lib/gdb/xmethod.py +@@ -21,12 +21,6 @@ import re + import sys + + +-if sys.version_info[0] > 2: +- # Python 3 removed basestring and long +- basestring = str +- long = int +- +- + class XMethod(object): + """Base class (or a template) for an xmethod description. + +@@ -223,7 +217,7 @@ def _validate_xmethod_matcher(matcher): + return TypeError("Xmethod matcher is missing attribute: name") + if not hasattr(matcher, "enabled"): + return TypeError("Xmethod matcher is missing attribute: enabled") +- if not isinstance(matcher.name, basestring): ++ if not isinstance(matcher.name, str): + return TypeError("Attribute 'name' of xmethod matcher is not a " "string") + if matcher.name.find(";") >= 0: + return ValueError("Xmethod matcher name cannot contain ';' in it") +diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c +index 0f273b3..e87881a 100644 +--- a/gdb/python/py-arch.c ++++ b/gdb/python/py-arch.c +@@ -139,12 +139,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) + conversion process. */ + if (PyLong_Check (end_obj)) + end = PyLong_AsUnsignedLongLong (end_obj); +-#if PY_MAJOR_VERSION == 2 +- else if (PyInt_Check (end_obj)) +- /* If the end_pc value is specified without a trailing 'L', end_obj will +- be an integer and not a long integer. */ +- end = PyInt_AsLong (end_obj); +-#endif + else + { + PyErr_SetString (PyExc_TypeError, +diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c +index 457825c..23a5d75 100644 +--- a/gdb/python/py-evts.c ++++ b/gdb/python/py-evts.c +@@ -20,7 +20,6 @@ + #include "defs.h" + #include "py-events.h" + +-#ifdef IS_PY3K + static struct PyModuleDef EventModuleDef = + { + PyModuleDef_HEAD_INIT, +@@ -33,7 +32,6 @@ static struct PyModuleDef EventModuleDef = + NULL, + NULL + }; +-#endif + + /* Initialize python events. */ + +@@ -53,11 +51,7 @@ add_new_registry (eventregistry_object **registryp, const char *name) + int + gdbpy_initialize_py_events (void) + { +-#ifdef IS_PY3K + gdb_py_events.module = PyModule_Create (&EventModuleDef); +-#else +- gdb_py_events.module = Py_InitModule ("events", NULL); +-#endif + + if (!gdb_py_events.module) + return -1; +diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c +index e6eb1ec..0170fe6 100644 +--- a/gdb/python/py-framefilter.c ++++ b/gdb/python/py-framefilter.c +@@ -920,11 +920,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags, + + function = function_to_free.get (); + } +- else if (PyLong_Check (py_func.get ()) +-#if PY_MAJOR_VERSION == 2 +- || PyInt_Check (py_func.get ()) +-#endif +- ) ++ else if (PyLong_Check (py_func.get ())) + { + CORE_ADDR addr; + struct bound_minimal_symbol msymbol; +diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c +index 74cc0fb..348dfa3 100644 +--- a/gdb/python/py-membuf.c ++++ b/gdb/python/py-membuf.c +@@ -54,15 +54,7 @@ gdbpy_buffer_to_membuf (gdb::unique_xmalloc_ptr buffer, + membuf_obj->addr = address; + membuf_obj->length = length; + +- PyObject *result; +-#ifdef IS_PY3K +- result = PyMemoryView_FromObject ((PyObject *) membuf_obj.get ()); +-#else +- result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj.get (), 0, +- Py_END_OF_BUFFER); +-#endif +- +- return result; ++ return PyMemoryView_FromObject ((PyObject *) membuf_obj.get ()); + } + + /* Destructor for gdb.Membuf objects. */ +@@ -88,8 +80,6 @@ which is %s bytes long."), + pulongest (membuf_obj->length)); + } + +-#ifdef IS_PY3K +- + static int + get_buffer (PyObject *self, Py_buffer *buf, int flags) + { +@@ -107,54 +97,6 @@ get_buffer (PyObject *self, Py_buffer *buf, int flags) + return ret; + } + +-#else +- +-static Py_ssize_t +-get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr) +-{ +- membuf_object *membuf_obj = (membuf_object *) self; +- +- if (segment) +- { +- PyErr_SetString (PyExc_SystemError, +- _("The memory buffer supports only one segment.")); +- return -1; +- } +- +- *ptrptr = membuf_obj->buffer; +- +- return membuf_obj->length; +-} +- +-static Py_ssize_t +-get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr) +-{ +- return get_read_buffer (self, segment, ptrptr); +-} +- +-static Py_ssize_t +-get_seg_count (PyObject *self, Py_ssize_t *lenp) +-{ +- if (lenp) +- *lenp = ((membuf_object *) self)->length; +- +- return 1; +-} +- +-static Py_ssize_t +-get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr) +-{ +- void *ptr = nullptr; +- Py_ssize_t ret; +- +- ret = get_read_buffer (self, segment, &ptr); +- *ptrptr = (char *) ptr; +- +- return ret; +-} +- +-#endif /* IS_PY3K */ +- + /* General Python initialization callback. */ + + int +@@ -168,24 +110,11 @@ gdbpy_initialize_membuf (void) + (PyObject *) &membuf_object_type); + } + +-#ifdef IS_PY3K +- + static PyBufferProcs buffer_procs = + { + get_buffer + }; + +-#else +- +-static PyBufferProcs buffer_procs = { +- get_read_buffer, +- get_write_buffer, +- get_seg_count, +- get_char_buffer +-}; +- +-#endif /* IS_PY3K */ +- + PyTypeObject membuf_object_type = { + PyVarObject_HEAD_INIT (nullptr, 0) + "gdb.Membuf", /*tp_name*/ +diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c +index 00f917e..6be771c 100644 +--- a/gdb/python/py-param.c ++++ b/gdb/python/py-param.c +@@ -126,11 +126,7 @@ static PyObject * + get_attr (PyObject *obj, PyObject *attr_name) + { + if (PyString_Check (attr_name) +-#ifdef IS_PY3K + && ! PyUnicode_CompareWithASCIIString (attr_name, "value")) +-#else +- && ! strcmp (PyString_AsString (attr_name), "value")) +-#endif + { + parmpy_object *self = (parmpy_object *) obj; + +@@ -313,11 +309,7 @@ static int + set_attr (PyObject *obj, PyObject *attr_name, PyObject *val) + { + if (PyString_Check (attr_name) +-#ifdef IS_PY3K + && ! PyUnicode_CompareWithASCIIString (attr_name, "value")) +-#else +- && ! strcmp (PyString_AsString (attr_name), "value")) +-#endif + { + if (!val) + { +diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c +index 2a0e89d..bee17e0 100644 +--- a/gdb/python/py-record-btrace.c ++++ b/gdb/python/py-record-btrace.c +@@ -28,16 +28,6 @@ + #include "disasm.h" + #include "gdbarch.h" + +-#if defined (IS_PY3K) +- +-#define BTPY_PYSLICE(x) (x) +- +-#else +- +-#define BTPY_PYSLICE(x) ((PySliceObject *) x) +- +-#endif +- + /* Python object for btrace record lists. */ + + struct btpy_list_object { +@@ -295,12 +285,7 @@ recpy_bt_insn_data (PyObject *self, void *closure) + if (object == NULL) + return NULL; + +-#ifdef IS_PY3K + return PyMemoryView_FromObject (object); +-#else +- return PyBuffer_FromObject (object, 0, Py_END_OF_BUFFER); +-#endif +- + } + + /* Implementation of RecordInstruction.decoded [str] for btrace. +@@ -500,7 +485,7 @@ btpy_list_slice (PyObject *self, PyObject *value) + if (!PySlice_Check (value)) + return PyErr_Format (PyExc_TypeError, _("Index must be int or slice.")); + +- if (0 != PySlice_GetIndicesEx (BTPY_PYSLICE (value), length, &start, &stop, ++ if (0 != PySlice_GetIndicesEx (value, length, &start, &stop, + &step, &slicelength)) + return NULL; + +diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c +index 7be3f32..8838884 100644 +--- a/gdb/python/py-type.c ++++ b/gdb/python/py-type.c +@@ -1610,9 +1610,6 @@ static PyNumberMethods type_object_as_number = { + NULL, /* nb_add */ + NULL, /* nb_subtract */ + NULL, /* nb_multiply */ +-#ifndef IS_PY3K +- NULL, /* nb_divide */ +-#endif + NULL, /* nb_remainder */ + NULL, /* nb_divmod */ + NULL, /* nb_power */ +@@ -1626,19 +1623,9 @@ static PyNumberMethods type_object_as_number = { + NULL, /* nb_and */ + NULL, /* nb_xor */ + NULL, /* nb_or */ +-#ifdef IS_PY3K + NULL, /* nb_int */ + NULL, /* reserved */ +-#else +- NULL, /* nb_coerce */ +- NULL, /* nb_int */ +- NULL, /* nb_long */ +-#endif + NULL, /* nb_float */ +-#ifndef IS_PY3K +- NULL, /* nb_oct */ +- NULL /* nb_hex */ +-#endif + }; + + static PyMappingMethods typy_mapping = { +diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c +index 838853c..e7b147c 100644 +--- a/gdb/python/py-utils.c ++++ b/gdb/python/py-utils.c +@@ -45,14 +45,10 @@ python_string_to_unicode (PyObject *obj) + unicode_str = obj; + Py_INCREF (obj); + } +-#ifndef IS_PY3K +- else if (PyString_Check (obj)) +- unicode_str = PyUnicode_FromEncodedObject (obj, host_charset (), NULL); +-#endif + else + { + PyErr_SetString (PyExc_TypeError, +- _("Expected a string or unicode object.")); ++ _("Expected a string object.")); + unicode_str = NULL; + } + +@@ -166,11 +162,7 @@ host_string_to_python_string (const char *str) + int + gdbpy_is_string (PyObject *obj) + { +-#ifdef IS_PY3K + return PyUnicode_Check (obj); +-#else +- return PyString_Check (obj) || PyUnicode_Check (obj); +-#endif + } + + /* Return the string representation of OBJ, i.e., str (obj). +@@ -182,17 +174,7 @@ gdbpy_obj_to_string (PyObject *obj) + gdbpy_ref<> str_obj (PyObject_Str (obj)); + + if (str_obj != NULL) +- { +- gdb::unique_xmalloc_ptr msg; +- +-#ifdef IS_PY3K +- msg = python_string_to_host_string (str_obj.get ()); +-#else +- msg.reset (xstrdup (PyString_AsString (str_obj.get ()))); +-#endif +- +- return msg; +- } ++ return python_string_to_host_string (str_obj.get ()); + + return NULL; + } +@@ -296,20 +278,9 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr) + gdbpy_ref<> + gdb_py_object_from_longest (LONGEST l) + { +-#ifdef IS_PY3K + if (sizeof (l) > sizeof (long)) + return gdbpy_ref<> (PyLong_FromLongLong (l)); + return gdbpy_ref<> (PyLong_FromLong (l)); +-#else +-#ifdef HAVE_LONG_LONG /* Defined by Python. */ +- /* If we have 'long long', and the value overflows a 'long', use a +- Python Long; otherwise use a Python Int. */ +- if (sizeof (l) > sizeof (long) +- && (l > PyInt_GetMax () || l < (- (LONGEST) PyInt_GetMax ()) - 1)) +- return gdbpy_ref<> (PyLong_FromLongLong (l)); +-#endif +- return gdbpy_ref<> (PyInt_FromLong (l)); +-#endif + } + + /* Convert a ULONGEST to the appropriate Python object -- either an +@@ -318,23 +289,9 @@ gdb_py_object_from_longest (LONGEST l) + gdbpy_ref<> + gdb_py_object_from_ulongest (ULONGEST l) + { +-#ifdef IS_PY3K + if (sizeof (l) > sizeof (unsigned long)) + return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l)); + return gdbpy_ref<> (PyLong_FromUnsignedLong (l)); +-#else +-#ifdef HAVE_LONG_LONG /* Defined by Python. */ +- /* If we have 'long long', and the value overflows a 'long', use a +- Python Long; otherwise use a Python Int. */ +- if (sizeof (l) > sizeof (unsigned long) && l > PyInt_GetMax ()) +- return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l)); +-#endif +- +- if (l > PyInt_GetMax ()) +- return gdbpy_ref<> (PyLong_FromUnsignedLong (l)); +- +- return gdbpy_ref<> (PyInt_FromLong (l)); +-#endif + } + + /* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts +diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c +index b546344..e779f49 100644 +--- a/gdb/python/py-value.c ++++ b/gdb/python/py-value.c +@@ -1695,41 +1695,6 @@ valpy_richcompare (PyObject *self, PyObject *other, int op) + Py_RETURN_FALSE; + } + +-#ifndef IS_PY3K +-/* Implements conversion to int. */ +-static PyObject * +-valpy_int (PyObject *self) +-{ +- struct value *value = ((value_object *) self)->value; +- struct type *type = value_type (value); +- LONGEST l = 0; +- +- try +- { +- if (is_floating_value (value)) +- { +- type = builtin_type_pylong; +- value = value_cast (type, value); +- } +- +- if (!is_integral_type (type) +- && type->code () != TYPE_CODE_PTR) +- error (_("Cannot convert value to int.")); +- +- l = value_as_long (value); +- } +- catch (const gdb_exception &except) +- { +- GDB_PY_HANDLE_EXCEPTION (except); +- } +- +- if (type->is_unsigned ()) +- return gdb_py_object_from_ulongest (l).release (); +- else +- return gdb_py_object_from_longest (l).release (); +-} +-#endif +- + /* Implements conversion to long. */ + static PyObject * + valpy_long (PyObject *self) +@@ -1914,15 +1879,6 @@ convert_value_from_python (PyObject *obj) + else + value = value_from_longest (builtin_type_pylong, l); + } +-#if PY_MAJOR_VERSION == 2 +- else if (PyInt_Check (obj)) +- { +- long l = PyInt_AsLong (obj); +- +- if (! PyErr_Occurred ()) +- value = value_from_longest (builtin_type_pyint, l); +- } +-#endif + else if (PyFloat_Check (obj)) + { + double d = PyFloat_AsDouble (obj); +@@ -1948,14 +1904,8 @@ convert_value_from_python (PyObject *obj) + value = value_copy (((value_object *) result)->value); + } + else +-#ifdef IS_PY3K + PyErr_Format (PyExc_TypeError, + _("Could not convert Python object: %S."), obj); +-#else +- PyErr_Format (PyExc_TypeError, +- _("Could not convert Python object: %s."), +- PyString_AsString (PyObject_Str (obj))); +-#endif + } + catch (const gdb_exception &except) + { +@@ -2176,9 +2126,6 @@ static PyNumberMethods value_object_as_number = { + valpy_add, + valpy_subtract, + valpy_multiply, +-#ifndef IS_PY3K +- valpy_divide, +-#endif + valpy_remainder, + NULL, /* nb_divmod */ + valpy_power, /* nb_power */ +@@ -2192,25 +2139,12 @@ static PyNumberMethods value_object_as_number = { + valpy_and, /* nb_and */ + valpy_xor, /* nb_xor */ + valpy_or, /* nb_or */ +-#ifdef IS_PY3K + valpy_long, /* nb_int */ + NULL, /* reserved */ +-#else +- NULL, /* nb_coerce */ +- valpy_int, /* nb_int */ +- valpy_long, /* nb_long */ +-#endif + valpy_float, /* nb_float */ +-#ifndef IS_PY3K +- NULL, /* nb_oct */ +- NULL, /* nb_hex */ +-#endif + NULL, /* nb_inplace_add */ + NULL, /* nb_inplace_subtract */ + NULL, /* nb_inplace_multiply */ +-#ifndef IS_PY3K +- NULL, /* nb_inplace_divide */ +-#endif + NULL, /* nb_inplace_remainder */ + NULL, /* nb_inplace_power */ + NULL, /* nb_inplace_lshift */ +diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h +index 098d913..e3a3fc4 100644 +--- a/gdb/python/python-internal.h ++++ b/gdb/python/python-internal.h +@@ -87,11 +87,6 @@ + #include + #include "py-ref.h" + +-#if PY_MAJOR_VERSION >= 3 +-#define IS_PY3K 1 +-#endif +- +-#ifdef IS_PY3K + #define Py_TPFLAGS_CHECKTYPES 0 + + #define PyInt_Check PyLong_Check +@@ -102,7 +97,6 @@ + #define PyString_Decode PyUnicode_Decode + #define PyString_FromFormat PyUnicode_FromFormat + #define PyString_Check PyUnicode_Check +-#endif + + /* If Python.h does not define WITH_THREAD, then the various + GIL-related functions will not be defined. However, +@@ -209,11 +203,7 @@ gdb_PySys_GetObject (const char *name) + before Python 3.6. Hence, we wrap it in a function to avoid errors + when compiled with -Werror. */ + +-#ifdef IS_PY3K + # define GDB_PYSYS_SETPATH_CHAR wchar_t +-#else +-# define GDB_PYSYS_SETPATH_CHAR char +-#endif + + static inline void + gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path) +diff --git a/gdb/python/python.c b/gdb/python/python.c +index 91636ef..e97bca7 100644 +--- a/gdb/python/python.c ++++ b/gdb/python/python.c +@@ -317,11 +317,6 @@ eval_python_command (const char *command) + if (v == NULL) + return -1; + +-#ifndef IS_PY3K +- if (Py_FlushLine ()) +- PyErr_Clear (); +-#endif +- + return 0; + } + +@@ -1803,7 +1798,6 @@ finalize_python (void *ignore) + restore_active_ext_lang (previous_active); + } + +-#ifdef IS_PY3K + static struct PyModuleDef python_GdbModuleDef = + { + PyModuleDef_HEAD_INIT, +@@ -1826,7 +1820,6 @@ init__gdb_module (void) + { + return PyModule_Create (&python_GdbModuleDef); + } +-#endif + + /* Emit a gdb.GdbExitingEvent, return a negative value if there are any + errors, otherwise, return 0. */ +@@ -1873,7 +1866,6 @@ do_start_initialization () + gdb::unique_xmalloc_ptr progname + (concat (ldirname (python_libdir.c_str ()).c_str (), SLASH_STRING, "bin", + SLASH_STRING, "python", (char *) NULL)); +-#ifdef IS_PY3K + /* Python documentation indicates that the memory given + to Py_SetProgramName cannot be freed. However, it seems that + at least Python 3.7.4 Py_SetProgramName takes a copy of the +@@ -1902,9 +1894,6 @@ do_start_initialization () + + /* Define _gdb as a built-in module. */ + PyImport_AppendInittab ("_gdb", init__gdb_module); +-#else +- Py_SetProgramName (progname.release ()); +-#endif + #endif + + Py_Initialize (); +@@ -1915,11 +1904,7 @@ do_start_initialization () + PyEval_InitThreads (); + #endif + +-#ifdef IS_PY3K + gdb_module = PyImport_ImportModule ("_gdb"); +-#else +- gdb_module = Py_InitModule ("_gdb", python_GdbMethods); +-#endif + if (gdb_module == NULL) + return false; + +@@ -2220,11 +2205,7 @@ do_initialize (const struct extension_language_defn *extlang) + /* If sys.path is not defined yet, define it first. */ + if (!(sys_path && PyList_Check (sys_path))) + { +-#ifdef IS_PY3K + PySys_SetPath (L""); +-#else +- PySys_SetPath (""); +-#endif + sys_path = PySys_GetObject ("path"); + } + if (sys_path && PyList_Check (sys_path)) +diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp +index aa78a15..552f9b1 100644 +--- a/gdb/testsuite/gdb.python/py-inferior.exp ++++ b/gdb/testsuite/gdb.python/py-inferior.exp +@@ -77,11 +77,7 @@ gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ + "read str address" 0 + gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \ + "read str contents" 1 +-if { $gdb_py_is_py3k == 0 } { +- gdb_py_test_silent_cmd "python a = 'a'" "" 0 +-} else { +- gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0 +-} ++gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0 + gdb_py_test_silent_cmd "python str\[1\] = a" "change str" 0 + gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \ + "write str" 1 +diff --git a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py +index dfc2ebd..035478f 100644 +--- a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py ++++ b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py +@@ -17,27 +17,23 @@ import sys + import gdb + import gdb.types + +-# Following is for Python 3 compatibility... +-if sys.version_info[0] > 2: +- long = int +- + + class cons_pp(object): + def __init__(self, val): + self._val = val + + def to_string(self): +- if long(self._val) == 0: ++ if int(self._val) == 0: + return "nil" +- elif long(self._val["type"]) == 0: ++ elif int(self._val["type"]) == 0: + return "( . )" + else: + return "%d" % self._val["atom"]["ival"] + + def children(self): +- if long(self._val) == 0: ++ if int(self._val) == 0: + return [] +- elif long(self._val["type"]) == 0: ++ elif int(self._val["type"]) == 0: + return [("atom", self._val["atom"])] + else: + return [ +diff --git a/gdb/testsuite/gdb.python/py-record-btrace.exp b/gdb/testsuite/gdb.python/py-record-btrace.exp +index 8204577..e9fdd06 100644 +--- a/gdb/testsuite/gdb.python/py-record-btrace.exp ++++ b/gdb/testsuite/gdb.python/py-record-btrace.exp +@@ -85,11 +85,7 @@ with_test_prefix "instruction " { + gdb_test "python print(i.number)" "1" + gdb_test "python print(i.sal)" "symbol and line for .*" + gdb_test "python print(i.pc)" "$decimal" +- if { $gdb_py_is_py3k == 0 } { +- gdb_test "python print(repr(i.data))" "" +- } else { +- gdb_test "python print(repr(i.data))" "" +- } ++ gdb_test "python print(repr(i.data))" "" + gdb_test "python print(i.decoded)" ".*" + gdb_test "python print(i.size)" "$decimal" + gdb_test "python print(i.is_speculative)" "False" +diff --git a/gdb/testsuite/gdb.python/py-send-packet.py b/gdb/testsuite/gdb.python/py-send-packet.py +index 4966688..a6adc82 100644 +--- a/gdb/testsuite/gdb.python/py-send-packet.py ++++ b/gdb/testsuite/gdb.python/py-send-packet.py +@@ -81,17 +81,9 @@ def run_send_packet_test(): + # the 'maint packet' command so that the output from the two sources + # can be compared. + def bytes_to_string(byte_array): +- +- # Python 2/3 compatibility. We need a function that can give us +- # the value of a single element in BYTE_ARRAY as an integer. +- if sys.version_info[0] > 2: +- value_of_single_byte = int +- else: +- value_of_single_byte = ord +- + res = "" + for b in byte_array: +- b = value_of_single_byte(b) ++ b = int(b) + if b >= 32 and b <= 126: + res = res + ("%c" % b) + else: +@@ -136,39 +128,23 @@ def run_set_global_var_test(): + res = conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr) + assert isinstance(res, bytes) + check_global_var(0x02020202) +- if sys.version_info[0] > 2: +- # On Python 3 this first attempt will not work as we're +- # passing a Unicode string containing non-ascii characters. +- saw_error = False +- try: +- res = conn.send_packet("X%x,4:\xff\xff\xff\xff" % addr) +- except UnicodeError: +- saw_error = True +- except: +- assert False +- assert saw_error +- check_global_var(0x02020202) +- # Now we pass a bytes object, which will work. +- res = conn.send_packet(b"X%x,4:\xff\xff\xff\xff" % addr) +- check_global_var(0xFFFFFFFF) +- else: +- # On Python 2 we need to force the creation of a Unicode +- # string, but, with that done, we expect to see the same error +- # as on Python 3; the unicode string contains non-ascii +- # characters. +- saw_error = False +- try: +- res = conn.send_packet(unicode("X%x,4:\xff\xff\xff\xff") % addr) +- except UnicodeError: +- saw_error = True +- except: +- assert False +- assert saw_error +- check_global_var(0x02020202) +- # Now we pass a plain string, which, on Python 2, is the same +- # as a bytes object, this, we expect to work. ++ ++ # This first attempt will not work as we're passing a Unicode string ++ # containing non-ascii characters. ++ saw_error = False ++ try: + res = conn.send_packet("X%x,4:\xff\xff\xff\xff" % addr) +- check_global_var(0xFFFFFFFF) ++ except UnicodeError: ++ saw_error = True ++ except: ++ assert False ++ ++ assert saw_error ++ check_global_var(0x02020202) ++ # Now we pass a bytes object, which will work. ++ res = conn.send_packet(b"X%x,4:\xff\xff\xff\xff" % addr) ++ check_global_var(0xFFFFFFFF) ++ + print("set global_var test passed") + + +diff --git a/gdb/testsuite/gdb.python/py-shared.exp b/gdb/testsuite/gdb.python/py-shared.exp +index 61c057a..2d33902 100644 +--- a/gdb/testsuite/gdb.python/py-shared.exp ++++ b/gdb/testsuite/gdb.python/py-shared.exp +@@ -57,14 +57,11 @@ runto [gdb_get_line_number "Break to end."] + # Test gdb.solib_name + gdb_test "p &func1" "" "func1 address" + gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1 +-if { $gdb_py_is_py3k == 1 } { +- gdb_py_test_silent_cmd "python long = int" "" 0 +-} +-gdb_test "python print (gdb.solib_name(long(func1)))" "py-shared-sl.sl" "test func1 solib location" ++gdb_test "python print (gdb.solib_name(int(func1)))" "py-shared-sl.sl" "test func1 solib location" + + gdb_test "p &main" "" "main address" + gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1 +-gdb_test "python print (gdb.solib_name(long(main)))" "None" "test main solib location" ++gdb_test "python print (gdb.solib_name(int(main)))" "None" "test main solib location" + + if {[is_lp64_target]} { + gdb_test "python print (len(\[gdb.solib_name(0xffffffffffffffff)\]))" "1" +diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp +index 2ea8363..b88c451 100644 +--- a/gdb/testsuite/gdb.python/py-value.exp ++++ b/gdb/testsuite/gdb.python/py-value.exp +@@ -47,33 +47,19 @@ proc build_inferior {exefile lang} { + + proc test_value_creation {} { + global gdb_prompt +- global gdb_py_is_py3k + + gdb_py_test_silent_cmd "python i = gdb.Value (True)" "create boolean value" 1 + gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create integer value" 1 + gdb_py_test_silent_cmd "python i = gdb.Value (3,None)" "create integer value, with None type" 1 +- if { $gdb_py_is_py3k == 0 } { +- gdb_py_test_silent_cmd "python i = gdb.Value (5L)" "create long value" 1 +- } + + gdb_py_test_silent_cmd "python l = gdb.Value(0xffffffff12345678)" "create large unsigned 64-bit value" 1 +- if { $gdb_py_is_py3k == 0 } { +- gdb_test "python print long(l)" "18446744069720004216" "large unsigned 64-bit int conversion to python" +- } else { +- gdb_test "python print (int(l))" "18446744069720004216" "large unsigned 64-bit int conversion to python" +- } ++ gdb_test "python print (int(l))" "18446744069720004216" "large unsigned 64-bit int conversion to python" + + gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create double value" 1 + gdb_py_test_silent_cmd "python a = gdb.Value ('string test')" "create 8-bit string value" 1 + gdb_test "python print (a)" "\"string test\"" "print 8-bit string" + gdb_test "python print (a.__class__)" "<(type|class) 'gdb.Value'>" "verify type of 8-bit string" + +- if { $gdb_py_is_py3k == 0 } { +- gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1 +- gdb_test "python print (a)" "\"unicode test\"" "print Unicode string" +- gdb_test "python print (a.__class__)" "<(type|class) 'gdb.Value'>" "verify type of unicode string" +- } +- + # Test address attribute is None in a non-addressable value + gdb_test "python print ('result = %s' % i.address)" "= None" "test address attribute in non-addressable value" + +@@ -95,7 +81,6 @@ proc test_value_reinit {} { + + proc test_value_numeric_ops {} { + global gdb_prompt +- global gdb_py_is_py3k + + gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create first integer value" 0 + gdb_py_test_silent_cmd "python j = gdb.Value (2)" "create second integer value" 0 +@@ -147,9 +132,6 @@ proc test_value_numeric_ops {} { + gdb_test_no_output "python b = gdb.history (0)" "" + + gdb_test "python print(int(b))" "5" "convert pointer to int" +- if {!$gdb_py_is_py3k} { +- gdb_test "python print(long(b))" "5" "convert pointer to long" +- } + + gdb_test "python print ('result = ' + str(a+5))" " = 0x7( <.*>)?" "add pointer value with python integer" + gdb_test "python print ('result = ' + str(b-2))" " = 0x3( <.*>)?" "subtract python integer from pointer value" +@@ -159,17 +141,11 @@ proc test_value_numeric_ops {} { + "result = r" "use value as string index" + gdb_test "python print ('result = ' + str((1,2,3)\[gdb.Value(0)\]))" \ + "result = 1" "use value as tuple index" +- if {!$gdb_py_is_py3k} { +- gdb_test "python print ('result = ' + str(\[1,2,3\]\[gdb.Value(0)\]))" \ +- "result = 1" "use value as array index" +- } ++ gdb_test "python print ('result = ' + str(\[1,2,3\]\[gdb.Value(0)\]))" \ ++ "result = 1" "use value as array index" + + gdb_test "python print('%x' % int(gdb.parse_and_eval('-1ull')))" \ + "f+" "int conversion respect type sign" +- if {!$gdb_py_is_py3k} { +- gdb_test "python print('%x' % long(gdb.parse_and_eval('-1ull')))" \ +- "f+" "long conversion respect type sign" +- } + + # Test some invalid operations. + +@@ -245,7 +221,6 @@ proc test_value_compare {} { + proc test_value_in_inferior {} { + global gdb_prompt + global testfile +- global gdb_py_is_py3k + + gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"] + gdb_continue_to_breakpoint "break to inspect struct and union" +@@ -256,9 +231,6 @@ proc test_value_in_inferior {} { + gdb_py_test_silent_cmd "python s = gdb.history (0)" "get value s from history" 1 + + gdb_test "python print ('result = ' + str(s\['a'\]))" " = 3" "access element inside struct using 8-bit string name" +- if { $gdb_py_is_py3k == 0 } { +- gdb_test "python print ('result = ' + str(s\[u'a'\]))" " = 3" "access element inside struct using unicode name" +- } + + # Test dereferencing the argv pointer + +@@ -536,13 +508,8 @@ proc test_value_hash {} { + } + + proc test_float_conversion {} { +- global gdb_py_is_py3k + gdb_test "python print(int(gdb.Value(0)))" "0" + gdb_test "python print(int(gdb.Value(2.5)))" "2" +- if {!$gdb_py_is_py3k} { +- gdb_test "python print(long(gdb.Value(0)))" "0" +- gdb_test "python print(long(gdb.Value(2.5)))" "2" +- } + gdb_test "python print(float(gdb.Value(2.5)))" "2\\.5" + gdb_test "python print(float(gdb.Value(0)))" "0\\.0" + } +@@ -568,7 +535,6 @@ proc prepare_type_and_buffer {} { + + proc test_value_from_buffer {} { + global gdb_prompt +- global gdb_py_is_py3k + + prepare_type_and_buffer + gdb_test "python v=gdb.Value(b,tp); print(v)" "1" \ +diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp +index efe1c39..ba8b930 100644 +--- a/gdb/testsuite/lib/gdb.exp ++++ b/gdb/testsuite/lib/gdb.exp +@@ -2340,8 +2340,6 @@ proc skip_rust_tests {} { + # PROMPT_REGEXP is the expected prompt. + + proc skip_python_tests_prompt { prompt_regexp } { +- global gdb_py_is_py3k +- + gdb_test_multiple "python print ('test')" "verify python support" \ + -prompt "$prompt_regexp" { + -re "not supported.*$prompt_regexp" { +@@ -2351,16 +2349,6 @@ proc skip_python_tests_prompt { prompt_regexp } { + -re "$prompt_regexp" {} + } + +- gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" \ +- -prompt "$prompt_regexp" { +- -re "3.*$prompt_regexp" { +- set gdb_py_is_py3k 1 +- } +- -re ".*$prompt_regexp" { +- set gdb_py_is_py3k 0 +- } +- } +- + return 0 + } + +-- +2.33.0 + diff --git a/gdb.spec b/gdb.spec index c48e428..a1d0192 100644 --- a/gdb.spec +++ b/gdb.spec @@ -1,6 +1,6 @@ Name: gdb Version: 12.1 -Release: 4 +Release: 5 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL-1.3 Source: https://ftp.gnu.org/gnu/gdb/gdb-%{version}.tar.xz @@ -89,6 +89,10 @@ Patch76: gdb-sw22395-constify-target_desc.patch Patch77: 0001-set-entry-point-when-text-segment-is-missing.patch Patch78: 0002-Add-support-for-readline-8.2.patch Patch79: gdb-initialize-the-data_head-variable-to-eliminate-c.patch +Patch80: gdb-python-remove-Python-2-support.patch +Patch81: gdb-Use-bool-for-evregpy_no_listeners_p.patch +Patch82: gdb-Make-import-gdb.events-work.patch +Patch83: gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch %global gdb_src gdb-%{version} %global gdb_build build-%{_target_platform} @@ -364,6 +368,9 @@ rm -f $RPM_BUILD_ROOT%{_datadir}/gdb/python/gdb/command/backtrace.py %{_infodir}/ctf-spec.info.gz %changelog +* Thu Jul 27 2023 Wenyu Liu - 12.1-5 +- Handle Python 3.11 deprecation of PySys_SetPath and Py_SetProgramName + * Thu Jul 27 2023 Wenyu Liu - 12.1-4 - initialize the data_head variable to eliminate compilation warnings -- Gitee From bffdd7c6f1916438e3ebed7aa05e6951cbb58311 Mon Sep 17 00:00:00 2001 From: Wenyu Liu Date: Thu, 3 Aug 2023 17:34:29 +0800 Subject: [PATCH 3/3] libctf: update regexp to allow makeinfo to build document Signed-off-by: WizardHowl --- ...gexp-to-allow-makeinfo-to-build-docu.patch | 76 +++++++++++++++++++ gdb.spec | 6 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 gdb-libctf-update-regexp-to-allow-makeinfo-to-build-docu.patch diff --git a/gdb-libctf-update-regexp-to-allow-makeinfo-to-build-docu.patch b/gdb-libctf-update-regexp-to-allow-makeinfo-to-build-docu.patch new file mode 100644 index 0000000..39e234e --- /dev/null +++ b/gdb-libctf-update-regexp-to-allow-makeinfo-to-build-docu.patch @@ -0,0 +1,76 @@ +From 24669c55aed712c192b80456295cce122c7d5f73 Mon Sep 17 00:00:00 2001 +From: Enze Li +Date: Sat, 14 Jan 2023 11:33:48 +0800 +Subject: [PATCH] libctf: update regexp to allow makeinfo to build document + +While trying to build gdb on latest openSUSE Tumbleweed, I noticed the +following warning, + + checking for makeinfo... makeinfo --split-size=5000000 + configure: WARNING: + *** Makeinfo is too old. Info documentation will not be built. + +then I checked the version of makeinfo, it said, +====== +$ makeinfo --version +texi2any (GNU texinfo) 7.0.1 + +Copyright (C) 2022 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +====== + +After digging a little bit, it became quite obvious that a dot is +missing in regexp that makes it impossible to match versions higher than +7.0, and here's the solution: + +- | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then ++ | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]\.[0-9])' >/dev/null 2>&1; then + +However, Eli pointed out that the solution above has another problem: it +will stop working when Texinfo 10.1 will be released. Meanwhile, he +suggested to solve this problem permanently. That is, we don't care +about the minor version for Texinfo > 6.9, we only care about the major +version. + +In this way, the problem will be resolved permanently, thanks to Eli. + +libctf/ChangeLog: + + * configure: Regenerated. + * configure.ac: Update regexp to match versions higher than 7.0. +--- + libctf/configure | 2 +- + libctf/configure.ac | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/libctf/configure b/libctf/configure +index c22f7dffd2c..a0e40f49a80 100755 +--- a/libctf/configure ++++ b/libctf/configure +@@ -14864,7 +14864,7 @@ esac + # We require texinfo to be 6.3 or later, for a working synindex + # and validatemenus: otherwise we fall back to /bin/true. + if ${MAKEINFO} --version \ +- | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then ++ | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]|[1-6][0-9])' >/dev/null 2>&1; then + build_info=yes + else + build_info= +diff --git a/libctf/configure.ac b/libctf/configure.ac +index 1d0cf4d0fa5..6a5eade1855 100644 +--- a/libctf/configure.ac ++++ b/libctf/configure.ac +@@ -184,7 +184,7 @@ changequote(,) + # We require texinfo to be 6.3 or later, for a working synindex + # and validatemenus: otherwise we fall back to /bin/true. + if ${MAKEINFO} --version \ +- | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then ++ | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]|[1-6][0-9])' >/dev/null 2>&1; then + build_info=yes + else + build_info= +-- +2.33.0 + diff --git a/gdb.spec b/gdb.spec index a1d0192..50b87b7 100644 --- a/gdb.spec +++ b/gdb.spec @@ -1,6 +1,6 @@ Name: gdb Version: 12.1 -Release: 5 +Release: 6 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL-1.3 Source: https://ftp.gnu.org/gnu/gdb/gdb-%{version}.tar.xz @@ -93,6 +93,7 @@ Patch80: gdb-python-remove-Python-2-support.patch Patch81: gdb-Use-bool-for-evregpy_no_listeners_p.patch Patch82: gdb-Make-import-gdb.events-work.patch Patch83: gdb-Handle-Python-3.11-deprecation-of-PySys_SetPath-and-.patch +Patch84: gdb-libctf-update-regexp-to-allow-makeinfo-to-build-docu.patch %global gdb_src gdb-%{version} %global gdb_build build-%{_target_platform} @@ -368,6 +369,9 @@ rm -f $RPM_BUILD_ROOT%{_datadir}/gdb/python/gdb/command/backtrace.py %{_infodir}/ctf-spec.info.gz %changelog +* Thu Aug 3 2023 Wenyu Liu - 12.1-6 +- libctf: update regexp to allow makeinfo to build document + * Thu Jul 27 2023 Wenyu Liu - 12.1-5 - Handle Python 3.11 deprecation of PySys_SetPath and Py_SetProgramName -- Gitee