diff options
author | Tom de Vries <tdevries@suse.de> | 2024-11-22 19:34:24 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-11-22 19:34:24 +0100 |
commit | 372d0a4c9655127da2677dabf70e8e51de24c382 (patch) | |
tree | 079001f526e3e7cf799a45f1662792a1ce112b8b /gdb/python/py-auto-load.c | |
parent | 9d3785a8ac15dcc369b8c0b1074c5ca7145cdda7 (diff) | |
download | binutils-372d0a4c9655127da2677dabf70e8e51de24c382.zip binutils-372d0a4c9655127da2677dabf70e8e51de24c382.tar.gz binutils-372d0a4c9655127da2677dabf70e8e51de24c382.tar.bz2 |
[gdb/python] Handle failure to initialize without exiting
I tried out making python initialization fail by passing an incorrect
PYTHONHOME, and got:
...
$ 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
$
...
The relevant part of the code is:
...
static void
gdbpy_initialize (const struct extension_language_defn *extlang)
{
if (!do_start_initialization () && py_isinitialized && PyErr_Occurred ())
gdbpy_print_stack ();
gdbpy_enter enter_py;
...
What happens is:
- gdbpy_enter::gdbpy_enter () is called, where we run into:
'if (!gdb_python_initialized) error (_("Python not initialized"));'
- the error propagates to gdb's toplevel
- gdb print the error and exits.
It seems unnecesssary that we exit gdb. We could continue the
session without python support.
Fix this by:
- bailing out of gdbpy_initialize if !do_start_initialization
- bailing out of finalize_python if !gdb_python_initialized
This gets us instead:
...
$ PYTHONHOME=foo gdb -q
Python path configuration:
PYTHONHOME = 'foo'
...
Python initialization failed: \
failed to get the Python codec of the filesystem encoding
(gdb) python print (1)
Python not initialized
(gdb)
...
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/py-auto-load.c')
0 files changed, 0 insertions, 0 deletions