public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb/python: remove Python 2 support
@ 2022-01-07 15:29 Simon Marchi
  2022-01-07 15:29 ` [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
                   ` (5 more replies)
  0 siblings, 6 replies; 27+ messages in thread
From: Simon Marchi @ 2022-01-07 15:29 UTC (permalink / raw)
  To: gdb-patches

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

I therefore propose to drop Python 2 support.  I know that a few
maintainers have given their informal support for this (on IRC and the
mailing list).

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/configure                                 | 75 -------------------
 gdb/configure.ac                              | 11 ---
 gdb/doc/python.texi                           |  3 +-
 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 ---
 26 files changed, 48 insertions(+), 501 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 429eaebe5688..02c2a895c8d8 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11280,81 +11280,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; }
 
-  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
-
-
-  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;
-}
-_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
   fi
 
   if test "${have_libpython}" = no; then
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 13e880d59a99..58a8ba9ac21f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -733,7 +733,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 -
@@ -742,7 +741,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 -
@@ -877,15 +875,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 6bd5f6b90ac3..6e89aae02bd3 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -18,8 +18,7 @@
 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.
+@value{GDBN} can be built against Python 3.
 
 @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 11a1b444bfd0..0c04a72f7819 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -21,7 +21,7 @@ import _gdb
 # 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 ea49c38d7f01..c03bef34182a 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 f8ce9ead7c22..7cb6e8f34023 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 93d61f127dc0..e208e889caae 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 4c3a52206fa0..c69ea9992a33 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 0f273b344e47..e87881a8fd39 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 457825c98638..23a5d75ae21b 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 936354f354c1..60b9375b5278 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 e789a78e6493..fa8731a515f9 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<gdb_byte> 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.  */
@@ -87,8 +79,6 @@ which is %s bytes long."),
 			      pulongest (membuf_obj->length));
 }
 
-#ifdef IS_PY3K
-
 static int
 get_buffer (PyObject *self, Py_buffer *buf, int flags)
 {
@@ -106,54 +96,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
@@ -167,24 +109,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 592ecbb41f97..a601790102c1 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 2a0e89ddcfa4..bee17e0e3cc2 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 220b0d46ffb0..ed487d82cac3 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1575,9 +1575,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 */
@@ -1591,19 +1588,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 79e1c013261c..0d1a55734671 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;
     }
 
@@ -164,11 +160,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).
@@ -180,17 +172,7 @@ gdbpy_obj_to_string (PyObject *obj)
   gdbpy_ref<> str_obj (PyObject_Str (obj));
 
   if (str_obj != NULL)
-    {
-      gdb::unique_xmalloc_ptr<char> 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;
 }
@@ -294,20 +276,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
@@ -316,23 +287,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 70b33d5a27bb..9056d3af5c05 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1689,41 +1689,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)
@@ -1908,15 +1873,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);
@@ -1942,14 +1898,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)
     {
@@ -2162,9 +2112,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 */
@@ -2178,25 +2125,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 583989c5a6da..421031c9609d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -87,11 +87,6 @@
 #include <frameobject.h>
 #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 e05b99c0becb..ebfe7823d743 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -298,11 +298,6 @@ eval_python_command (const char *command)
   if (v == NULL)
     return -1;
 
-#ifndef IS_PY3K
-  if (Py_FlushLine ())
-    PyErr_Clear ();
-#endif
-
   return 0;
 }
 
@@ -1695,7 +1690,6 @@ finalize_python (void *ignore)
   restore_active_ext_lang (previous_active);
 }
 
-#ifdef IS_PY3K
 static struct PyModuleDef python_GdbModuleDef =
 {
   PyModuleDef_HEAD_INIT,
@@ -1718,7 +1712,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.  */
@@ -1765,7 +1758,6 @@ do_start_initialization ()
   gdb::unique_xmalloc_ptr<char> 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
@@ -1794,9 +1786,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 ();
@@ -1807,11 +1796,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;
 
@@ -2111,11 +2096,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 5b5f58243e42..4355a47fc17a 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 dfc2ebdf0e47..035478f6dc78 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 8204577b8662..e9fdd06154e8 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))" "<read-only buffer for $hex,.*>"
-    } else {
-	gdb_test "python print(repr(i.data))" "<memory at $hex>"
-    }
+    gdb_test "python print(repr(i.data))" "<memory at $hex>"
     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 4966688a9222..a6adc8279cb4 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 61c057ace922..2d3390284fe8 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 9ee3c5f223d2..f96af1f84f72 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"
 }
@@ -92,7 +78,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
@@ -144,9 +129,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"
@@ -156,17 +138,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.
 
@@ -242,7 +218,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"
@@ -253,9 +228,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
 
@@ -533,13 +505,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"
 }
@@ -565,7 +532,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 60f7b83571ad..a7a8d8855e90 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2311,8 +2311,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" {
@@ -2322,16 +2320,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
 }
 

base-commit: 0e9f1c04b9572920c7f940203a67d5af3f6c19f6
-- 
2.34.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
@ 2022-01-07 15:29 ` Simon Marchi
  2022-01-07 15:29 ` [PATCH 3/3] gdb/python: drop support for Python < 3.4 Simon Marchi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-01-07 15:29 UTC (permalink / raw)
  To: gdb-patches

python-internal.h contains a number of macros that helped make the code
work with both Python 2 and 3.  Remove them and adjust the code to use
the Python 3 functions.

Change-Id: I99a3d80067fb2d65de4f69f6473ba6ffd16efb2d
---
 gdb/python/py-arch.c          | 11 +++++------
 gdb/python/py-breakpoint.c    | 12 ++++++------
 gdb/python/py-cmd.c           | 10 +++++-----
 gdb/python/py-connection.c    |  4 ++--
 gdb/python/py-frame.c         |  2 +-
 gdb/python/py-inferior.c      |  4 ++--
 gdb/python/py-infthread.c     |  2 +-
 gdb/python/py-lazy-string.c   |  2 +-
 gdb/python/py-membuf.c        |  2 +-
 gdb/python/py-objfile.c       |  6 +++---
 gdb/python/py-param.c         | 16 ++++++++--------
 gdb/python/py-record-btrace.c |  8 ++++----
 gdb/python/py-record-full.c   |  4 ++--
 gdb/python/py-record.c        |  2 +-
 gdb/python/py-registers.c     |  6 +++---
 gdb/python/py-signalevent.c   |  2 +-
 gdb/python/py-symbol.c        |  6 +++---
 gdb/python/py-symtab.c        |  4 ++--
 gdb/python/py-type.c          | 12 ++++++------
 gdb/python/py-unwind.c        |  6 +++---
 gdb/python/py-utils.c         |  8 ++++----
 gdb/python/py-xmethods.c      |  6 +++---
 gdb/python/python-internal.h  | 22 ----------------------
 gdb/python/python.c           | 26 +++++++++++++-------------
 24 files changed, 80 insertions(+), 103 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index e87881a8fd39..da6af8755739 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -100,7 +100,7 @@ archpy_name (PyObject *self, PyObject *args)
   ARCHPY_REQUIRE_VALID (self, gdbarch);
 
   name = (gdbarch_bfd_arch_info (gdbarch))->printable_name;
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implementation of
@@ -158,7 +158,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
     }
   if (count_obj)
     {
-      count = PyInt_AsLong (count_obj);
+      count = PyLong_AsLong (count_obj);
       if (PyErr_Occurred () || count < 0)
 	{
 	  PyErr_SetString (PyExc_TypeError,
@@ -207,9 +207,8 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
       if (pc_obj == nullptr)
 	return nullptr;
 
-      gdbpy_ref<> asm_obj (PyString_FromString (!stb.empty ()
-						? stb.c_str ()
-						: "<unknown>"));
+      gdbpy_ref<> asm_obj
+	(PyUnicode_FromString (!stb.empty () ? stb.c_str () : "<unknown>"));
       if (asm_obj == nullptr)
 	return nullptr;
 
@@ -332,7 +331,7 @@ gdbpy_all_architecture_names (PyObject *self, PyObject *args)
   std::vector<const char *> name_list = gdbarch_printable_names ();
   for (const char *name : name_list)
     {
-      gdbpy_ref <> py_name (PyString_FromString (name));
+      gdbpy_ref <> py_name (PyUnicode_FromString (name));
       if (py_name == nullptr)
 	return nullptr;
       if (PyList_Append (list.get (), py_name.get ()) < 0)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index f00bd6f78e61..6eb980be9b25 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -224,7 +224,7 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `thread' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -266,7 +266,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `task' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -341,7 +341,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `ignore_count' attribute."));
       return -1;
     }
-  else if (! PyInt_Check (newvalue))
+  else if (! PyLong_Check (newvalue))
     {
       PyErr_SetString (PyExc_TypeError,
 		       _("The value of `ignore_count' must be an integer."));
@@ -780,9 +780,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
   if (lineobj != NULL)
     {
-      if (PyInt_Check (lineobj))
-	line = xstrprintf ("%ld", PyInt_AsLong (lineobj));
-      else if (PyString_Check (lineobj))
+      if (PyLong_Check (lineobj))
+	line = xstrprintf ("%ld", PyLong_AsLong (lineobj));
+      else if (PyUnicode_Check (lineobj))
 	line = python_string_to_host_string (lineobj);
       else
 	{
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3a4e6490cf09..9181aadcd011 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -233,7 +233,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  We are only
@@ -277,7 +277,7 @@ cmdpy_completer (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  */
@@ -592,10 +592,10 @@ gdbpy_initialize_commands (void)
 			      (PyObject *) &cmdpy_object_type) < 0)
     return -1;
 
-  invoke_cst = PyString_FromString ("invoke");
+  invoke_cst = PyUnicode_FromString ("invoke");
   if (invoke_cst == NULL)
     return -1;
-  complete_cst = PyString_FromString ("complete");
+  complete_cst = PyUnicode_FromString ("complete");
   if (complete_cst == NULL)
     return -1;
 
@@ -684,7 +684,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
 
       for (char *arg : c_argv)
 	{
-	  gdbpy_ref<> argp (PyString_FromString (arg));
+	  gdbpy_ref<> argp (PyUnicode_FromString (arg));
 
 	  if (argp == NULL
 	      || PyList_Append (py_argv.get (), argp.get ()) < 0)
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index 7c33a1f93d43..c125e4754375 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -204,9 +204,9 @@ connpy_repr (PyObject *obj)
   process_stratum_target *target = self->target;
 
   if (target == nullptr)
-    return PyString_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
+    return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
 
-  return PyString_FromFormat ("<%s num=%d, what=\"%s\">",
+  return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">",
 			      Py_TYPE (obj)->tp_name,
 			      target->connection_number,
 			      make_target_connection_string (target).c_str ());
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 0cab8e159465..bf9eba89c5fd 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -80,7 +80,7 @@ static PyObject *
 frapy_str (PyObject *self)
 {
   const frame_id &fid = ((frame_object *) self)->frame_id;
-  return PyString_FromString (fid.to_string ().c_str ());
+  return PyUnicode_FromString (fid.to_string ().c_str ());
 }
 
 /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 45e33f9e28a7..87b5a20cf1e4 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -754,9 +754,9 @@ infpy_repr (PyObject *obj)
   inferior *inf = self->inferior;
 
   if (inf == nullptr)
-    return PyString_FromString ("<gdb.Inferior (invalid)>");
+    return PyUnicode_FromString ("<gdb.Inferior (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
+  return PyUnicode_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
 			      inf->num, inf->pid);
 }
 
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index e568d8d916e4..fdf337f056a3 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -73,7 +73,7 @@ thpy_get_name (PyObject *self, void *ignore)
   if (name == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 static int
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 69b1bc52ab9a..c49987e25300 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -73,7 +73,7 @@ stpy_get_encoding (PyObject *self, void *closure)
   /* An encoding can be set to NULL by the user, so check before
      attempting a Python FromString call.  If NULL return Py_None.  */
   if (self_string->encoding)
-    result = PyString_FromString (self_string->encoding);
+    result = PyUnicode_FromString (self_string->encoding);
   else
     {
       result = Py_None;
diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
index fa8731a515f9..ee49b97aa44d 100644
--- a/gdb/python/py-membuf.c
+++ b/gdb/python/py-membuf.c
@@ -73,7 +73,7 @@ mbpy_str (PyObject *self)
 {
   membuf_object *membuf_obj = (membuf_object *) self;
 
-  return PyString_FromFormat (_("Memory buffer for address %s, \
+  return PyUnicode_FromFormat (_("Memory buffer for address %s, \
 which is %s bytes long."),
 			      paddress (python_gdbarch, membuf_obj->addr),
 			      pulongest (membuf_obj->length));
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 38052245bde7..12b4e15c3442 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -510,10 +510,10 @@ objfpy_repr (PyObject *self_)
   objfile *obj = self->objfile;
 
   if (obj == nullptr)
-    return PyString_FromString ("<gdb.Objfile (invalid)>");
+    return PyUnicode_FromString ("<gdb.Objfile (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Objfile filename=%s>",
-			      objfile_filename (obj));
+  return PyUnicode_FromFormat ("<gdb.Objfile filename=%s>",
+			       objfile_filename (obj));
 }
 
 /* Subroutine of gdbpy_lookup_objfile_by_build_id to simplify it.
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index a601790102c1..c86f0ee538ed 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -125,7 +125,7 @@ static PyObject *show_doc_cst;
 static PyObject *
 get_attr (PyObject *obj, PyObject *attr_name)
 {
-  if (PyString_Check (attr_name)
+  if (PyUnicode_Check (attr_name)
       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
     {
       parmpy_object *self = (parmpy_object *) obj;
@@ -243,7 +243,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	long l;
 	int ok;
 
-	if (! PyInt_Check (value))
+	if (! PyLong_Check (value))
 	  {
 	    PyErr_SetString (PyExc_RuntimeError,
 			     _("The value must be integer."));
@@ -308,7 +308,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 static int
 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
 {
-  if (PyString_Check (attr_name)
+  if (PyUnicode_Check (attr_name)
       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
     {
       if (!val)
@@ -389,7 +389,7 @@ get_set_value (const char *args, int from_tty,
   gdb::unique_xmalloc_ptr<char> set_doc_string;
 
   gdbpy_enter enter_py (get_current_arch (), current_language);
-  gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
+  gdbpy_ref<> set_doc_func (PyUnicode_FromString ("get_set_string"));
 
   if (set_doc_func == NULL)
     {
@@ -424,7 +424,7 @@ get_show_value (struct ui_file *file, int from_tty,
   gdb::unique_xmalloc_ptr<char> show_doc_string;
 
   gdbpy_enter enter_py (get_current_arch (), current_language);
-  gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
+  gdbpy_ref<> show_doc_func (PyUnicode_FromString ("get_show_string"));
 
   if (show_doc_func == NULL)
     {
@@ -434,7 +434,7 @@ get_show_value (struct ui_file *file, int from_tty,
 
   if (PyObject_HasAttr (obj, show_doc_func.get ()))
     {
-      gdbpy_ref<> val_obj (PyString_FromString (value));
+      gdbpy_ref<> val_obj (PyUnicode_FromString (value));
 
       if (val_obj == NULL)
 	{
@@ -773,10 +773,10 @@ gdbpy_initialize_parameters (void)
   if (PyType_Ready (&parmpy_object_type) < 0)
     return -1;
 
-  set_doc_cst = PyString_FromString ("set_doc");
+  set_doc_cst = PyUnicode_FromString ("set_doc");
   if (! set_doc_cst)
     return -1;
-  show_doc_cst = PyString_FromString ("show_doc");
+  show_doc_cst = PyUnicode_FromString ("show_doc");
   if (! show_doc_cst)
     return -1;
 
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index bee17e0e3cc2..85401010f0a0 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -471,9 +471,9 @@ btpy_list_slice (PyObject *self, PyObject *value)
   const Py_ssize_t length = btpy_list_length (self);
   Py_ssize_t start, stop, step, slicelength;
 
-  if (PyInt_Check (value))
+  if (PyLong_Check (value))
     {
-      Py_ssize_t index = PyInt_AsSsize_t (value);
+      Py_ssize_t index = PyLong_AsSsize_t (value);
 
       /* Emulate Python behavior for negative indices.  */
       if (index < 0)
@@ -607,7 +607,7 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
 PyObject *
 recpy_bt_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("btrace");
+  return PyUnicode_FromString ("btrace");
 }
 
 /* Implementation of
@@ -628,7 +628,7 @@ recpy_bt_format (PyObject *self, void *closure)
   if (config == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (btrace_format_short_string (config->format));
+  return PyUnicode_FromString (btrace_format_short_string (config->format));
 }
 
 /* Implementation of
diff --git a/gdb/python/py-record-full.c b/gdb/python/py-record-full.c
index 1caec735c497..ecae08bfc956 100644
--- a/gdb/python/py-record-full.c
+++ b/gdb/python/py-record-full.c
@@ -26,7 +26,7 @@
 PyObject *
 recpy_full_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
 
 /* Implementation of
@@ -35,5 +35,5 @@ recpy_full_method (PyObject *self, void *closure)
 PyObject *
 recpy_full_format (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index a4ab2936b014..51084dfac72c 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -474,7 +474,7 @@ recpy_gap_reason_string (PyObject *self, void *closure)
 {
   const recpy_gap_object * const obj = (const recpy_gap_object *) self;
 
-  return PyString_FromString (obj->reason_string);
+  return PyUnicode_FromString (obj->reason_string);
 }
 
 /* Record method list.  */
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index b3f784e7fc51..eab88a30b3b7 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -138,7 +138,7 @@ gdbpy_reggroup_to_string (PyObject *self)
   struct reggroup *reggroup = group->reggroup;
 
   const char *name = reggroup_name (reggroup);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterGroup.name (self) -> String.
@@ -196,7 +196,7 @@ gdbpy_register_descriptor_to_string (PyObject *self)
   int regnum = reg->regnum;
 
   const char *name = gdbarch_register_name (gdbarch, regnum);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterDescriptor.name attribute get function.  Return a
@@ -391,7 +391,7 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
 	}
     }
   /* The register could be its internal GDB register number.  */
-  else if (PyInt_Check (pyo_reg_id))
+  else if (PyLong_Check (pyo_reg_id))
     {
       long value;
       if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index e349f6107b29..69eeebbfaaa7 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -31,7 +31,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
 
   const char *signal_name = gdb_signal_to_name (stop_signal);
 
-  gdbpy_ref<> signal_name_obj (PyString_FromString (signal_name));
+  gdbpy_ref<> signal_name_obj (PyUnicode_FromString (signal_name));
   if (signal_name_obj == NULL)
     return NULL;
   if (evpy_add_attribute (signal_event_obj.get (),
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 508f445e1001..b06a24a942b0 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -60,7 +60,7 @@ sympy_str (PyObject *self)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  result = PyString_FromString (symbol->print_name ());
+  result = PyUnicode_FromString (symbol->print_name ());
 
   return result;
 }
@@ -101,7 +101,7 @@ sympy_get_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->natural_name ());
+  return PyUnicode_FromString (symbol->natural_name ());
 }
 
 static PyObject *
@@ -111,7 +111,7 @@ sympy_get_linkage_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->linkage_name ());
+  return PyUnicode_FromString (symbol->linkage_name ());
 }
 
 static PyObject *
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index db19e4b1213e..c3e1cf340354 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -93,7 +93,7 @@ stpy_str (PyObject *self)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  result = PyString_FromString (symtab_to_filename_for_display (symtab));
+  result = PyUnicode_FromString (symtab_to_filename_for_display (symtab));
 
   return result;
 }
@@ -234,7 +234,7 @@ salpy_str (PyObject *self)
       filename = symtab_to_filename_for_display (symtab);
     }
 
-  return PyString_FromFormat ("symbol and line for %s, line %d", filename,
+  return PyUnicode_FromFormat ("symbol and line for %s, line %d", filename,
 			      sal->line);
 }
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index ed487d82cac3..aa5d9b46b341 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -210,7 +210,7 @@ convert_field (struct type *type, int field)
 
       if (field_name[0] != '\0')
 	{
-	  arg.reset (PyString_FromString (type->field (field).name ()));
+	  arg.reset (PyUnicode_FromString (type->field (field).name ()));
 	  if (arg == NULL)
 	    return NULL;
 	}
@@ -262,7 +262,7 @@ field_name (struct type *type, int field)
   gdbpy_ref<> result;
 
   if (type->field (field).name ())
-    result.reset (PyString_FromString (type->field (field).name ()));
+    result.reset (PyUnicode_FromString (type->field (field).name ()));
   else
     result = gdbpy_ref<>::new_reference (Py_None);
 
@@ -400,9 +400,9 @@ typy_get_name (PyObject *self, void *closure)
     {
       std::string name = ada_decode (type->name (), false);
       if (!name.empty ())
-	return PyString_FromString (name.c_str ());
+	return PyUnicode_FromString (name.c_str ());
     }
-  return PyString_FromString (type->name ());
+  return PyUnicode_FromString (type->name ());
 }
 
 /* Return the type's tag, or None.  */
@@ -419,7 +419,7 @@ typy_get_tag (PyObject *self, void *closure)
 
   if (tagname == nullptr)
     Py_RETURN_NONE;
-  return PyString_FromString (tagname);
+  return PyUnicode_FromString (tagname);
 }
 
 /* Return the type's objfile, or None.  */
@@ -506,7 +506,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 
   if (n2_obj)
     {
-      if (!PyInt_Check (n2_obj))
+      if (!PyLong_Check (n2_obj))
 	{
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("Array bound must be an integer"));
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index a884c83ec269..f82dd9474c02 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -213,7 +213,7 @@ unwind_infopy_str (PyObject *self)
     stb.puts (")");
   }
 
-  return PyString_FromString (stb.c_str ());
+  return PyUnicode_FromString (stb.c_str ());
 }
 
 /* Create UnwindInfo instance for given PendingFrame and frame ID.
@@ -349,7 +349,7 @@ pending_framepy_str (PyObject *self)
   const char *pc_str = NULL;
 
   if (frame == NULL)
-    return PyString_FromString ("Stale PendingFrame instance");
+    return PyUnicode_FromString ("Stale PendingFrame instance");
   try
     {
       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
@@ -360,7 +360,7 @@ pending_framepy_str (PyObject *self)
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
+  return PyUnicode_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
 }
 
 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 0d1a55734671..8027fa469acf 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -150,8 +150,8 @@ python_string_to_host_string (PyObject *obj)
 gdbpy_ref<>
 host_string_to_python_string (const char *str)
 {
-  return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (),
-				       NULL));
+  return gdbpy_ref<> (PyUnicode_Decode (str, strlen (str), host_charset (),
+					NULL));
 }
 
 /* Return true if OBJ is a Python string or unicode object, false
@@ -292,13 +292,13 @@ gdb_py_object_from_ulongest (ULONGEST l)
   return gdbpy_ref<> (PyLong_FromUnsignedLong (l));
 }
 
-/* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts
+/* Like PyLong_AsLong, but returns 0 on failure, 1 on success, and puts
    the value into an out parameter.  */
 
 int
 gdb_py_int_as_long (PyObject *obj, long *result)
 {
-  *result = PyInt_AsLong (obj);
+  *result = PyLong_AsLong (obj);
   return ! (*result == -1 && PyErr_Occurred ());
 }
 
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index fd3673029a02..897f58cc7131 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -103,7 +103,7 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
   if (match_method == NULL)
     return NULL;
 
-  gdbpy_ref<> py_xmethod_name (PyString_FromString (xmethod_name));
+  gdbpy_ref<> py_xmethod_name (PyUnicode_FromString (xmethod_name));
   if (py_xmethod_name == NULL)
     return NULL;
 
@@ -601,12 +601,12 @@ python_xmethod_worker::python_xmethod_worker (PyObject *py_worker,
 int
 gdbpy_initialize_xmethods (void)
 {
-  py_match_method_name = PyString_FromString (match_method_name);
+  py_match_method_name = PyUnicode_FromString (match_method_name);
   if (py_match_method_name == NULL)
     return -1;
 
   py_get_arg_types_method_name
-    = PyString_FromString (get_arg_types_method_name);
+    = PyUnicode_FromString (get_arg_types_method_name);
   if (py_get_arg_types_method_name == NULL)
     return -1;
 
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 421031c9609d..b38d69258add 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -89,15 +89,6 @@
 
 #define Py_TPFLAGS_CHECKTYPES 0
 
-#define PyInt_Check PyLong_Check
-#define PyInt_AsLong PyLong_AsLong
-#define PyInt_AsSsize_t PyLong_AsSsize_t
-
-#define PyString_FromString PyUnicode_FromString
-#define PyString_Decode PyUnicode_Decode
-#define PyString_FromFormat PyUnicode_FromFormat
-#define PyString_Check PyUnicode_Check
-
 /* If Python.h does not define WITH_THREAD, then the various
    GIL-related functions will not be defined.  However,
    PyGILState_STATE will be.  */
@@ -141,19 +132,6 @@ typedef long Py_hash_t;
 #define PyMem_RawMalloc PyMem_Malloc
 #endif
 
-/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
-   to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
-   Wrap it ourselves, so that callers don't need to care.  */
-
-static inline void
-gdb_Py_DECREF (void *op) /* ARI: editCase function */
-{
-  Py_DECREF (op);
-}
-
-#undef Py_DECREF
-#define Py_DECREF(op) gdb_Py_DECREF (op)
-
 /* PyObject_CallMethod's 'method' and 'format' parameters were missing
    the 'const' qualifier before Python 3.4.  Hence, we wrap the
    function in our own version to avoid errors with string literals.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ebfe7823d743..a9dfb6f5877b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -656,7 +656,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
     }
 
   if (to_string)
-    return PyString_FromString (to_string_res.c_str ());
+    return PyUnicode_FromString (to_string_res.c_str ());
   Py_RETURN_NONE;
 }
 
@@ -902,7 +902,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
 
   if (arg != NULL && strlen (arg) > 0)
     {
-      unparsed.reset (PyString_FromString (arg));
+      unparsed.reset (PyUnicode_FromString (arg));
       if (unparsed == NULL)
 	return NULL;
     }
@@ -1064,7 +1064,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
 
       if (PyCallable_Check (hook.get ()))
 	{
-	  gdbpy_ref<> current_prompt (PyString_FromString (current_gdb_prompt));
+	  gdbpy_ref<> current_prompt (PyUnicode_FromString (current_gdb_prompt));
 	  if (current_prompt == NULL)
 	    {
 	      gdbpy_print_stack ();
@@ -1083,7 +1083,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
 	  /* Return type should be None, or a String.  If it is None,
 	     fall through, we will not set a prompt.  If it is a
 	     string, set  PROMPT.  Anything else, set an exception.  */
-	  if (result != Py_None && ! PyString_Check (result.get ()))
+	  if (result != Py_None && ! PyUnicode_Check (result.get ()))
 	    {
 	      PyErr_Format (PyExc_RuntimeError,
 			    _("Return from prompt_hook must " \
@@ -1136,13 +1136,13 @@ gdbpy_colorize (const std::string &filename, const std::string &contents)
   if (!PyCallable_Check (hook.get ()))
     return {};
 
-  gdbpy_ref<> fname_arg (PyString_FromString (filename.c_str ()));
+  gdbpy_ref<> fname_arg (PyUnicode_FromString (filename.c_str ()));
   if (fname_arg == nullptr)
     {
       gdbpy_print_stack ();
       return {};
     }
-  gdbpy_ref<> contents_arg (PyString_FromString (contents.c_str ()));
+  gdbpy_ref<> contents_arg (PyUnicode_FromString (contents.c_str ()));
   if (contents_arg == nullptr)
     {
       gdbpy_print_stack ();
@@ -1871,22 +1871,22 @@ do_start_initialization ()
 #include "py-event-types.def"
 #undef GDB_PY_DEFINE_EVENT_TYPE
 
-  gdbpy_to_string_cst = PyString_FromString ("to_string");
+  gdbpy_to_string_cst = PyUnicode_FromString ("to_string");
   if (gdbpy_to_string_cst == NULL)
     return false;
-  gdbpy_children_cst = PyString_FromString ("children");
+  gdbpy_children_cst = PyUnicode_FromString ("children");
   if (gdbpy_children_cst == NULL)
     return false;
-  gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+  gdbpy_display_hint_cst = PyUnicode_FromString ("display_hint");
   if (gdbpy_display_hint_cst == NULL)
     return false;
-  gdbpy_doc_cst = PyString_FromString ("__doc__");
+  gdbpy_doc_cst = PyUnicode_FromString ("__doc__");
   if (gdbpy_doc_cst == NULL)
     return false;
-  gdbpy_enabled_cst = PyString_FromString ("enabled");
+  gdbpy_enabled_cst = PyUnicode_FromString ("enabled");
   if (gdbpy_enabled_cst == NULL)
     return false;
-  gdbpy_value_cst = PyString_FromString ("value");
+  gdbpy_value_cst = PyUnicode_FromString ("value");
   if (gdbpy_value_cst == NULL)
     return false;
 
@@ -2101,7 +2101,7 @@ do_initialize (const struct extension_language_defn *extlang)
     }
   if (sys_path && PyList_Check (sys_path))
     {
-      gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ()));
+      gdbpy_ref<> pythondir (PyUnicode_FromString (gdb_pythondir.c_str ()));
       if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
 	return false;
     }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 3/3] gdb/python: drop support for Python < 3.4
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
  2022-01-07 15:29 ` [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
@ 2022-01-07 15:29 ` Simon Marchi
  2022-01-07 16:33   ` Eli Zaretskii
  2022-01-07 15:33 ` [PATCH 1/3] gdb/python: remove Python 2 support Paul Koning
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 27+ messages in thread
From: Simon Marchi @ 2022-01-07 15:29 UTC (permalink / raw)
  To: gdb-patches

Python 3 versions <= 3.3 are quite old and not likely to be used
nowadays.  Dropping support for them allows us to remove some hacks and
compatibility macros that depend on the Python version being < 3.4.

Change the documentation to state the Python 3 versions we support.

We could go even further and document that we only support versions 3.5
or 3.6 and up, for example, but that wouldn't change the code.  So we
might as well document the older Python 3 version we can support without
special hacks.

[1] https://www.python.org/dev/peps/pep-0478/
[2] https://www.python.org/dev/peps/pep-0494/

Change-Id: I608610dced678c93e2bd338a91662d1c706df511
---
 gdb/doc/python.texi                            |  2 +-
 gdb/python/lib/gdb/__init__.py                 |  8 +-------
 gdb/python/py-gdb-readline.c                   |  7 +------
 gdb/python/python-internal.h                   | 11 -----------
 gdb/testsuite/gdb.perf/lib/perftest/measure.py |  6 ------
 5 files changed, 3 insertions(+), 31 deletions(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 6e89aae02bd3..889888c4a459 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -18,7 +18,7 @@
 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 Python 3.
+@value{GDBN} can be built against Python 3, versions 3.4 and above.
 
 @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 0c04a72f7819..4c939da6d400 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -17,13 +17,7 @@ import traceback
 import os
 import sys
 import _gdb
-
-# Python 3 moved "reload"
-if sys.version_info >= (3, 4):
-    from importlib import reload
-else:
-    from imp import reload
-
+from importlib import reload
 from _gdb import *
 
 
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index af388d5ed72e..ee243d15412a 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -29,12 +29,7 @@
    command_line_input is used instead.  */
 
 static char *
-gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
-#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4
-			const char *prompt)
-#else
-			char *prompt)
-#endif
+gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
 {
   int n;
   const char *p = NULL;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b38d69258add..1137b1da56fe 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -121,17 +121,6 @@ typedef unsigned long gdb_py_ulongest;
 
 #endif /* HAVE_LONG_LONG */
 
-#if PY_VERSION_HEX < 0x03020000
-typedef long Py_hash_t;
-#endif
-
-/* PyMem_RawMalloc appeared in Python 3.4.  For earlier versions, we can just
-   fall back to PyMem_Malloc.  */
-
-#if PY_VERSION_HEX < 0x03040000
-#define PyMem_RawMalloc PyMem_Malloc
-#endif
-
 /* PyObject_CallMethod's 'method' and 'format' parameters were missing
    the 'const' qualifier before Python 3.4.  Hence, we wrap the
    function in our own version to avoid errors with string literals.
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/measure.py b/gdb/testsuite/gdb.perf/lib/perftest/measure.py
index 88fd6c87e52f..514687d0ec69 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/measure.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/measure.py
@@ -18,12 +18,6 @@ import os
 import gc
 import sys
 
-# time.perf_counter() and time.process_time() were added in Python
-# 3.3, time.clock() was removed in Python 3.8.
-if sys.version_info < (3, 3, 0):
-    time.perf_counter = time.clock
-    time.process_time = time.clock
-
 
 class Measure(object):
     """A class that measure and collect the interesting data for a given testcase.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
  2022-01-07 15:29 ` [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
  2022-01-07 15:29 ` [PATCH 3/3] gdb/python: drop support for Python < 3.4 Simon Marchi
@ 2022-01-07 15:33 ` Paul Koning
  2022-01-07 15:41   ` Simon Marchi
  2022-01-07 17:44 ` Andrew Burgess
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 27+ messages in thread
From: Paul Koning @ 2022-01-07 15:33 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches



> On Jan 7, 2022, at 10:29 AM, Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> wrote:
> 
> 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
> 
> I therefore propose to drop Python 2 support.  I know that a few
> maintainers have given their informal support for this (on IRC and the
> mailing list).

It sounds like a good change to me.

> ...
> 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. 

How hard is that?  It seems worth having such a check.

	paul



^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-07 15:33 ` [PATCH 1/3] gdb/python: remove Python 2 support Paul Koning
@ 2022-01-07 15:41   ` Simon Marchi
  0 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-01-07 15:41 UTC (permalink / raw)
  To: Paul Koning, gdb-patches

On 2022-01-07 10:33, Paul Koning wrote:
>> 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. 
> 
> How hard is that?  It seems worth having such a check.

Probably easy, for someone knowing what they are doing.  I was hoping
somebody else could take a look :).  Otherwise I will give it a try,
eventually.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 3/3] gdb/python: drop support for Python < 3.4
  2022-01-07 15:29 ` [PATCH 3/3] gdb/python: drop support for Python < 3.4 Simon Marchi
@ 2022-01-07 16:33   ` Eli Zaretskii
  2022-01-07 17:14     ` Simon Marchi
  0 siblings, 1 reply; 27+ messages in thread
From: Eli Zaretskii @ 2022-01-07 16:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

> Date: Fri,  7 Jan 2022 10:29:21 -0500
> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
> 
> Python 3 versions <= 3.3 are quite old and not likely to be used
> nowadays.  Dropping support for them allows us to remove some hacks and
> compatibility macros that depend on the Python version being < 3.4.

Are there real reasons to drop those old versions?  I mean, does
supporting them causes us some real maintenance burden?

> We could go even further and document that we only support versions 3.5
> or 3.6 and up, for example, but that wouldn't change the code.

That'd mean dropping support for Windows XP, as AFAIU 3.4 is the last
one which supports it.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 3/3] gdb/python: drop support for Python < 3.4
  2022-01-07 16:33   ` Eli Zaretskii
@ 2022-01-07 17:14     ` Simon Marchi
  0 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-01-07 17:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches



On 2022-01-07 11:33, Eli Zaretskii wrote:
>> Date: Fri,  7 Jan 2022 10:29:21 -0500
>> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
>>
>> Python 3 versions <= 3.3 are quite old and not likely to be used
>> nowadays.  Dropping support for them allows us to remove some hacks and
>> compatibility macros that depend on the Python version being < 3.4.
> 
> Are there real reasons to drop those old versions?  I mean, does
> supporting them causes us some real maintenance burden?

Not on the same level as supporting Python 2 does, no.  It's just on the
basis that these versions are long gone, in my experience.

I'll withdraw this patch, since keeping support for these old versions
isn't much of a burden.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
                   ` (2 preceding siblings ...)
  2022-01-07 15:33 ` [PATCH 1/3] gdb/python: remove Python 2 support Paul Koning
@ 2022-01-07 17:44 ` Andrew Burgess
  2022-01-08  8:18   ` Joel Brobecker
  2022-03-03 16:31 ` Andrew Burgess
  2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
  5 siblings, 1 reply; 27+ messages in thread
From: Andrew Burgess @ 2022-01-07 17:44 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2022-01-07 10:29:19 -0500]:

> 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
> 
> I therefore propose to drop Python 2 support.  I know that a few
> maintainers have given their informal support for this (on IRC and the
> mailing list).

Given this is a pretty big change (if you are a user that happens to
build against Py2), I wonder if it would be worth holding off this
change until after GDB 12 has branched?

We could add an entry to the NEWS file for GDB 12 to say something
like "This is the last version of GDB that will support Python 2.".
Then this gives users a good ~6 months+ notice to get their house in
order before GDB 13 lands without Python support.

Thoughts?

Thanks,
Andrew



> 
> 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/configure                                 | 75 -------------------
>  gdb/configure.ac                              | 11 ---
>  gdb/doc/python.texi                           |  3 +-
>  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 ---
>  26 files changed, 48 insertions(+), 501 deletions(-)
> 
> diff --git a/gdb/configure b/gdb/configure
> index 429eaebe5688..02c2a895c8d8 100755
> --- a/gdb/configure
> +++ b/gdb/configure
> @@ -11280,81 +11280,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; }
>  
> -  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
> -
> -
> -  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;
> -}
> -_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
>    fi
>  
>    if test "${have_libpython}" = no; then
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index 13e880d59a99..58a8ba9ac21f 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -733,7 +733,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 -
> @@ -742,7 +741,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 -
> @@ -877,15 +875,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 6bd5f6b90ac3..6e89aae02bd3 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -18,8 +18,7 @@
>  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.
> +@value{GDBN} can be built against Python 3.
>  
>  @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 11a1b444bfd0..0c04a72f7819 100644
> --- a/gdb/python/lib/gdb/__init__.py
> +++ b/gdb/python/lib/gdb/__init__.py
> @@ -21,7 +21,7 @@ import _gdb
>  # 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 ea49c38d7f01..c03bef34182a 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 f8ce9ead7c22..7cb6e8f34023 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 93d61f127dc0..e208e889caae 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 4c3a52206fa0..c69ea9992a33 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 0f273b344e47..e87881a8fd39 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 457825c98638..23a5d75ae21b 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 936354f354c1..60b9375b5278 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 e789a78e6493..fa8731a515f9 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<gdb_byte> 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.  */
> @@ -87,8 +79,6 @@ which is %s bytes long."),
>  			      pulongest (membuf_obj->length));
>  }
>  
> -#ifdef IS_PY3K
> -
>  static int
>  get_buffer (PyObject *self, Py_buffer *buf, int flags)
>  {
> @@ -106,54 +96,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
> @@ -167,24 +109,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 592ecbb41f97..a601790102c1 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 2a0e89ddcfa4..bee17e0e3cc2 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 220b0d46ffb0..ed487d82cac3 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -1575,9 +1575,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 */
> @@ -1591,19 +1588,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 79e1c013261c..0d1a55734671 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;
>      }
>  
> @@ -164,11 +160,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).
> @@ -180,17 +172,7 @@ gdbpy_obj_to_string (PyObject *obj)
>    gdbpy_ref<> str_obj (PyObject_Str (obj));
>  
>    if (str_obj != NULL)
> -    {
> -      gdb::unique_xmalloc_ptr<char> 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;
>  }
> @@ -294,20 +276,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
> @@ -316,23 +287,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 70b33d5a27bb..9056d3af5c05 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -1689,41 +1689,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)
> @@ -1908,15 +1873,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);
> @@ -1942,14 +1898,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)
>      {
> @@ -2162,9 +2112,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 */
> @@ -2178,25 +2125,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 583989c5a6da..421031c9609d 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -87,11 +87,6 @@
>  #include <frameobject.h>
>  #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 e05b99c0becb..ebfe7823d743 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -298,11 +298,6 @@ eval_python_command (const char *command)
>    if (v == NULL)
>      return -1;
>  
> -#ifndef IS_PY3K
> -  if (Py_FlushLine ())
> -    PyErr_Clear ();
> -#endif
> -
>    return 0;
>  }
>  
> @@ -1695,7 +1690,6 @@ finalize_python (void *ignore)
>    restore_active_ext_lang (previous_active);
>  }
>  
> -#ifdef IS_PY3K
>  static struct PyModuleDef python_GdbModuleDef =
>  {
>    PyModuleDef_HEAD_INIT,
> @@ -1718,7 +1712,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.  */
> @@ -1765,7 +1758,6 @@ do_start_initialization ()
>    gdb::unique_xmalloc_ptr<char> 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
> @@ -1794,9 +1786,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 ();
> @@ -1807,11 +1796,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;
>  
> @@ -2111,11 +2096,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 5b5f58243e42..4355a47fc17a 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 dfc2ebdf0e47..035478f6dc78 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 8204577b8662..e9fdd06154e8 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))" "<read-only buffer for $hex,.*>"
> -    } else {
> -	gdb_test "python print(repr(i.data))" "<memory at $hex>"
> -    }
> +    gdb_test "python print(repr(i.data))" "<memory at $hex>"
>      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 4966688a9222..a6adc8279cb4 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 61c057ace922..2d3390284fe8 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 9ee3c5f223d2..f96af1f84f72 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"
>  }
> @@ -92,7 +78,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
> @@ -144,9 +129,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"
> @@ -156,17 +138,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.
>  
> @@ -242,7 +218,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"
> @@ -253,9 +228,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
>  
> @@ -533,13 +505,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"
>  }
> @@ -565,7 +532,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 60f7b83571ad..a7a8d8855e90 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -2311,8 +2311,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" {
> @@ -2322,16 +2320,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
>  }
>  
> 
> base-commit: 0e9f1c04b9572920c7f940203a67d5af3f6c19f6
> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-07 17:44 ` Andrew Burgess
@ 2022-01-08  8:18   ` Joel Brobecker
  2022-01-10  2:28     ` Simon Marchi
  0 siblings, 1 reply; 27+ messages in thread
From: Joel Brobecker @ 2022-01-08  8:18 UTC (permalink / raw)
  To: Andrew Burgess via Gdb-patches; +Cc: Simon Marchi, Joel Brobecker

> > I therefore propose to drop Python 2 support.  I know that a few
> > maintainers have given their informal support for this (on IRC and the
> > mailing list).
> 
> Given this is a pretty big change (if you are a user that happens to
> build against Py2), I wonder if it would be worth holding off this
> change until after GDB 12 has branched?

FWIW, if it were me proposing the patch, I'd ask that we go ahead
now. Delaying patches always comes at a cost, and while I'm sympathetic
to those few who might not be ready to move to Python 3.x yet,
they can continue using GDB 11 if needed. Meanwhile, I'm hoping
to start discussions about GDB 12 a couple of weeks from now,
and it's typically taken us a couple of months before we reach
a point where we can branch, and then another month or two,
sometimes more, before the first release is out. So those who
still depend on Python 2.x have those many months to finish
their transition.

-- 
Joel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-08  8:18   ` Joel Brobecker
@ 2022-01-10  2:28     ` Simon Marchi
  2022-01-10  2:59       ` Joel Brobecker
  2022-01-10 16:26       ` Tom Tromey
  0 siblings, 2 replies; 27+ messages in thread
From: Simon Marchi @ 2022-01-10  2:28 UTC (permalink / raw)
  To: Joel Brobecker, Andrew Burgess via Gdb-patches

On 2022-01-08 03:18, Joel Brobecker wrote:
>>> I therefore propose to drop Python 2 support.  I know that a few
>>> maintainers have given their informal support for this (on IRC and the
>>> mailing list).
>>
>> Given this is a pretty big change (if you are a user that happens to
>> build against Py2), I wonder if it would be worth holding off this
>> change until after GDB 12 has branched?
> 
> FWIW, if it were me proposing the patch, I'd ask that we go ahead
> now. Delaying patches always comes at a cost, and while I'm sympathetic
> to those few who might not be ready to move to Python 3.x yet,
> they can continue using GDB 11 if needed. Meanwhile, I'm hoping
> to start discussions about GDB 12 a couple of weeks from now,
> and it's typically taken us a couple of months before we reach
> a point where we can branch, and then another month or two,
> sometimes more, before the first release is out. So those who
> still depend on Python 2.x have those many months to finish
> their transition.

Personally, I would also prefer merging sooner than later, just because
once it's done I can stop worrying about it.  But I am also not in a
hurry.  What finally triggered me to do this was the review of
Andrew's patch, I don't know if that is urgent or not.

Joel, I don't think that the problem is the time we leave to downstream
users who might be impacted, but how we reach them.  I like the idea of
the NEWS entry to give a heads up, because it might be the only way we
have to communicate with some downstream users.  Oh, and we could also
make it so GDB shows a warning at startup if it's built with Python 2,
saying that Python 2 support will be removed in the next version.  That
has maybe more chances of being seen.

If drop support in GDB 12, we don't have a chance to warn users (unless
we add that warning to GDB 11.2...).  We could always send an email on
the mailing lists, but that probably doesn't have as much reach.

So, if there is no particular rush, I am leaning towards aiming for GDB
13.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-10  2:28     ` Simon Marchi
@ 2022-01-10  2:59       ` Joel Brobecker
  2022-01-10 16:39         ` Simon Marchi
  2022-01-10 16:26       ` Tom Tromey
  1 sibling, 1 reply; 27+ messages in thread
From: Joel Brobecker @ 2022-01-10  2:59 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Joel Brobecker, Andrew Burgess via Gdb-patches

> Personally, I would also prefer merging sooner than later, just because
> once it's done I can stop worrying about it.  But I am also not in a
> hurry.  What finally triggered me to do this was the review of
> Andrew's patch, I don't know if that is urgent or not.
> 
> Joel, I don't think that the problem is the time we leave to downstream
> users who might be impacted, but how we reach them.  I like the idea of
> the NEWS entry to give a heads up, because it might be the only way we
> have to communicate with some downstream users.  Oh, and we could also
> make it so GDB shows a warning at startup if it's built with Python 2,
> saying that Python 2 support will be removed in the next version.  That
> has maybe more chances of being seen.
> 
> If drop support in GDB 12, we don't have a chance to warn users (unless
> we add that warning to GDB 11.2...).  We could always send an email on
> the mailing lists, but that probably doesn't have as much reach.
> 
> So, if there is no particular rush, I am leaning towards aiming for GDB
> 13.

If you do not mind, then, OK for me as well. But just in the spirit of
exploring all our options: What about adding a warning in the 11.2 NEWS?
We create a PR, add news entry, and the change is in both the NEWS and
the announcement I'm sending to everyone. We can also add a dedicated
NEWS entry on GDB's web page.

-- 
Joel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-10  2:28     ` Simon Marchi
  2022-01-10  2:59       ` Joel Brobecker
@ 2022-01-10 16:26       ` Tom Tromey
  1 sibling, 0 replies; 27+ messages in thread
From: Tom Tromey @ 2022-01-10 16:26 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Joel Brobecker, Simon Marchi

Simon> If drop support in GDB 12, we don't have a chance to warn users (unless
Simon> we add that warning to GDB 11.2...).  We could always send an email on
Simon> the mailing lists, but that probably doesn't have as much reach.

Simon> So, if there is no particular rush, I am leaning towards aiming for GDB
Simon> 13.

I don't really have a preference here -- I just wanted to say I'd
support either deprecation in 12 and removal in 13, or a special
deprecation note and removal in 12.  Either way I'm in favor of removing
the Python 2 support.

thanks,
Tom

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-10  2:59       ` Joel Brobecker
@ 2022-01-10 16:39         ` Simon Marchi
  2022-01-11  3:26           ` Joel Brobecker
  0 siblings, 1 reply; 27+ messages in thread
From: Simon Marchi @ 2022-01-10 16:39 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Andrew Burgess via Gdb-patches

On 2022-01-09 21:59, Joel Brobecker wrote:
>> Personally, I would also prefer merging sooner than later, just because
>> once it's done I can stop worrying about it.  But I am also not in a
>> hurry.  What finally triggered me to do this was the review of
>> Andrew's patch, I don't know if that is urgent or not.
>>
>> Joel, I don't think that the problem is the time we leave to downstream
>> users who might be impacted, but how we reach them.  I like the idea of
>> the NEWS entry to give a heads up, because it might be the only way we
>> have to communicate with some downstream users.  Oh, and we could also
>> make it so GDB shows a warning at startup if it's built with Python 2,
>> saying that Python 2 support will be removed in the next version.  That
>> has maybe more chances of being seen.
>>
>> If drop support in GDB 12, we don't have a chance to warn users (unless
>> we add that warning to GDB 11.2...).  We could always send an email on
>> the mailing lists, but that probably doesn't have as much reach.
>>
>> So, if there is no particular rush, I am leaning towards aiming for GDB
>> 13.
> 
> If you do not mind, then, OK for me as well. But just in the spirit of
> exploring all our options: What about adding a warning in the 11.2 NEWS?
> We create a PR, add news entry, and the change is in both the NEWS and
> the announcement I'm sending to everyone. We can also add a dedicated
> NEWS entry on GDB's web page.

Even though it would be possible to add the deprecation notice in 11.2,
I don't think we should.  I see Python 2 getting the "will be removed in
next release" a bit like a new feature, and we should not introduce it
in a bugfix release.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-10 16:39         ` Simon Marchi
@ 2022-01-11  3:26           ` Joel Brobecker
  0 siblings, 0 replies; 27+ messages in thread
From: Joel Brobecker @ 2022-01-11  3:26 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Joel Brobecker, Andrew Burgess via Gdb-patches

> Even though it would be possible to add the deprecation notice in 11.2,
> I don't think we should.  I see Python 2 getting the "will be removed in
> next release" a bit like a new feature, and we should not introduce it
> in a bugfix release.

OK, that makes sense as well, so no problem. OK for me to wait for GDB 13.

-- 
Joel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
                   ` (3 preceding siblings ...)
  2022-01-07 17:44 ` Andrew Burgess
@ 2022-03-03 16:31 ` Andrew Burgess
  2022-03-03 17:40   ` Simon Marchi
  2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
  5 siblings, 1 reply; 27+ messages in thread
From: Andrew Burgess @ 2022-03-03 16:31 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> 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.

I think the conclusion of this thread was to drop Python 2 support after
GDB 12 was branched.

Should we add NEWS entry that Py2 support is going away?

Below is a straw man patch.  I suspect the wording is probably not the
best, but this is a starting point.

Thanks,
Andrew

---

diff --git a/gdb/NEWS b/gdb/NEWS
index 1e53a55c259..6cde4a4abb2 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
 
 *** Changes since GDB 11
 
+* GDB 12 is the last release of GDB that will support building against
+  Python 2.  For GDB 13, it will only be possible to build GDB itself
+  with Python 3 support.
+
 * Improved C++ template support
 
   GDB now treats functions/types involving C++ templates like it does function


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] gdb/python: remove Python 2 support
  2022-03-03 16:31 ` Andrew Burgess
@ 2022-03-03 17:40   ` Simon Marchi
  0 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-03 17:40 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-03-03 11:31, Andrew Burgess wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> 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.
> 
> I think the conclusion of this thread was to drop Python 2 support after
> GDB 12 was branched.
> 
> Should we add NEWS entry that Py2 support is going away?
> 
> Below is a straw man patch.  I suspect the wording is probably not the
> best, but this is a starting point.
> 
> Thanks,
> Andrew
> 
> ---
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 1e53a55c259..6cde4a4abb2 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,10 @@
>  
>  *** Changes since GDB 11
>  
> +* GDB 12 is the last release of GDB that will support building against
> +  Python 2.  For GDB 13, it will only be possible to build GDB itself
> +  with Python 3 support.
> +
>  * Improved C++ template support
>  
>    GDB now treats functions/types involving C++ templates like it does function
> 

I think that's a good idea, LGTM.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v2 0/2] Remove Python 2 support
  2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
                   ` (4 preceding siblings ...)
  2022-03-03 16:31 ` Andrew Burgess
@ 2022-03-21 14:46 ` Simon Marchi
  2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
                     ` (2 more replies)
  5 siblings, 3 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 14:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

New version of this:

  https://sourceware.org/pipermail/gdb-patches/2022-January/184910.html

Now that the GDB 12 branch has been created, I think we can merge
this.  Patch 3 ("gdb/python: drop support for Python < 3.4") was
dropped.

Simon Marchi (2):
  gdb/python: remove Python 2 support
  gdb/python: remove Python 2/3 compatibility macros

 gdb/NEWS                                      |  3 +
 gdb/config.in                                 |  3 -
 gdb/configure                                 | 78 +-----------------
 gdb/configure.ac                              | 18 ++---
 gdb/doc/python.texi                           |  3 +-
 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                          | 17 ++--
 gdb/python/py-breakpoint.c                    | 12 +--
 gdb/python/py-cmd.c                           | 10 +--
 gdb/python/py-connection.c                    | 10 +--
 gdb/python/py-evts.c                          |  6 --
 gdb/python/py-frame.c                         |  2 +-
 gdb/python/py-framefilter.c                   |  6 +-
 gdb/python/py-inferior.c                      |  6 +-
 gdb/python/py-infthread.c                     |  4 +-
 gdb/python/py-lazy-string.c                   |  2 +-
 gdb/python/py-membuf.c                        | 81 ++-----------------
 gdb/python/py-micmd.c                         |  8 +-
 gdb/python/py-objfile.c                       |  6 +-
 gdb/python/py-param.c                         | 24 ++----
 gdb/python/py-record-btrace.c                 | 25 ++----
 gdb/python/py-record-full.c                   |  4 +-
 gdb/python/py-record.c                        |  2 +-
 gdb/python/py-registers.c                     |  6 +-
 gdb/python/py-signalevent.c                   |  2 +-
 gdb/python/py-symbol.c                        |  6 +-
 gdb/python/py-symtab.c                        |  6 +-
 gdb/python/py-type.c                          | 25 ++----
 gdb/python/py-unwind.c                        |  6 +-
 gdb/python/py-utils.c                         | 55 ++-----------
 gdb/python/py-value.c                         | 66 ---------------
 gdb/python/py-xmethods.c                      |  6 +-
 gdb/python/python-internal.h                  | 32 --------
 gdb/python/python.c                           | 43 +++-------
 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 ---
 45 files changed, 153 insertions(+), 619 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
@ 2022-03-21 14:46   ` Simon Marchi
  2022-03-21 14:50     ` Simon Marchi
  2022-03-21 14:58     ` Eli Zaretskii
  2022-03-21 14:46   ` [PATCH v2 2/2] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
  2022-03-23 11:46   ` [PATCH v2 0/2] Remove Python 2 support Simon Marchi
  2 siblings, 2 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 14:46 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

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.
 - NEWS entry.

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/config.in                                 |  3 -
 gdb/configure                                 | 78 +------------------
 gdb/configure.ac                              | 18 ++---
 gdb/doc/python.texi                           |  3 +-
 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(+), 504 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 4308e170e41..32d7ae0dd1f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 12
 
+* Remove support for building against Python 2, it is now only possible to
+* build GDB against Python 3.
+
 *** Changes in GDB 12
 
 * DBX mode is deprecated, and will be removed in GDB 13
diff --git a/gdb/config.in b/gdb/config.in
index cd9f252eba1..0146bc38cff 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -370,9 +370,6 @@
 /* Define if sys/ptrace.h defines the PT_GETDBREGS request. */
 #undef HAVE_PT_GETDBREGS
 
-/* Define if sys/ptrace.h defines the PT_GETXMMREGS request. */
-#undef HAVE_PT_GETXMMREGS
-
 /* Define to 1 if you have the `pt_insn_event' function. */
 #undef HAVE_PT_INSN_EVENT
 
diff --git a/gdb/configure b/gdb/configure
index b34baff13be..7ae8a2a3f3f 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11262,81 +11262,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;
 }
@@ -11354,7 +11285,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 bc8925ddd69..310c76557ae 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -717,7 +717,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
@@ -733,7 +738,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 -
@@ -742,7 +746,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 -
@@ -877,15 +880,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 918418b08c9..a401615e898 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -18,8 +18,7 @@
 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.
+@value{GDBN} can be built against Python 3.
 
 @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 5f63bced320..a52f6b46413 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 ea49c38d7f0..c03bef34182 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 f8ce9ead7c2..7cb6e8f3402 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 93d61f127dc..e208e889caa 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 4c3a52206fa..c69ea9992a3 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 0f273b344e4..e87881a8fd3 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 457825c9863..23a5d75ae21 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 e6eb1ec8cdf..0170fe61e7b 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 74cc0fb46bd..348dfa3f4b4 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<gdb_byte> 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 00f917edb30..6be771c2c4e 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 2a0e89ddcfa..bee17e0e3cc 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 7be3f3276c2..8838884592e 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 838853c896c..e7b147c92d3 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<char> 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 b546344da95..e779f491b5b 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 098d9130bf5..e3a3fc4d097 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -87,11 +87,6 @@
 #include <frameobject.h>
 #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 91636ef0225..e97bca7b5f3 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<char> 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 aa78a1540cf..552f9b17f4d 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 dfc2ebdf0e4..035478f6dc7 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 8204577b866..e9fdd06154e 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))" "<read-only buffer for $hex,.*>"
-    } else {
-	gdb_test "python print(repr(i.data))" "<memory at $hex>"
-    }
+    gdb_test "python print(repr(i.data))" "<memory at $hex>"
     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 4966688a922..a6adc8279cb 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 61c057ace92..2d3390284fe 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 60039c9373f..5d77b0ccc3c 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"
 }
@@ -92,7 +78,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
@@ -144,9 +129,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"
@@ -156,17 +138,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.
 
@@ -242,7 +218,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"
@@ -253,9 +228,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
 
@@ -533,13 +505,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"
 }
@@ -565,7 +532,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 729bded2950..c192130c010 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2360,8 +2360,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" {
@@ -2371,16 +2369,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.35.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v2 2/2] gdb/python: remove Python 2/3 compatibility macros
  2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
  2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
@ 2022-03-21 14:46   ` Simon Marchi
  2022-03-23 11:46   ` [PATCH v2 0/2] Remove Python 2 support Simon Marchi
  2 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 14:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

New in this version:

 - Rebase on master, fix a few more issues that appeared.

python-internal.h contains a number of macros that helped make the code
work with both Python 2 and 3.  Remove them and adjust the code to use
the Python 3 functions.

Change-Id: I99a3d80067fb2d65de4f69f6473ba6ffd16efb2d
---
 gdb/python/py-arch.c          | 11 +++++------
 gdb/python/py-breakpoint.c    | 12 ++++++------
 gdb/python/py-cmd.c           | 10 +++++-----
 gdb/python/py-connection.c    | 10 +++++-----
 gdb/python/py-frame.c         |  2 +-
 gdb/python/py-inferior.c      |  6 +++---
 gdb/python/py-infthread.c     |  4 ++--
 gdb/python/py-lazy-string.c   |  2 +-
 gdb/python/py-membuf.c        |  8 ++++----
 gdb/python/py-micmd.c         |  8 ++++----
 gdb/python/py-objfile.c       |  6 +++---
 gdb/python/py-param.c         | 16 ++++++++--------
 gdb/python/py-record-btrace.c |  8 ++++----
 gdb/python/py-record-full.c   |  4 ++--
 gdb/python/py-record.c        |  2 +-
 gdb/python/py-registers.c     |  6 +++---
 gdb/python/py-signalevent.c   |  2 +-
 gdb/python/py-symbol.c        |  6 +++---
 gdb/python/py-symtab.c        |  6 +++---
 gdb/python/py-type.c          | 12 ++++++------
 gdb/python/py-unwind.c        |  6 +++---
 gdb/python/py-utils.c         |  8 ++++----
 gdb/python/py-xmethods.c      |  6 +++---
 gdb/python/python-internal.h  | 22 ----------------------
 gdb/python/python.c           | 24 ++++++++++++------------
 25 files changed, 92 insertions(+), 115 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index e87881a8fd3..da6af875573 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -100,7 +100,7 @@ archpy_name (PyObject *self, PyObject *args)
   ARCHPY_REQUIRE_VALID (self, gdbarch);
 
   name = (gdbarch_bfd_arch_info (gdbarch))->printable_name;
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implementation of
@@ -158,7 +158,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
     }
   if (count_obj)
     {
-      count = PyInt_AsLong (count_obj);
+      count = PyLong_AsLong (count_obj);
       if (PyErr_Occurred () || count < 0)
 	{
 	  PyErr_SetString (PyExc_TypeError,
@@ -207,9 +207,8 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
       if (pc_obj == nullptr)
 	return nullptr;
 
-      gdbpy_ref<> asm_obj (PyString_FromString (!stb.empty ()
-						? stb.c_str ()
-						: "<unknown>"));
+      gdbpy_ref<> asm_obj
+	(PyUnicode_FromString (!stb.empty () ? stb.c_str () : "<unknown>"));
       if (asm_obj == nullptr)
 	return nullptr;
 
@@ -332,7 +331,7 @@ gdbpy_all_architecture_names (PyObject *self, PyObject *args)
   std::vector<const char *> name_list = gdbarch_printable_names ();
   for (const char *name : name_list)
     {
-      gdbpy_ref <> py_name (PyString_FromString (name));
+      gdbpy_ref <> py_name (PyUnicode_FromString (name));
       if (py_name == nullptr)
 	return nullptr;
       if (PyList_Append (list.get (), py_name.get ()) < 0)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 2fc20376af8..5891c3a9735 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -224,7 +224,7 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `thread' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -266,7 +266,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `task' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -341,7 +341,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `ignore_count' attribute."));
       return -1;
     }
-  else if (! PyInt_Check (newvalue))
+  else if (!PyLong_Check (newvalue))
     {
       PyErr_SetString (PyExc_TypeError,
 		       _("The value of `ignore_count' must be an integer."));
@@ -780,9 +780,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
   if (lineobj != NULL)
     {
-      if (PyInt_Check (lineobj))
-	line = xstrprintf ("%ld", PyInt_AsLong (lineobj));
-      else if (PyString_Check (lineobj))
+      if (PyLong_Check (lineobj))
+	line = xstrprintf ("%ld", PyLong_AsLong (lineobj));
+      else if (PyUnicode_Check (lineobj))
 	line = python_string_to_host_string (lineobj);
       else
 	{
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index b51b05c95ad..c0a98544619 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -233,7 +233,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  We are only
@@ -277,7 +277,7 @@ cmdpy_completer (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  */
@@ -592,10 +592,10 @@ gdbpy_initialize_commands (void)
 			      (PyObject *) &cmdpy_object_type) < 0)
     return -1;
 
-  invoke_cst = PyString_FromString ("invoke");
+  invoke_cst = PyUnicode_FromString ("invoke");
   if (invoke_cst == NULL)
     return -1;
-  complete_cst = PyString_FromString ("complete");
+  complete_cst = PyUnicode_FromString ("complete");
   if (complete_cst == NULL)
     return -1;
 
@@ -684,7 +684,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
 
       for (char *arg : c_argv)
 	{
-	  gdbpy_ref<> argp (PyString_FromString (arg));
+	  gdbpy_ref<> argp (PyUnicode_FromString (arg));
 
 	  if (argp == NULL
 	      || PyList_Append (py_argv.get (), argp.get ()) < 0)
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index 4cdd6abbf3d..84660414dd0 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -204,12 +204,12 @@ connpy_repr (PyObject *obj)
   process_stratum_target *target = self->target;
 
   if (target == nullptr)
-    return PyString_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
+    return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
 
-  return PyString_FromFormat ("<%s num=%d, what=\"%s\">",
-			      Py_TYPE (obj)->tp_name,
-			      target->connection_number,
-			      make_target_connection_string (target).c_str ());
+  return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">",
+			       Py_TYPE (obj)->tp_name,
+			       target->connection_number,
+			       make_target_connection_string (target).c_str ());
 }
 
 /* Implementation of gdb.TargetConnection.is_valid() -> Boolean.  Returns
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 0cab8e15946..bf9eba89c5f 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -80,7 +80,7 @@ static PyObject *
 frapy_str (PyObject *self)
 {
   const frame_id &fid = ((frame_object *) self)->frame_id;
-  return PyString_FromString (fid.to_string ().c_str ());
+  return PyUnicode_FromString (fid.to_string ().c_str ());
 }
 
 /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 46f0c9ffd04..ebcd5b0a70f 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -753,10 +753,10 @@ infpy_repr (PyObject *obj)
   inferior *inf = self->inferior;
 
   if (inf == nullptr)
-    return PyString_FromString ("<gdb.Inferior (invalid)>");
+    return PyUnicode_FromString ("<gdb.Inferior (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
-			      inf->num, inf->pid);
+  return PyUnicode_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
+			       inf->num, inf->pid);
 }
 
 
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index c94d5b0ddab..34f60526ac9 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -73,7 +73,7 @@ thpy_get_name (PyObject *self, void *ignore)
   if (name == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Return a string containing target specific additional information about
@@ -101,7 +101,7 @@ thpy_get_details (PyObject *self, void *ignore)
   if (extra_info == nullptr)
     Py_RETURN_NONE;
 
-  return PyString_FromString (extra_info);
+  return PyUnicode_FromString (extra_info);
 }
 
 static int
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 69b1bc52ab9..c49987e2530 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -73,7 +73,7 @@ stpy_get_encoding (PyObject *self, void *closure)
   /* An encoding can be set to NULL by the user, so check before
      attempting a Python FromString call.  If NULL return Py_None.  */
   if (self_string->encoding)
-    result = PyString_FromString (self_string->encoding);
+    result = PyUnicode_FromString (self_string->encoding);
   else
     {
       result = Py_None;
diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
index 348dfa3f4b4..d2a059a0e34 100644
--- a/gdb/python/py-membuf.c
+++ b/gdb/python/py-membuf.c
@@ -73,11 +73,11 @@ mbpy_str (PyObject *self)
 {
   membuf_object *membuf_obj = (membuf_object *) self;
 
-  return PyString_FromFormat (_("Memory buffer for address %s, \
+  return PyUnicode_FromFormat (_("Memory buffer for address %s, \
 which is %s bytes long."),
-			      paddress (gdbpy_enter::get_gdbarch (),
-					membuf_obj->addr),
-			      pulongest (membuf_obj->length));
+			       paddress (gdbpy_enter::get_gdbarch (),
+					 membuf_obj->addr),
+			       pulongest (membuf_obj->length));
 }
 
 static int
diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c
index a194798eaec..a0c3071ebf8 100644
--- a/gdb/python/py-micmd.c
+++ b/gdb/python/py-micmd.c
@@ -185,7 +185,7 @@ static gdb::unique_xmalloc_ptr<char>
 py_object_to_mi_key (PyObject *key_obj)
 {
   /* The key must be a string.  */
-  if (!PyString_Check (key_obj))
+  if (!PyUnicode_Check (key_obj))
     {
       gdbpy_ref<> key_repr (PyObject_Repr (key_obj));
       gdb::unique_xmalloc_ptr<char> key_repr_string;
@@ -261,7 +261,7 @@ serialize_mi_result_1 (PyObject *result, const char *field_name)
 	  serialize_mi_result_1 (value, key_string.get ());
 	}
     }
-  else if (PySequence_Check (result) && !PyString_Check (result))
+  else if (PySequence_Check (result) && !PyUnicode_Check (result))
     {
       ui_out_emit_list list_emitter (uiout, field_name);
       Py_ssize_t len = PySequence_Size (result);
@@ -607,7 +607,7 @@ gdbpy_initialize_micommands ()
       < 0)
     return -1;
 
-  invoke_cst = PyString_FromString ("invoke");
+  invoke_cst = PyUnicode_FromString ("invoke");
   if (invoke_cst == nullptr)
     return -1;
 
@@ -636,7 +636,7 @@ micmdpy_get_name (PyObject *self, void *closure)
 
   gdb_assert (micmd_obj->mi_command_name != nullptr);
   std::string name_str = string_printf ("-%s", micmd_obj->mi_command_name);
-  return PyString_FromString (name_str.c_str ());
+  return PyUnicode_FromString (name_str.c_str ());
 }
 
 /* Get the gdb.MICommand.installed property.  Returns true if this MI
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 8c568799843..3e3270e7cd3 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -510,10 +510,10 @@ objfpy_repr (PyObject *self_)
   objfile *obj = self->objfile;
 
   if (obj == nullptr)
-    return PyString_FromString ("<gdb.Objfile (invalid)>");
+    return PyUnicode_FromString ("<gdb.Objfile (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Objfile filename=%s>",
-			      objfile_name (obj));
+  return PyUnicode_FromFormat ("<gdb.Objfile filename=%s>",
+			       objfile_name (obj));
 }
 
 /* Subroutine of gdbpy_lookup_objfile_by_build_id to simplify it.
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 6be771c2c4e..d0dd2a97648 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -125,7 +125,7 @@ static PyObject *show_doc_cst;
 static PyObject *
 get_attr (PyObject *obj, PyObject *attr_name)
 {
-  if (PyString_Check (attr_name)
+  if (PyUnicode_Check (attr_name)
       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
     {
       parmpy_object *self = (parmpy_object *) obj;
@@ -243,7 +243,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	long l;
 	int ok;
 
-	if (! PyInt_Check (value))
+	if (!PyLong_Check (value))
 	  {
 	    PyErr_SetString (PyExc_RuntimeError,
 			     _("The value must be integer."));
@@ -308,7 +308,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 static int
 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
 {
-  if (PyString_Check (attr_name)
+  if (PyUnicode_Check (attr_name)
       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
     {
       if (!val)
@@ -447,7 +447,7 @@ get_set_value (const char *args, int from_tty,
   gdb::unique_xmalloc_ptr<char> set_doc_string;
 
   gdbpy_enter enter_py;
-  gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
+  gdbpy_ref<> set_doc_func (PyUnicode_FromString ("get_set_string"));
 
   if (set_doc_func == NULL)
     {
@@ -482,7 +482,7 @@ get_show_value (struct ui_file *file, int from_tty,
   gdb::unique_xmalloc_ptr<char> show_doc_string;
 
   gdbpy_enter enter_py;
-  gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
+  gdbpy_ref<> show_doc_func (PyUnicode_FromString ("get_show_string"));
 
   if (show_doc_func == NULL)
     {
@@ -492,7 +492,7 @@ get_show_value (struct ui_file *file, int from_tty,
 
   if (PyObject_HasAttr (obj, show_doc_func.get ()))
     {
-      gdbpy_ref<> val_obj (PyString_FromString (value));
+      gdbpy_ref<> val_obj (PyUnicode_FromString (value));
 
       if (val_obj == NULL)
 	{
@@ -835,10 +835,10 @@ gdbpy_initialize_parameters (void)
   if (PyType_Ready (&parmpy_object_type) < 0)
     return -1;
 
-  set_doc_cst = PyString_FromString ("set_doc");
+  set_doc_cst = PyUnicode_FromString ("set_doc");
   if (! set_doc_cst)
     return -1;
-  show_doc_cst = PyString_FromString ("show_doc");
+  show_doc_cst = PyUnicode_FromString ("show_doc");
   if (! show_doc_cst)
     return -1;
 
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index bee17e0e3cc..85401010f0a 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -471,9 +471,9 @@ btpy_list_slice (PyObject *self, PyObject *value)
   const Py_ssize_t length = btpy_list_length (self);
   Py_ssize_t start, stop, step, slicelength;
 
-  if (PyInt_Check (value))
+  if (PyLong_Check (value))
     {
-      Py_ssize_t index = PyInt_AsSsize_t (value);
+      Py_ssize_t index = PyLong_AsSsize_t (value);
 
       /* Emulate Python behavior for negative indices.  */
       if (index < 0)
@@ -607,7 +607,7 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
 PyObject *
 recpy_bt_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("btrace");
+  return PyUnicode_FromString ("btrace");
 }
 
 /* Implementation of
@@ -628,7 +628,7 @@ recpy_bt_format (PyObject *self, void *closure)
   if (config == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (btrace_format_short_string (config->format));
+  return PyUnicode_FromString (btrace_format_short_string (config->format));
 }
 
 /* Implementation of
diff --git a/gdb/python/py-record-full.c b/gdb/python/py-record-full.c
index 1caec735c49..ecae08bfc95 100644
--- a/gdb/python/py-record-full.c
+++ b/gdb/python/py-record-full.c
@@ -26,7 +26,7 @@
 PyObject *
 recpy_full_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
 
 /* Implementation of
@@ -35,5 +35,5 @@ recpy_full_method (PyObject *self, void *closure)
 PyObject *
 recpy_full_format (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index a4ab2936b01..51084dfac72 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -474,7 +474,7 @@ recpy_gap_reason_string (PyObject *self, void *closure)
 {
   const recpy_gap_object * const obj = (const recpy_gap_object *) self;
 
-  return PyString_FromString (obj->reason_string);
+  return PyUnicode_FromString (obj->reason_string);
 }
 
 /* Record method list.  */
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index b3f784e7fc5..eab88a30b3b 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -138,7 +138,7 @@ gdbpy_reggroup_to_string (PyObject *self)
   struct reggroup *reggroup = group->reggroup;
 
   const char *name = reggroup_name (reggroup);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterGroup.name (self) -> String.
@@ -196,7 +196,7 @@ gdbpy_register_descriptor_to_string (PyObject *self)
   int regnum = reg->regnum;
 
   const char *name = gdbarch_register_name (gdbarch, regnum);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterDescriptor.name attribute get function.  Return a
@@ -391,7 +391,7 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
 	}
     }
   /* The register could be its internal GDB register number.  */
-  else if (PyInt_Check (pyo_reg_id))
+  else if (PyLong_Check (pyo_reg_id))
     {
       long value;
       if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index e349f6107b2..69eeebbfaaa 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -31,7 +31,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
 
   const char *signal_name = gdb_signal_to_name (stop_signal);
 
-  gdbpy_ref<> signal_name_obj (PyString_FromString (signal_name));
+  gdbpy_ref<> signal_name_obj (PyUnicode_FromString (signal_name));
   if (signal_name_obj == NULL)
     return NULL;
   if (evpy_add_attribute (signal_event_obj.get (),
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 819a51f7e41..12c97bf63bb 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -60,7 +60,7 @@ sympy_str (PyObject *self)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  result = PyString_FromString (symbol->print_name ());
+  result = PyUnicode_FromString (symbol->print_name ());
 
   return result;
 }
@@ -101,7 +101,7 @@ sympy_get_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->natural_name ());
+  return PyUnicode_FromString (symbol->natural_name ());
 }
 
 static PyObject *
@@ -111,7 +111,7 @@ sympy_get_linkage_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->linkage_name ());
+  return PyUnicode_FromString (symbol->linkage_name ());
 }
 
 static PyObject *
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index cb28264a03f..bfda599dddd 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -93,7 +93,7 @@ stpy_str (PyObject *self)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  result = PyString_FromString (symtab_to_filename_for_display (symtab));
+  result = PyUnicode_FromString (symtab_to_filename_for_display (symtab));
 
   return result;
 }
@@ -234,8 +234,8 @@ salpy_str (PyObject *self)
       filename = symtab_to_filename_for_display (symtab);
     }
 
-  return PyString_FromFormat ("symbol and line for %s, line %d", filename,
-			      sal->line);
+  return PyUnicode_FromFormat ("symbol and line for %s, line %d", filename,
+			       sal->line);
 }
 
 static void
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 8838884592e..5352ead84bd 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -209,7 +209,7 @@ convert_field (struct type *type, int field)
 
       if (field_name[0] != '\0')
 	{
-	  arg.reset (PyString_FromString (type->field (field).name ()));
+	  arg.reset (PyUnicode_FromString (type->field (field).name ()));
 	  if (arg == NULL)
 	    return NULL;
 	}
@@ -261,7 +261,7 @@ field_name (struct type *type, int field)
   gdbpy_ref<> result;
 
   if (type->field (field).name ())
-    result.reset (PyString_FromString (type->field (field).name ()));
+    result.reset (PyUnicode_FromString (type->field (field).name ()));
   else
     result = gdbpy_ref<>::new_reference (Py_None);
 
@@ -399,9 +399,9 @@ typy_get_name (PyObject *self, void *closure)
     {
       std::string name = ada_decode (type->name (), false);
       if (!name.empty ())
-	return PyString_FromString (name.c_str ());
+	return PyUnicode_FromString (name.c_str ());
     }
-  return PyString_FromString (type->name ());
+  return PyUnicode_FromString (type->name ());
 }
 
 /* Return the type's tag, or None.  */
@@ -418,7 +418,7 @@ typy_get_tag (PyObject *self, void *closure)
 
   if (tagname == nullptr)
     Py_RETURN_NONE;
-  return PyString_FromString (tagname);
+  return PyUnicode_FromString (tagname);
 }
 
 /* Return the type's objfile, or None.  */
@@ -539,7 +539,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 
   if (n2_obj)
     {
-      if (!PyInt_Check (n2_obj))
+      if (!PyLong_Check (n2_obj))
 	{
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("Array bound must be an integer"));
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 36f42cbcac3..dd43901be21 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -213,7 +213,7 @@ unwind_infopy_str (PyObject *self)
     stb.puts (")");
   }
 
-  return PyString_FromString (stb.c_str ());
+  return PyUnicode_FromString (stb.c_str ());
 }
 
 /* Create UnwindInfo instance for given PendingFrame and frame ID.
@@ -349,7 +349,7 @@ pending_framepy_str (PyObject *self)
   const char *pc_str = NULL;
 
   if (frame == NULL)
-    return PyString_FromString ("Stale PendingFrame instance");
+    return PyUnicode_FromString ("Stale PendingFrame instance");
   try
     {
       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
@@ -360,7 +360,7 @@ pending_framepy_str (PyObject *self)
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
+  return PyUnicode_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
 }
 
 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index e7b147c92d3..72b7eaa2390 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -152,8 +152,8 @@ python_string_to_host_string (PyObject *obj)
 gdbpy_ref<>
 host_string_to_python_string (const char *str)
 {
-  return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (),
-				       NULL));
+  return gdbpy_ref<> (PyUnicode_Decode (str, strlen (str), host_charset (),
+					NULL));
 }
 
 /* Return true if OBJ is a Python string or unicode object, false
@@ -294,13 +294,13 @@ gdb_py_object_from_ulongest (ULONGEST l)
   return gdbpy_ref<> (PyLong_FromUnsignedLong (l));
 }
 
-/* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts
+/* Like PyLong_AsLong, but returns 0 on failure, 1 on success, and puts
    the value into an out parameter.  */
 
 int
 gdb_py_int_as_long (PyObject *obj, long *result)
 {
-  *result = PyInt_AsLong (obj);
+  *result = PyLong_AsLong (obj);
   return ! (*result == -1 && PyErr_Occurred ());
 }
 
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index 9d5824962b1..1467e52a960 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -103,7 +103,7 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
   if (match_method == NULL)
     return NULL;
 
-  gdbpy_ref<> py_xmethod_name (PyString_FromString (xmethod_name));
+  gdbpy_ref<> py_xmethod_name (PyUnicode_FromString (xmethod_name));
   if (py_xmethod_name == NULL)
     return NULL;
 
@@ -601,12 +601,12 @@ python_xmethod_worker::python_xmethod_worker (PyObject *py_worker,
 int
 gdbpy_initialize_xmethods (void)
 {
-  py_match_method_name = PyString_FromString (match_method_name);
+  py_match_method_name = PyUnicode_FromString (match_method_name);
   if (py_match_method_name == NULL)
     return -1;
 
   py_get_arg_types_method_name
-    = PyString_FromString (get_arg_types_method_name);
+    = PyUnicode_FromString (get_arg_types_method_name);
   if (py_get_arg_types_method_name == NULL)
     return -1;
 
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index e3a3fc4d097..4edefe9c88c 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -89,15 +89,6 @@
 
 #define Py_TPFLAGS_CHECKTYPES 0
 
-#define PyInt_Check PyLong_Check
-#define PyInt_AsLong PyLong_AsLong
-#define PyInt_AsSsize_t PyLong_AsSsize_t
-
-#define PyString_FromString PyUnicode_FromString
-#define PyString_Decode PyUnicode_Decode
-#define PyString_FromFormat PyUnicode_FromFormat
-#define PyString_Check PyUnicode_Check
-
 /* If Python.h does not define WITH_THREAD, then the various
    GIL-related functions will not be defined.  However,
    PyGILState_STATE will be.  */
@@ -141,19 +132,6 @@ typedef long Py_hash_t;
 #define PyMem_RawMalloc PyMem_Malloc
 #endif
 
-/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
-   to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
-   Wrap it ourselves, so that callers don't need to care.  */
-
-static inline void
-gdb_Py_DECREF (void *op) /* ARI: editCase function */
-{
-  Py_DECREF (op);
-}
-
-#undef Py_DECREF
-#define Py_DECREF(op) gdb_Py_DECREF (op)
-
 /* PyObject_CallMethod's 'method' and 'format' parameters were missing
    the 'const' qualifier before Python 3.4.  Hence, we wrap the
    function in our own version to avoid errors with string literals.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index e97bca7b5f3..0b101af44aa 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -685,7 +685,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
     }
 
   if (to_string)
-    return PyString_FromString (to_string_res.c_str ());
+    return PyUnicode_FromString (to_string_res.c_str ());
   Py_RETURN_NONE;
 }
 
@@ -931,7 +931,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
 
   if (arg != NULL && strlen (arg) > 0)
     {
-      unparsed.reset (PyString_FromString (arg));
+      unparsed.reset (PyUnicode_FromString (arg));
       if (unparsed == NULL)
 	return NULL;
     }
@@ -1093,7 +1093,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
 
       if (PyCallable_Check (hook.get ()))
 	{
-	  gdbpy_ref<> current_prompt (PyString_FromString (current_gdb_prompt));
+	  gdbpy_ref<> current_prompt (PyUnicode_FromString (current_gdb_prompt));
 	  if (current_prompt == NULL)
 	    {
 	      gdbpy_print_stack ();
@@ -1112,7 +1112,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
 	  /* Return type should be None, or a String.  If it is None,
 	     fall through, we will not set a prompt.  If it is a
 	     string, set  PROMPT.  Anything else, set an exception.  */
-	  if (result != Py_None && ! PyString_Check (result.get ()))
+	  if (result != Py_None && !PyUnicode_Check (result.get ()))
 	    {
 	      PyErr_Format (PyExc_RuntimeError,
 			    _("Return from prompt_hook must " \
@@ -1171,7 +1171,7 @@ gdbpy_colorize (const std::string &filename, const std::string &contents)
   if (!PyCallable_Check (hook.get ()))
     return {};
 
-  gdbpy_ref<> fname_arg (PyString_FromString (filename.c_str ()));
+  gdbpy_ref<> fname_arg (PyUnicode_FromString (filename.c_str ()));
   if (fname_arg == nullptr)
     {
       gdbpy_print_stack ();
@@ -1980,22 +1980,22 @@ do_start_initialization ()
 #include "py-event-types.def"
 #undef GDB_PY_DEFINE_EVENT_TYPE
 
-  gdbpy_to_string_cst = PyString_FromString ("to_string");
+  gdbpy_to_string_cst = PyUnicode_FromString ("to_string");
   if (gdbpy_to_string_cst == NULL)
     return false;
-  gdbpy_children_cst = PyString_FromString ("children");
+  gdbpy_children_cst = PyUnicode_FromString ("children");
   if (gdbpy_children_cst == NULL)
     return false;
-  gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+  gdbpy_display_hint_cst = PyUnicode_FromString ("display_hint");
   if (gdbpy_display_hint_cst == NULL)
     return false;
-  gdbpy_doc_cst = PyString_FromString ("__doc__");
+  gdbpy_doc_cst = PyUnicode_FromString ("__doc__");
   if (gdbpy_doc_cst == NULL)
     return false;
-  gdbpy_enabled_cst = PyString_FromString ("enabled");
+  gdbpy_enabled_cst = PyUnicode_FromString ("enabled");
   if (gdbpy_enabled_cst == NULL)
     return false;
-  gdbpy_value_cst = PyString_FromString ("value");
+  gdbpy_value_cst = PyUnicode_FromString ("value");
   if (gdbpy_value_cst == NULL)
     return false;
 
@@ -2210,7 +2210,7 @@ do_initialize (const struct extension_language_defn *extlang)
     }
   if (sys_path && PyList_Check (sys_path))
     {
-      gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ()));
+      gdbpy_ref<> pythondir (PyUnicode_FromString (gdb_pythondir.c_str ()));
       if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
 	return false;
     }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
@ 2022-03-21 14:50     ` Simon Marchi
  2022-03-21 14:58     ` Eli Zaretskii
  1 sibling, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 14:50 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

> diff --git a/gdb/config.in b/gdb/config.in
> index cd9f252eba1..0146bc38cff 100644
> --- a/gdb/config.in
> +++ b/gdb/config.in
> @@ -370,9 +370,6 @@
>  /* Define if sys/ptrace.h defines the PT_GETDBREGS request. */
>  #undef HAVE_PT_GETDBREGS
>
> -/* Define if sys/ptrace.h defines the PT_GETXMMREGS request. */
> -#undef HAVE_PT_GETXMMREGS

This hunk does not belong here.  I just pushed a patch to re-generate
config.in, so it will disappear when rebasing.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
  2022-03-21 14:50     ` Simon Marchi
@ 2022-03-21 14:58     ` Eli Zaretskii
  2022-03-21 15:04       ` Simon Marchi
  1 sibling, 1 reply; 27+ messages in thread
From: Eli Zaretskii @ 2022-03-21 14:58 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

> Date: Mon, 21 Mar 2022 10:46:23 -0400
> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 4308e170e41..32d7ae0dd1f 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 12
>  
> +* Remove support for building against Python 2, it is now only possible to
> +* build GDB against Python 3.
> +
>  *** Changes in GDB 12

This part is OK.

> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 918418b08c9..a401615e898 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -18,8 +18,7 @@
>  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.
> +@value{GDBN} can be built against Python 3.

Here, I think we should say "only against Python 3", or say "Python 2
is not supported as of GDB 13", or something to that effect.  Because
it is otherwise strange to mention Python 3, it sounds "out of the
blue".

Thanks.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 14:58     ` Eli Zaretskii
@ 2022-03-21 15:04       ` Simon Marchi
  2022-03-21 15:33         ` Pedro Alves
  0 siblings, 1 reply; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 15:04 UTC (permalink / raw)
  To: Eli Zaretskii, Simon Marchi; +Cc: gdb-patches

On 2022-03-21 10:58, Eli Zaretskii via Gdb-patches wrote:
> Here, I think we should say "only against Python 3", or say "Python 2
> is not supported as of GDB 13", or something to that effect.  Because
> it is otherwise strange to mention Python 3, it sounds "out of the
> blue".

I'll say "can only be built against Python 3" then.  I'd rather not say
"GDB 13", since this text will live for many GDB versions.  Updated
locally.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 15:04       ` Simon Marchi
@ 2022-03-21 15:33         ` Pedro Alves
  2022-03-21 16:31           ` Simon Marchi
  0 siblings, 1 reply; 27+ messages in thread
From: Pedro Alves @ 2022-03-21 15:33 UTC (permalink / raw)
  To: Simon Marchi, Eli Zaretskii, Simon Marchi; +Cc: gdb-patches

On 2022-03-21 15:04, Simon Marchi wrote:
> On 2022-03-21 10:58, Eli Zaretskii via Gdb-patches wrote:
>> Here, I think we should say "only against Python 3", or say "Python 2
>> is not supported as of GDB 13", or something to that effect.  Because
>> it is otherwise strange to mention Python 3, it sounds "out of the
>> blue".
> 
> I'll say "can only be built against Python 3" then.  I'd rather not say
> "GDB 13", since this text will live for many GDB versions.  Updated
> locally.

We document in gdb/README the minimum supported version, so I think you
could drop the "Python 3" reference completely if you wanted.

Speaking of which, said gdb/README note should also be updated, as is documents
that the oldest supported version is 2.6:

`--with-python[=PYTHON]'
     Build GDB with Python scripting support.  (Done by default if
     libpython is present and found at configure time.)  Python makes
     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
     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.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 15:33         ` Pedro Alves
@ 2022-03-21 16:31           ` Simon Marchi
  2022-03-21 16:55             ` Pedro Alves
  0 siblings, 1 reply; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 16:31 UTC (permalink / raw)
  To: Pedro Alves, Eli Zaretskii, Simon Marchi; +Cc: gdb-patches

On 2022-03-21 11:33, Pedro Alves wrote:
> On 2022-03-21 15:04, Simon Marchi wrote:
>> On 2022-03-21 10:58, Eli Zaretskii via Gdb-patches wrote:
>>> Here, I think we should say "only against Python 3", or say "Python 2
>>> is not supported as of GDB 13", or something to that effect.  Because
>>> it is otherwise strange to mention Python 3, it sounds "out of the
>>> blue".
>>
>> I'll say "can only be built against Python 3" then.  I'd rather not say
>> "GDB 13", since this text will live for many GDB versions.  Updated
>> locally.
> 
> We document in gdb/README the minimum supported version, so I think you
> could drop the "Python 3" reference completely if you wanted.

Ok, I'll remove that sentence.

> 
> Speaking of which, said gdb/README note should also be updated, as is documents
> that the oldest supported version is 2.6:
> 
> `--with-python[=PYTHON]'
>      Build GDB with Python scripting support.  (Done by default if
>      libpython is present and found at configure time.)  Python makes
>      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
>      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.

Indeed, we should update it.  But we should probably be precise and which
3.x version we support exactly.  The question is what do we support? My
initial patch #3 removed support for below 3.4, so it must be below 3.4.

Using this PPA

https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

on Ubuntu 18.04, I tried Python 3.1 and above.  Python 3.1 didn't build
because of this:

  CXX    python/py-record-btrace.o
../../gdb/python/py-record-btrace.c: In function 'PyObject* btpy_list_slice(PyObject*, PyObject*)':
../../gdb/python/py-record-btrace.c:504:25: error: cannot convert 'PyObject* {aka _object*}' to 'PySliceObject*' for argument '1' to 'int PySlice_GetIndicesEx(PySliceObject*, Py_ssize_t, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*)'
      &step, &slicelength))
                         ^
... which is a "bug" in the Python 3.1 API, fixed in 3.2.  Python 3.2
built fine (although I didn't test further, other than starting GDB).

So I would replace "2.6" with "3.2" in there.  Sounds good?

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 16:31           ` Simon Marchi
@ 2022-03-21 16:55             ` Pedro Alves
  2022-03-21 17:04               ` Simon Marchi
  0 siblings, 1 reply; 27+ messages in thread
From: Pedro Alves @ 2022-03-21 16:55 UTC (permalink / raw)
  To: Simon Marchi, Eli Zaretskii, Simon Marchi; +Cc: gdb-patches

On 2022-03-21 16:31, Simon Marchi wrote:
> On 2022-03-21 11:33, Pedro Alves wrote:

> 
> Using this PPA
> 
> https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
> 
> on Ubuntu 18.04, I tried Python 3.1 and above.  Python 3.1 didn't build
> because of this:
> 
>   CXX    python/py-record-btrace.o
> ../../gdb/python/py-record-btrace.c: In function 'PyObject* btpy_list_slice(PyObject*, PyObject*)':
> ../../gdb/python/py-record-btrace.c:504:25: error: cannot convert 'PyObject* {aka _object*}' to 'PySliceObject*' for argument '1' to 'int PySlice_GetIndicesEx(PySliceObject*, Py_ssize_t, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*)'
>       &step, &slicelength))
>                          ^
> ... which is a "bug" in the Python 3.1 API, fixed in 3.2.  Python 3.2
> built fine (although I didn't test further, other than starting GDB).
> 
> So I would replace "2.6" with "3.2" in there.  Sounds good?

Sounds good to me.  

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 1/2] gdb/python: remove Python 2 support
  2022-03-21 16:55             ` Pedro Alves
@ 2022-03-21 17:04               ` Simon Marchi
  0 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-21 17:04 UTC (permalink / raw)
  To: Pedro Alves, Eli Zaretskii, Simon Marchi; +Cc: gdb-patches

On 2022-03-21 12:55, Pedro Alves wrote:
> On 2022-03-21 16:31, Simon Marchi wrote:
>> On 2022-03-21 11:33, Pedro Alves wrote:
> 
>>
>> Using this PPA
>>
>> https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
>>
>> on Ubuntu 18.04, I tried Python 3.1 and above.  Python 3.1 didn't build
>> because of this:
>>
>>   CXX    python/py-record-btrace.o
>> ../../gdb/python/py-record-btrace.c: In function 'PyObject* btpy_list_slice(PyObject*, PyObject*)':
>> ../../gdb/python/py-record-btrace.c:504:25: error: cannot convert 'PyObject* {aka _object*}' to 'PySliceObject*' for argument '1' to 'int PySlice_GetIndicesEx(PySliceObject*, Py_ssize_t, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*, Py_ssize_t*)'
>>       &step, &slicelength))
>>                          ^
>> ... which is a "bug" in the Python 3.1 API, fixed in 3.2.  Python 3.2
>> built fine (although I didn't test further, other than starting GDB).
>>
>> So I would replace "2.6" with "3.2" in there.  Sounds good?
> 
> Sounds good to me.  

Ok, updated locally.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2 0/2] Remove Python 2 support
  2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
  2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
  2022-03-21 14:46   ` [PATCH v2 2/2] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
@ 2022-03-23 11:46   ` Simon Marchi
  2 siblings, 0 replies; 27+ messages in thread
From: Simon Marchi @ 2022-03-23 11:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches



On 2022-03-21 10:46, Simon Marchi via Gdb-patches wrote:
> New version of this:
> 
>   https://sourceware.org/pipermail/gdb-patches/2022-January/184910.html
> 
> Now that the GDB 12 branch has been created, I think we can merge
> this.  Patch 3 ("gdb/python: drop support for Python < 3.4") was
> dropped.
I pushed these patches, including the small tweaks discussed in this thread.

Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2022-03-23 11:46 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
2022-01-07 15:29 ` [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
2022-01-07 15:29 ` [PATCH 3/3] gdb/python: drop support for Python < 3.4 Simon Marchi
2022-01-07 16:33   ` Eli Zaretskii
2022-01-07 17:14     ` Simon Marchi
2022-01-07 15:33 ` [PATCH 1/3] gdb/python: remove Python 2 support Paul Koning
2022-01-07 15:41   ` Simon Marchi
2022-01-07 17:44 ` Andrew Burgess
2022-01-08  8:18   ` Joel Brobecker
2022-01-10  2:28     ` Simon Marchi
2022-01-10  2:59       ` Joel Brobecker
2022-01-10 16:39         ` Simon Marchi
2022-01-11  3:26           ` Joel Brobecker
2022-01-10 16:26       ` Tom Tromey
2022-03-03 16:31 ` Andrew Burgess
2022-03-03 17:40   ` Simon Marchi
2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
2022-03-21 14:50     ` Simon Marchi
2022-03-21 14:58     ` Eli Zaretskii
2022-03-21 15:04       ` Simon Marchi
2022-03-21 15:33         ` Pedro Alves
2022-03-21 16:31           ` Simon Marchi
2022-03-21 16:55             ` Pedro Alves
2022-03-21 17:04               ` Simon Marchi
2022-03-21 14:46   ` [PATCH v2 2/2] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
2022-03-23 11:46   ` [PATCH v2 0/2] Remove Python 2 support Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).