Delay Python initialisation until gdbpy_finish_initialization.
This is mostly about splitting the existing gdbpy_initialize_*
functions in two, all the calls to register_objfile_data_with_cleanup,
gdbarch_data_register_post_init, etc are moved into new _initialize_*
functions, but everything else is left in the gdbpy_initialize_*
functions.
Then the call to do_start_initialization (in python/python.c) is moved
from the _initialize_python function into gdbpy_finish_initialization.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* python/py-arch.c (_initialize_py_arch): New function.
(gdbpy_initialize_arch): Move code to _initialize_py_arch.
* python/py-block.c (_initialize_py_block): New function.
(gdbpy_initialize_blocks): Move code to _initialize_py_block.
* python/py-inferior.c (_initialize_py_inferior): New function.
(gdbpy_initialize_inferior): Move code to _initialize_py_inferior.
* python/py-objfile.c (_initialize_py_objfile): New function.
(gdbpy_initialize_objfile): Move code to _initialize_py_objfile.
* python/py-progspace.c (_initialize_py_progspace): New function.
(gdbpy_initialize_pspace): Move code to _initialize_py_progspace.
* python/py-registers.c (_initialize_py_registers): New function.
(gdbpy_initialize_registers): Move code to
_initialize_py_registers.
* python/py-symbol.c (_initialize_py_symbol): New function.
(gdbpy_initialize_symbols): Move code to _initialize_py_symbol.
* python/py-symtab.c (_initialize_py_symtab): New function.
(gdbpy_initialize_symtabs): Move code to _initialize_py_symtab.
* python/py-type.c (_initialize_py_type): New function.
(gdbpy_initialize_types): Move code to _initialize_py_type.
* python/py-unwind.c (_initialize_py_unwind): New function.
(gdbpy_initialize_unwind): Move code to _initialize_py_unwind.
* python/python.c (_initialize_python): Move call to
do_start_initialization to gdbpy_finish_initialization.
(gdbpy_finish_initialization): Add call to
do_start_initialization.
+2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * python/py-arch.c (_initialize_py_arch): New function.
+ (gdbpy_initialize_arch): Move code to _initialize_py_arch.
+ * python/py-block.c (_initialize_py_block): New function.
+ (gdbpy_initialize_blocks): Move code to _initialize_py_block.
+ * python/py-inferior.c (_initialize_py_inferior): New function.
+ (gdbpy_initialize_inferior): Move code to _initialize_py_inferior.
+ * python/py-objfile.c (_initialize_py_objfile): New function.
+ (gdbpy_initialize_objfile): Move code to _initialize_py_objfile.
+ * python/py-progspace.c (_initialize_py_progspace): New function.
+ (gdbpy_initialize_pspace): Move code to _initialize_py_progspace.
+ * python/py-registers.c (_initialize_py_registers): New function.
+ (gdbpy_initialize_registers): Move code to
+ _initialize_py_registers.
+ * python/py-symbol.c (_initialize_py_symbol): New function.
+ (gdbpy_initialize_symbols): Move code to _initialize_py_symbol.
+ * python/py-symtab.c (_initialize_py_symtab): New function.
+ (gdbpy_initialize_symtabs): Move code to _initialize_py_symtab.
+ * python/py-type.c (_initialize_py_type): New function.
+ (gdbpy_initialize_types): Move code to _initialize_py_type.
+ * python/py-unwind.c (_initialize_py_unwind): New function.
+ (gdbpy_initialize_unwind): Move code to _initialize_py_unwind.
+ * python/python.c (_initialize_python): Move call to
+ do_start_initialization to gdbpy_finish_initialization.
+ (gdbpy_finish_initialization): Add call to
+ do_start_initialization.
+
2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com>
* extension.c (struct scoped_default_signal): New struct.
return gdbpy_new_reggroup_iterator (gdbarch);
}
+void _initialize_py_arch ();
+void
+_initialize_py_arch ()
+{
+ arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
+}
+
/* Initializes the Architecture class in the gdb module. */
int
gdbpy_initialize_arch (void)
{
- arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
arch_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&arch_object_type) < 0)
return -1;
}
}
+void _initialize_py_block ();
+void
+_initialize_py_block ()
+{
+ /* Register an objfile "free" callback so we can properly
+ invalidate blocks when an object file is about to be
+ deleted. */
+ blpy_objfile_data_key
+ = register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
+}
+
int
gdbpy_initialize_blocks (void)
{
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
return -1;
- /* Register an objfile "free" callback so we can properly
- invalidate blocks when an object file is about to be
- deleted. */
- blpy_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
-
if (gdb_pymodule_addobject (gdb_module, "Block",
(PyObject *) &block_object_type) < 0)
return -1;
inferior_to_inferior_object (current_inferior ()).release ());
}
+void _initialize_py_inferior ();
+void
+_initialize_py_inferior ()
+{
+ infpy_inf_data_key =
+ register_inferior_data_with_cleanup (NULL, py_free_inferior);
+}
+
int
gdbpy_initialize_inferior (void)
{
(PyObject *) &inferior_object_type) < 0)
return -1;
- infpy_inf_data_key =
- register_inferior_data_with_cleanup (NULL, py_free_inferior);
-
gdb::observers::new_thread.attach (add_thread_object, "py-inferior");
gdb::observers::thread_exit.attach (delete_thread_object, "py-inferior");
gdb::observers::normal_stop.attach (python_on_normal_stop, "py-inferior");
return gdbpy_ref<>::new_reference (result);
}
-int
-gdbpy_initialize_objfile (void)
+void _initialize_py_objfile ();
+void
+_initialize_py_objfile ()
{
objfpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, py_free_objfile);
+}
+int
+gdbpy_initialize_objfile (void)
+{
if (PyType_Ready (&objfile_object_type) < 0)
return -1;
return gdbpy_ref<>::new_reference (result);
}
-int
-gdbpy_initialize_pspace (void)
+void _initialize_py_progspace ();
+void
+_initialize_py_progspace ()
{
pspy_pspace_data_key
= register_program_space_data_with_cleanup (NULL, py_free_pspace);
+}
+int
+gdbpy_initialize_pspace (void)
+{
if (PyType_Ready (&pspace_object_type) < 0)
return -1;
return false;
}
+void _initialize_py_registers ();
+void
+_initialize_py_registers ()
+{
+ gdbpy_register_object_data
+ = gdbarch_data_register_post_init (gdbpy_register_object_data_init);
+}
+
/* Initializes the new Python classes from this file in the gdb module. */
int
gdbpy_initialize_registers ()
{
- gdbpy_register_object_data
- = gdbarch_data_register_post_init (gdbpy_register_object_data_init);
-
register_descriptor_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (®ister_descriptor_object_type) < 0)
return -1;
}
}
-int
-gdbpy_initialize_symbols (void)
+void _initialize_py_symbol ();
+void
+_initialize_py_symbol ()
{
- if (PyType_Ready (&symbol_object_type) < 0)
- return -1;
-
/* Register an objfile "free" callback so we can properly
invalidate symbol when an object file that is about to be
deleted. */
sympy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_symbols);
+}
+
+int
+gdbpy_initialize_symbols (void)
+{
+ if (PyType_Ready (&symbol_object_type) < 0)
+ return -1;
if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
|| PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST",
}
}
+void _initialize_py_symtab ();
+void
+_initialize_py_symtab ()
+{
+ /* Register an objfile "free" callback so we can properly
+ invalidate symbol tables, and symbol table and line data
+ structures when an object file that is about to be
+ deleted. */
+ stpy_objfile_data_key
+ = register_objfile_data_with_cleanup (NULL, del_objfile_symtab);
+ salpy_objfile_data_key
+ = register_objfile_data_with_cleanup (NULL, del_objfile_sal);
+}
+
int
gdbpy_initialize_symtabs (void)
{
if (PyType_Ready (&sal_object_type) < 0)
return -1;
- /* Register an objfile "free" callback so we can properly
- invalidate symbol tables, and symbol table and line data
- structures when an object file that is about to be
- deleted. */
- stpy_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, del_objfile_symtab);
- salpy_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, del_objfile_sal);
-
if (gdb_pymodule_addobject (gdb_module, "Symtab",
(PyObject *) &symtab_object_type) < 0)
return -1;
return type_to_type_object (type);
}
+void _initialize_py_type ();
+void
+_initialize_py_type ()
+{
+ typy_objfile_data_key
+ = register_objfile_data_with_cleanup (save_objfile_types, NULL);
+}
+
int
gdbpy_initialize_types (void)
{
int i;
- typy_objfile_data_key
- = register_objfile_data_with_cleanup (save_objfile_types, NULL);
-
if (PyType_Ready (&type_object_type) < 0)
return -1;
if (PyType_Ready (&field_object_type) < 0)
}
}
-/* Initialize unwind machinery. */
-
-int
-gdbpy_initialize_unwind (void)
+void _initialize_py_unwind ();
+void
+_initialize_py_unwind ()
{
- int rc;
add_setshow_zuinteger_cmd
("py-unwind", class_maintenance, &pyuw_debug,
_("Set Python unwinder debugging."),
NULL,
&setdebuglist, &showdebuglist);
pyuw_gdbarch_data
- = gdbarch_data_register_post_init (pyuw_gdbarch_data_init);
+ = gdbarch_data_register_post_init (pyuw_gdbarch_data_init);
+}
+
+/* Initialize unwind machinery. */
+
+int
+gdbpy_initialize_unwind (void)
+{
gdb::observers::architecture_changed.attach (pyuw_on_new_gdbarch,
"py-unwind");
if (PyType_Ready (&pending_frame_object_type) < 0)
return -1;
- rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
- (PyObject *) &pending_frame_object_type);
- if (rc)
+ int rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
+ (PyObject *) &pending_frame_object_type);
+ if (rc != 0)
return rc;
if (PyType_Ready (&unwind_info_object_type) < 0)
NULL, NULL,
&user_set_python_list,
&user_show_python_list);
-
-#ifdef HAVE_PYTHON
- if (!do_start_initialization () && PyErr_Occurred ())
- gdbpy_print_stack ();
-#endif /* HAVE_PYTHON */
}
#ifdef HAVE_PYTHON
static void
gdbpy_finish_initialization (const struct extension_language_defn *extlang)
{
+ if (!do_start_initialization () && PyErr_Occurred ())
+ gdbpy_print_stack ();
+
gdbpy_enter enter_py (get_current_arch (), current_language);
if (!do_finish_initialization (extlang))