mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-23 10:03:47 +08:00
9d3785a8ac
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 |
||
---|---|---|
.. | ||
lib/gdb | ||
py-all-events.def | ||
py-arch.c | ||
py-auto-load.c | ||
py-block.c | ||
py-bpevent.c | ||
py-breakpoint.c | ||
py-cmd.c | ||
py-connection.c | ||
py-continueevent.c | ||
py-dap.c | ||
py-disasm.c | ||
py-event-types.def | ||
py-event.c | ||
py-event.h | ||
py-events.h | ||
py-evtregistry.c | ||
py-evts.c | ||
py-exitedevent.c | ||
py-finishbreakpoint.c | ||
py-frame.c | ||
py-framefilter.c | ||
py-function.c | ||
py-gdb-readline.c | ||
py-inferior.c | ||
py-infevents.c | ||
py-infthread.c | ||
py-instruction.c | ||
py-instruction.h | ||
py-lazy-string.c | ||
py-linetable.c | ||
py-membuf.c | ||
py-mi.c | ||
py-micmd.c | ||
py-newobjfileevent.c | ||
py-objfile.c | ||
py-param.c | ||
py-prettyprint.c | ||
py-progspace.c | ||
py-record-btrace.c | ||
py-record-btrace.h | ||
py-record-full.c | ||
py-record-full.h | ||
py-record.c | ||
py-record.h | ||
py-ref.h | ||
py-registers.c | ||
py-signalevent.c | ||
py-stopevent.c | ||
py-stopevent.h | ||
py-symbol.c | ||
py-symtab.c | ||
py-threadevent.c | ||
py-tui.c | ||
py-type.c | ||
py-uiout.h | ||
py-unwind.c | ||
py-utils.c | ||
py-value.c | ||
py-varobj.c | ||
py-xmethods.c | ||
python-config.py | ||
python-internal.h | ||
python.c | ||
python.h |