aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-auto-load.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-11-22 19:34:24 +0100
committerTom de Vries <tdevries@suse.de>2024-11-22 19:34:24 +0100
commite5eca01155e5f6c57337b72cbbe97dc135b66c5e (patch)
tree47a0c80bf06b3399ec640d3851fc9eb32d92c825 /gdb/python/py-auto-load.c
parente031f02db3a23e96805b07fdee6fafdd2afea32f (diff)
downloadbinutils-e5eca01155e5f6c57337b72cbbe97dc135b66c5e.zip
binutils-e5eca01155e5f6c57337b72cbbe97dc135b66c5e.tar.gz
binutils-e5eca01155e5f6c57337b72cbbe97dc135b66c5e.tar.bz2
[gdb/python] Handle !Py_IsInitialized () in gdbpy_initialize
I tried out making python initialization fail by passing an incorrect PYTHONHOME, and got: ... $ PYTHONHOME=foo gdb -q Python path configuration: PYTHONHOME = 'foo' ... Python Exception <class 'ModuleNotFoundError'>: No module named 'encodings' Python not initialized $ ... The relevant part of the code is: ... static void gdbpy_initialize (const struct extension_language_defn *extlang) { if (!do_start_initialization () && PyErr_Occurred ()) gdbpy_print_stack (); gdbpy_enter enter_py; ... What happens is that: - do_start_initialization returns false because Py_InitializeFromConfig fails, leaving us in the !Py_IsInitialized () state - PyErr_Occurred () returns true - gdbpy_print_stack is called, which prints "Python Exception <class 'ModuleNotFoundError'>: No module named 'encodings" The problem is that in the Py_IsInitialized () == false state, very few functions can be called, and PyErr_Occurred is not one of them [1], and likewise functions in gdbpy_print_stack. Fix this by: - guarding the PyErr_Occurred / gdbpy_print_stack part with Py_IsInitialized (). - handling the !Py_IsInitialized () case by printing the failure PyStatus in do_start_initialization This gets us instead: ... $ PYTHONHOME=foo ./gdb.sh -q Python path configuration: PYTHONHOME = 'foo' ... Python initialization failed: failed to get the Python codec of the filesystem encoding Python not initialized $ ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> [1] https://docs.python.org/3/c-api/init.html#before-python-initialization
Diffstat (limited to 'gdb/python/py-auto-load.c')
0 files changed, 0 insertions, 0 deletions