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
commit9d3785a8ac15dcc369b8c0b1074c5ca7145cdda7 (patch)
tree1860867e4dadf7fd90d2801bde97bcb86f2ac9da /gdb/python/py-auto-load.c
parente5eca01155e5f6c57337b72cbbe97dc135b66c5e (diff)
downloadbinutils-9d3785a8ac15dcc369b8c0b1074c5ca7145cdda7.zip
binutils-9d3785a8ac15dcc369b8c0b1074c5ca7145cdda7.tar.gz
binutils-9d3785a8ac15dcc369b8c0b1074c5ca7145cdda7.tar.bz2
[gdb/python] Fix abort on Py_Initialize
I tried out making python initialization fail by passing an incorrect PYTHONHOME with python 3.6, and got: ... $ PYTHONHOME=foo gdb -q Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings' Current thread 0x0000ffff89269c80 (most recent call first): Fatal signal: Aborted ... Aborted (core dumped) $ ... This is as per spec: when Py_Initialize () fails, a fatal error is raised using Py_FatalError. This can be worked around using: ... $ PYTHONHOME=foo gdb -q -eiex "set python ignore-environment on" (gdb) ... but it would be better if gdb didn't abort. I found an article [1] describing two solutions: - try out Py_Initialize in a separate process, and - catch the abort using a signal handler. This patch implements the latter solution. Obviously we cannot call into python anymore after the abort, so we avoid calling Py_IsInitialized (), and instead use a new variable py_isinitialized. This gets us instead: ... $ PYTHONHOME=foo gdb -q Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings' Current thread 0x0000fffecfd49c80 (most recent call first): Python not initialized $ ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR python/32379 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32379 [1] https://stackoverflow.com/questions/7688374/how-to-i-catch-and-handle-a-fatal-error-when-py-initialize-fails
Diffstat (limited to 'gdb/python/py-auto-load.c')
0 files changed, 0 insertions, 0 deletions