diff options
author | Tom de Vries <tdevries@suse.de> | 2024-12-03 22:58:47 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-12-03 22:58:47 +0100 |
commit | 6a02aa77d80e4040bea699a88cf0dd208df639b4 (patch) | |
tree | af5de6f27dfce87c95bc4cacadd9bf02bdf1ae6d /gdb/testsuite/gdb.python/py-cmd.c | |
parent | 922ab963e1c48c364b7f6363cb8e19f8a7175a20 (diff) | |
download | binutils-6a02aa77d80e4040bea699a88cf0dd208df639b4.zip binutils-6a02aa77d80e4040bea699a88cf0dd208df639b4.tar.gz binutils-6a02aa77d80e4040bea699a88cf0dd208df639b4.tar.bz2 |
[gdb/python] Issue warning if python fails to initialize
A common problem is that python may fail to initialize if PYTHONHOME is
set incorrectly, or points to incompatible default libraries.
Likewise if PYTHONPATH points to incompatible modules.
For instance, say PYTHONHOME is foo, then we get:
...
$ gdb -q
Python path configuration:
PYTHONHOME = 'foo'
PYTHONPATH = (not set)
program name = '/usr/bin/python'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = 'foo/lib64/python3.12'
sys._base_executable = '/usr/bin/python'
sys.base_prefix = 'foo'
sys.base_exec_prefix = 'foo'
sys.platlibdir = 'lib64'
sys.executable = '/usr/bin/python'
sys.prefix = 'foo'
sys.exec_prefix = 'foo'
sys.path = [
'foo/lib64/python312.zip',
'foo/lib64/python3.12',
'foo/lib64/python3.12/lib-dynload',
]
Python Exception <class 'ModuleNotFoundError'>: No module named 'encodings'
Python not initialized
$
...
In this case, it might be easy to figure out what went wrong because of the
obviously incorrect pathnames, but that might not be the case if PYTHONHOME
points to an incompatible python installation.
Fix this by adding a warning with a description of the possible cause and what
to do about it:
...
Python initialization failed: \
failed to get the Python codec of the filesystem encoding
gdb: warning: Python failed to initialize with PYTHONHOME set. Maybe because \
it is set incorrectly? Maybe because it points to incompatible standard \
libraries? Consider changing or unsetting it, or ignoring it using "set \
python ignore-environment on" at early initialization.
...
Likewise for PYTHONPATH:
...
Python initialization failed: \
failed to get the Python codec of the filesystem encoding
gdb: warning: Python failed to initialize with PYTHONPATH set. Maybe because \
it points to incompatible modules? Consider changing or unsetting it, or \
ignoring it using "set python ignore-environment on" at early \
initialization.
...
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR python/32379
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32379
Diffstat (limited to 'gdb/testsuite/gdb.python/py-cmd.c')
0 files changed, 0 insertions, 0 deletions