diff options
author | Tom de Vries <tdevries@suse.de> | 2023-11-22 19:02:34 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-11-22 19:02:34 +0100 |
commit | e8c3dafa5f529e85d7179441be7d039ee9e062bc (patch) | |
tree | 5bd5690b3d62e2550e5adfaf15fc5e03a0bfa83d /gdb/python | |
parent | 27365c5189999e3326e097d9eef4aeaae88651c1 (diff) | |
download | gdb-e8c3dafa5f529e85d7179441be7d039ee9e062bc.zip gdb-e8c3dafa5f529e85d7179441be7d039ee9e062bc.tar.gz gdb-e8c3dafa5f529e85d7179441be7d039ee9e062bc.tar.bz2 |
[gdb/python] Don't import curses.ascii module unless necessary
I ran into a failure in test-case gdb.python/py-missing-debug.exp with python
3.6, which was fixed by commit 7db795bc67a ("gdb/python: remove use of
str.isascii()").
However, I subsequently ran into a failure with python 3.11:
...
(gdb) PASS: $exp: initial checks: debug info no longer found
source py-missing-debug.py^M
Traceback (most recent call last):^M
File "py-missing-debug.py", line 17, in <module>^M
from gdb.missing_debug import MissingDebugHandler^M
File "missing_debug.py", line 21, in <module>^M
from curses.ascii import isascii, isalnum^M
File "/usr/lib64/python3.11/_import_failed/curses.py", line 16, in <module>^M
raise ImportError(f"""Module '{failed_name}' is not installed.^M
ImportError: Module 'curses' is not installed.^M
Use:^M
sudo zypper install python311-curses^M
to install it.^M
(gdb) FAIL: $exp: source python script
...
Apparently I have the curses module installed for 3.6, but not 3.11.
I could just install it, but the test-case worked fine with 3.11 before commit
7db795bc67a.
Fix this by only using the curses module when necessary, for python <= 3.7.
Tested on x86_64-linux, with both python 3.6 and 3.11.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/missing_debug.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/gdb/python/lib/gdb/missing_debug.py b/gdb/python/lib/gdb/missing_debug.py index bb233a6..b693bf2 100644 --- a/gdb/python/lib/gdb/missing_debug.py +++ b/gdb/python/lib/gdb/missing_debug.py @@ -18,8 +18,18 @@ MissingDebugHandler base class, and register_handler function. """ import gdb -from curses.ascii import isascii, isalnum - +import sys +if sys.version_info >= (3, 7): + # Functions str.isascii() and str.isalnum are available starting Python + # 3.7. + def isascii(ch): + return ch.isascii() + def isalnum(ch): + return ch.isalnum() +else: + # Fall back to curses.ascii.isascii() and curses.ascii.isalnum() for + # earlier versions. + from curses.ascii import isascii, isalnum def _validate_name(name): """Validate a missing debug handler name string. |