gdb/gdb-python-avoid-depending-on-the-curses-library.patch
Tom de Vries 8aea3c9b98 - Update to fedora rawhide @ 08bfd0a.
- Patches dropped:
  * fixup-gdb-6.3-gstack-20050411.patch
  * fixup-skip-tests.patch
  * gdb-6.6-buildid-locate-rpm-librpm-workaround.patch
  * gdb-6.6-buildid-locate-rpm.patch
- Patches added:
  * gdb-add-missing-debug-ext-lang-hook.patch
  * gdb-add-missing-debug-info-python-hook.patch
  * gdb-add-rpm-suggestion-script.patch
  * gdb-do-not-import-py-curses-ascii-module.patch
  * gdb-handle-no-python-gdb-module.patch
  * gdb-merge-debug-symbol-lookup.patch
  * gdb-python-avoid-depending-on-the-curses-library.patch
  * gdb-refactor-find-and-add-separate-symbol-file.patch
  * gdb-reformat-missing-debug-py-file.patch
  * gdb-remove-path-in-test-name.patch
  * gdb-remove-use-of-py-isascii
  * gdb-sync-coffread-with-elfread.patch
- Patches updated:
  * fixup-gdb-bz634108-solib_address.patch
  * gdb-6.3-gstack-20050411.patch
  * gdb-6.6-buildid-locate-rpm-suse.patch
  * gdb-6.6-buildid-locate-solib-missing-ids.patch
  * gdb-6.6-buildid-locate.patch
  * gdb-archer-next-over-throw-cxx-exec.patch
  * gdb-bz634108-solib_address.patch
  * gdb-fedora-libncursesw.patch
  * gdb-glibc-strstr-workaround.patch
  * gdb-rhbz1007614-memleak-infpy_read_memory-test.patch

OBS-URL: https://build.opensuse.org/package/show/devel:gcc/gdb?expand=0&rev=409
2025-01-23 14:31:06 +00:00

93 lines
3.0 KiB
Diff

From ed298cb88f0345d32a412c481898d867677726b8 Mon Sep 17 00:00:00 2001
From: Andrew Burgess <aburgess@redhat.com>
Date: Mon, 9 Sep 2024 17:33:54 +0100
Subject: [PATCH] gdb/python: avoid depending on the curses library
The commit:
commit 29c70787112e01cd52b53bf14bdcacb0a11e0725
Date: Sun Sep 8 07:46:09 2024 +0200
[gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp
Highlighted that in some cases we might be running on a system with an
older version of Python (earlier than 3.7), and on a system for which
the curses library has not been installed.
In these circumstances the gdb.missing_debug module will not load as
it uses curses to provide isalnum() and isascii() functions.
To avoid this problem I propose that we copy the isalnum() and
isascii() from the Python curses library. These functions are
basically trivial and removing the curses dependency means GDB will
work in more cases without increasing its dependencies.
I did consider keeping the uses of curses and only having the function
definitions be a fallback for when the curses library failed to load,
but this felt like overkill. The function definitions are both tiny
and I think "obvious" given their specifications, so I figure we might
as well just use our own definitions if they are not available as
builtin methods on the str class.
For testing I changed this line:
if sys.version_info >= (3, 7):
to
if sys.version_info >= (3, 7) and False:
then reran gdb.python/py-missing-debug.exp, there were no failures.
Approved-By: Tom de Vries <tdevries@suse.de>
---
gdb/python/lib/gdb/missing_debug.py | 30 ++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/gdb/python/lib/gdb/missing_debug.py b/gdb/python/lib/gdb/missing_debug.py
index 7a768e5e05b..be6aacb1f41 100644
--- a/gdb/python/lib/gdb/missing_debug.py
+++ b/gdb/python/lib/gdb/missing_debug.py
@@ -30,9 +30,33 @@ if sys.version_info >= (3, 7):
return ch.isalnum()
else:
- # Fall back to curses.ascii.isascii() and curses.ascii.isalnum() for
- # earlier versions.
- from curses.ascii import isascii, isalnum
+ # Older version of Python doesn't have str.isascii() and
+ # str.isalnum() so provide our own.
+ #
+ # We could import isalnum() and isascii() from the curses library,
+ # but that adds an extra dependency. Given these functions are
+ # both small and trivial lets implement them here.
+ #
+ # These definitions are based on those in the curses library, but
+ # simplified as we know C will always be a single character 'str'.
+
+ def isdigit(c):
+ return 48 <= ord(c) <= 57
+
+ def islower(c):
+ return 97 <= ord(c) <= 122
+
+ def isupper(c):
+ return 65 <= ord(c) <= 90
+
+ def isalpha(c):
+ return isupper(c) or islower(c)
+
+ def isalnum(c):
+ return isalpha(c) or isdigit(c)
+
+ def isascii(c):
+ return 0 <= ord(c) <= 127
def _validate_name(name):
base-commit: cdf77e047eba662880a85ca55489a96c83c34cfb
--
2.43.0