gdb: delay python initialisation until gdbpy_finish_initialization
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.
This commit is contained in:
parent
913832e99c
commit
8e3685bf25
12 changed files with 125 additions and 48 deletions
|
@ -1,3 +1,31 @@
|
|||
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.
|
||||
|
|
|
@ -271,12 +271,18 @@ archpy_register_groups (PyObject *self, PyObject *args)
|
|||
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;
|
||||
|
|
|
@ -427,6 +427,17 @@ del_objfile_blocks (struct objfile *objfile, void *datum)
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -438,12 +449,6 @@ 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;
|
||||
|
|
|
@ -892,6 +892,14 @@ gdbpy_selected_inferior (PyObject *self, PyObject *args)
|
|||
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)
|
||||
{
|
||||
|
@ -902,9 +910,6 @@ 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");
|
||||
|
|
|
@ -693,12 +693,17 @@ objfile_to_objfile_object (struct objfile *objfile)
|
|||
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;
|
||||
|
||||
|
|
|
@ -504,12 +504,17 @@ pspace_to_pspace_object (struct program_space *pspace)
|
|||
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;
|
||||
|
||||
|
|
|
@ -423,14 +423,19 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
|
|||
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;
|
||||
|
|
|
@ -619,17 +619,22 @@ del_objfile_symbols (struct objfile *objfile, void *datum)
|
|||
}
|
||||
}
|
||||
|
||||
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",
|
||||
|
|
|
@ -511,6 +511,20 @@ del_objfile_sal (struct objfile *objfile, void *datum)
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -522,15 +536,6 @@ 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;
|
||||
|
|
|
@ -1424,14 +1424,19 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
|
|||
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)
|
||||
|
|
|
@ -614,12 +614,10 @@ pyuw_on_new_gdbarch (struct gdbarch *newarch)
|
|||
}
|
||||
}
|
||||
|
||||
/* 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."),
|
||||
|
@ -630,14 +628,21 @@ gdbpy_initialize_unwind (void)
|
|||
&setdebuglist, &showdebuglist);
|
||||
pyuw_gdbarch_data
|
||||
= 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",
|
||||
int rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
|
||||
(PyObject *) &pending_frame_object_type);
|
||||
if (rc)
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
if (PyType_Ready (&unwind_info_object_type) < 0)
|
||||
|
|
|
@ -1881,11 +1881,6 @@ message == an error message without a stack will be printed."),
|
|||
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
|
||||
|
@ -1962,6 +1957,9 @@ do_finish_initialization (const struct extension_language_defn *extlang)
|
|||
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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue