aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/python.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-06-03 07:59:49 -0600
committerTom Tromey <tromey@adacore.com>2022-07-05 10:28:39 -0600
commit3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3 (patch)
tree19216ecf8b1235823b9251f84710982be599e5f8 /gdb/python/python.c
parent736918239b16cc2ff57bfc64a982f2f0afc8c0f6 (diff)
downloadbinutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.zip
binutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.tar.gz
binutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.tar.bz2
Make 'import gdb.events' work
Pierre-Marie noticed that, while gdb.events is a Python module, it can't be imported. This patch changes how this module is created, so that it can be imported, while also ensuring that the module is always visible, just as it was in the past. This new approach required one non-obvious change -- when running gdb.base/warning.exp, where --data-directory is intentionally not found, the event registries can now be nullptr. Consequently, this patch probably also requires https://sourceware.org/pipermail/gdb-patches/2022-June/189796.html Note that this patch obsoletes https://sourceware.org/pipermail/gdb-patches/2022-June/189797.html
Diffstat (limited to 'gdb/python/python.c')
-rw-r--r--gdb/python/python.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8f526bb..2f1a00e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -2005,11 +2005,20 @@ do_start_initialization ()
remain alive for the duration of the program's execution, so
it is not freed after this call. */
Py_SetProgramName (progname_copy);
-
- /* Define _gdb as a built-in module. */
- PyImport_AppendInittab ("_gdb", init__gdb_module);
#endif
+ /* Define all internal modules. These are all imported (and thus
+ created) during initialization. */
+ struct _inittab mods[3] =
+ {
+ { "_gdb", init__gdb_module },
+ { "_gdbevents", gdbpy_events_mod_func },
+ { nullptr, nullptr }
+ };
+
+ if (PyImport_ExtendInittab (mods) < 0)
+ return false;
+
Py_Initialize ();
#if PY_VERSION_HEX < 0x03090000
/* PyEval_InitThreads became deprecated in Python 3.9 and will
@@ -2077,7 +2086,6 @@ do_start_initialization ()
|| gdbpy_initialize_thread () < 0
|| gdbpy_initialize_inferior () < 0
|| gdbpy_initialize_eventregistry () < 0
- || gdbpy_initialize_py_events () < 0
|| gdbpy_initialize_event () < 0
|| gdbpy_initialize_arch () < 0
|| gdbpy_initialize_registers () < 0