08bfd0a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
08bfd0a
From: Tom de Vries <tdevries@suse.de>
08bfd0a
Date: Wed, 22 Nov 2023 19:02:34 +0100
08bfd0a
Subject: gdb-do-not-import-py-curses-ascii-module.patch
08bfd0a
08bfd0a
;; Backport upstream commit e8c3dafa5f5.
08bfd0a
08bfd0a
[gdb/python] Don't import curses.ascii module unless necessary
08bfd0a
08bfd0a
I ran into a failure in test-case gdb.python/py-missing-debug.exp with python
08bfd0a
3.6, which was fixed by commit 7db795bc67a ("gdb/python: remove use of
08bfd0a
str.isascii()").
08bfd0a
08bfd0a
However, I subsequently ran into a failure with python 3.11:
08bfd0a
...
08bfd0a
(gdb) PASS: $exp: initial checks: debug info no longer found
08bfd0a
source py-missing-debug.py^M
08bfd0a
Traceback (most recent call last):^M
08bfd0a
  File "py-missing-debug.py", line 17, in <module>^M
08bfd0a
    from gdb.missing_debug import MissingDebugHandler^M
08bfd0a
  File "missing_debug.py", line 21, in <module>^M
08bfd0a
    from curses.ascii import isascii, isalnum^M
08bfd0a
  File "/usr/lib64/python3.11/_import_failed/curses.py", line 16, in <module>^M
08bfd0a
    raise ImportError(f"""Module '{failed_name}' is not installed.^M
08bfd0a
ImportError: Module 'curses' is not installed.^M
08bfd0a
Use:^M
08bfd0a
  sudo zypper install python311-curses^M
08bfd0a
to install it.^M
08bfd0a
(gdb) FAIL: $exp: source python script
08bfd0a
...
08bfd0a
08bfd0a
Apparently I have the curses module installed for 3.6, but not 3.11.
08bfd0a
08bfd0a
I could just install it, but the test-case worked fine with 3.11 before commit
08bfd0a
7db795bc67a.
08bfd0a
08bfd0a
Fix this by only using the curses module when necessary, for python <= 3.7.
08bfd0a
08bfd0a
Tested on x86_64-linux, with both python 3.6 and 3.11.
08bfd0a
08bfd0a
diff --git a/gdb/python/lib/gdb/missing_debug.py b/gdb/python/lib/gdb/missing_debug.py
08bfd0a
--- a/gdb/python/lib/gdb/missing_debug.py
08bfd0a
+++ b/gdb/python/lib/gdb/missing_debug.py
08bfd0a
@@ -18,8 +18,18 @@ MissingDebugHandler base class, and register_handler function.
08bfd0a
 """
08bfd0a
 
08bfd0a
 import gdb
08bfd0a
-from curses.ascii import isascii, isalnum
08bfd0a
-
08bfd0a
+import sys
08bfd0a
+if sys.version_info >= (3, 7):
08bfd0a
+    # Functions str.isascii() and str.isalnum are available starting Python
08bfd0a
+    # 3.7.
08bfd0a
+    def isascii(ch):
08bfd0a
+        return ch.isascii()
08bfd0a
+    def isalnum(ch):
08bfd0a
+        return ch.isalnum()
08bfd0a
+else:
08bfd0a
+    # Fall back to curses.ascii.isascii() and curses.ascii.isalnum() for
08bfd0a
+    # earlier versions.
08bfd0a
+    from curses.ascii import isascii, isalnum
08bfd0a
 
08bfd0a
 def _validate_name(name):
08bfd0a
     """Validate a missing debug handler name string.