aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/lib
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-12-23 20:20:46 -0500
committerSimon Marchi <simon.marchi@efficios.com>2022-03-23 07:41:19 -0400
commitedae3fd6600f10f9e16dc017b705959f541ed19a (patch)
tree0e8b6288c02dec48f369594a9032dcac20146e33 /gdb/python/lib
parente52a16f2aa20773f42c28bf91a568d0683e5767c (diff)
downloadbinutils-edae3fd6600f10f9e16dc017b705959f541ed19a.zip
binutils-edae3fd6600f10f9e16dc017b705959f541ed19a.tar.gz
binutils-edae3fd6600f10f9e16dc017b705959f541ed19a.tar.bz2
gdb/python: remove Python 2 support
New in this version: - Add a PY_MAJOR_VERSION check in configure.ac / AC_TRY_LIBPYTHON. If the user passes --with-python=python2, this will cause a configure failure saying that GDB only supports Python 3. Support for Python 2 is a maintenance burden for any patches touching Python support. Among others, the differences between Python 2 and 3 string and integer types are subtle. It requires a lot of effort and thinking to get something that behaves correctly on both. And that's if the author and reviewer of the patch even remember to test with Python 2. See this thread for an example: https://sourceware.org/pipermail/gdb-patches/2021-December/184260.html So, remove Python 2 support. Update the documentation to state that GDB can be built against Python 3 (as opposed to Python 2 or 3). Update all the spots that use: - sys.version_info - IS_PY3K - PY_MAJOR_VERSION - gdb_py_is_py3k ... to only keep the Python 3 portions and drop the use of some now-removed compatibility macros. I did not update the configure script more than just removing the explicit references to Python 2. We could maybe do more there, like check the Python version and reject it if that version is not supported. Otherwise (with this patch), things will only fail at compile time, so it won't really be clear to the user that they are trying to use an unsupported Python version. But I'm a bit lost in the configure code that checks for Python, so I kept that for later. Change-Id: I75b0f79c148afbe3c07ac664cfa9cade052c0c62
Diffstat (limited to 'gdb/python/lib')
-rw-r--r--gdb/python/lib/gdb/__init__.py2
-rw-r--r--gdb/python/lib/gdb/command/explore.py22
-rw-r--r--gdb/python/lib/gdb/printer/bound_registers.py7
-rw-r--r--gdb/python/lib/gdb/printing.py9
-rw-r--r--gdb/python/lib/gdb/xmethod.py8
5 files changed, 14 insertions, 34 deletions
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 5f63bce..a52f6b4 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -22,7 +22,7 @@ from contextlib import contextmanager
# Python 3 moved "reload"
if sys.version_info >= (3, 4):
from importlib import reload
-elif sys.version_info[0] > 2:
+else:
from imp import reload
from _gdb import *
diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py
index ea49c38..c03bef3 100644
--- a/gdb/python/lib/gdb/command/explore.py
+++ b/gdb/python/lib/gdb/command/explore.py
@@ -19,10 +19,6 @@
import gdb
import sys
-if sys.version_info[0] > 2:
- # Python 3 renamed raw_input to input
- raw_input = input
-
class Explorer(object):
"""Internal class which invokes other explorers."""
@@ -172,7 +168,7 @@ class Explorer(object):
so that the exploration session can shift back to the parent value.
Useful when exploring values.
"""
- raw_input("\nPress enter to return to parent value: ")
+ input("\nPress enter to return to parent value: ")
@staticmethod
def return_to_enclosing_type():
@@ -187,7 +183,7 @@ class Explorer(object):
so that the exploration session can shift back to the enclosing type.
Useful when exploring types.
"""
- raw_input("\nPress enter to return to enclosing type: ")
+ input("\nPress enter to return to enclosing type: ")
class ScalarExplorer(object):
@@ -244,7 +240,7 @@ class PointerExplorer(object):
"'%s' is a pointer to a value of type '%s'"
% (expr, str(value.type.target()))
)
- option = raw_input(
+ option = input(
"Continue exploring it as a pointer to a single " "value [y/n]: "
)
if option == "y":
@@ -264,13 +260,13 @@ class PointerExplorer(object):
)
return False
- option = raw_input("Continue exploring it as a pointer to an " "array [y/n]: ")
+ option = input("Continue exploring it as a pointer to an " "array [y/n]: ")
if option == "y":
while True:
index = 0
try:
index = int(
- raw_input(
+ input(
"Enter the index of the element you "
"want to explore in '%s': " % expr
)
@@ -338,7 +334,7 @@ class ArrayExplorer(object):
index = 0
try:
index = int(
- raw_input(
+ input(
"Enter the index of the element you want to "
"explore in '%s': " % expr
)
@@ -354,7 +350,7 @@ class ArrayExplorer(object):
str(element)
except gdb.MemoryError:
print("Cannot read value at index %d." % index)
- raw_input("Press enter to continue... ")
+ input("Press enter to continue... ")
return True
Explorer.explore_expr(
@@ -474,7 +470,7 @@ class CompoundExplorer(object):
print("")
if has_explorable_fields:
- choice = raw_input("Enter the field number of choice: ")
+ choice = input("Enter the field number of choice: ")
if choice in choice_to_compound_field_map:
Explorer.explore_expr(
choice_to_compound_field_map[choice][0],
@@ -550,7 +546,7 @@ class CompoundExplorer(object):
print("")
if len(choice_to_compound_field_map) > 0:
- choice = raw_input("Enter the field number of choice: ")
+ choice = input("Enter the field number of choice: ")
if choice in choice_to_compound_field_map:
if is_child:
new_name = "%s '%s' of %s" % (
diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py
index f8ce9ea..7cb6e8f 100644
--- a/gdb/python/lib/gdb/printer/bound_registers.py
+++ b/gdb/python/lib/gdb/printer/bound_registers.py
@@ -18,11 +18,6 @@ import sys
import gdb.printing
-if sys.version_info[0] > 2:
- # Python 3 removed basestring and long
- basestring = str
- long = int
-
class MpxBound128Printer:
"""Adds size field to a mpx __gdb_builtin_type_bound128 type."""
@@ -33,7 +28,7 @@ class MpxBound128Printer:
def to_string(self):
upper = self.val["ubound"]
lower = self.val["lbound"]
- size = (long)((upper) - (lower))
+ size = upper - lower
if size > -1:
size = size + 1
result = "{lbound = %s, ubound = %s} : size %s" % (lower, upper, size)
diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py
index 93d61f1..e208e88 100644
--- a/gdb/python/lib/gdb/printing.py
+++ b/gdb/python/lib/gdb/printing.py
@@ -21,11 +21,6 @@ import gdb.types
import re
import sys
-if sys.version_info[0] > 2:
- # Python 3 removed basestring and long
- basestring = str
- long = int
-
class PrettyPrinter(object):
"""A basic pretty-printer.
@@ -132,7 +127,7 @@ def register_pretty_printer(obj, printer, replace=False):
# Printers implemented as functions are old-style. In order to not risk
# breaking anything we do not check __name__ here.
if hasattr(printer, "name"):
- if not isinstance(printer.name, basestring):
+ if not isinstance(printer.name, str):
raise TypeError("printer name is not a string")
# If printer provides a name, make sure it doesn't contain ";".
# Semicolon is used by the info/enable/disable pretty-printer commands
@@ -232,7 +227,7 @@ class _EnumInstance:
def to_string(self):
flag_list = []
- v = long(self.val)
+ v = int(self.val)
any_found = False
for (e_name, e_value) in self.enumerators:
if v & e_value != 0:
diff --git a/gdb/python/lib/gdb/xmethod.py b/gdb/python/lib/gdb/xmethod.py
index 4c3a522..c69ea99 100644
--- a/gdb/python/lib/gdb/xmethod.py
+++ b/gdb/python/lib/gdb/xmethod.py
@@ -21,12 +21,6 @@ import re
import sys
-if sys.version_info[0] > 2:
- # Python 3 removed basestring and long
- basestring = str
- long = int
-
-
class XMethod(object):
"""Base class (or a template) for an xmethod description.
@@ -223,7 +217,7 @@ def _validate_xmethod_matcher(matcher):
return TypeError("Xmethod matcher is missing attribute: name")
if not hasattr(matcher, "enabled"):
return TypeError("Xmethod matcher is missing attribute: enabled")
- if not isinstance(matcher.name, basestring):
+ if not isinstance(matcher.name, str):
return TypeError("Attribute 'name' of xmethod matcher is not a " "string")
if matcher.name.find(";") >= 0:
return ValueError("Xmethod matcher name cannot contain ';' in it")