gdb: delay python initialisation until gdbpy_finish_initialization
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 22 Apr 2021 16:11:25 +0000 (17:11 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 28 Apr 2021 08:56:20 +0000 (09:56 +0100)
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.

12 files changed:
gdb/ChangeLog
gdb/python/py-arch.c
gdb/python/py-block.c
gdb/python/py-inferior.c
gdb/python/py-objfile.c
gdb/python/py-progspace.c
gdb/python/py-registers.c
gdb/python/py-symbol.c
gdb/python/py-symtab.c
gdb/python/py-type.c
gdb/python/py-unwind.c
gdb/python/python.c

index c417e81b893534af43dff7c67d126c472157f1f3..c3156a8d07350f6aca760378f590da8e6d42c0cd 100644 (file)
@@ -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.
index d1960b4906e5a9fd3cb842ba028c42209d4c7a87..66f2d28b94a5d5bfb28dd2fb006b207f53014891 100644 (file)
@@ -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;
index d257545b8aa3a6706cc5ff43e3d508624ea35bf1..244ff9a6bab6bcb1baf7038330431bfa6734b643 100644 (file)
@@ -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;
index febd2a73ece34a1ba236ecb52fa283eb326a0e43..94c2c2329e9ae83bf000002c215b936cfef5cd2d 100644 (file)
@@ -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");
index 8fb73820bb535997ca5aff919a0ac0e19f518bfa..626f2d3e18c4d1c3313871b0edb8fc072ab50dcc 100644 (file)
@@ -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;
 
index 011c6cc6c362f9503d35cb60f78e9765fbc0ccfb..d8df9c31d804cb4ea6c649baec573191790ad659 100644 (file)
@@ -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;
 
index eb59a499f337e3517c7f3453533a33ceb4a43ffb..04e554f48e111c5006ac1d91bc63cf06d861ba31 100644 (file)
@@ -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 (&register_descriptor_object_type) < 0)
     return -1;
index ead26d5d441a18ad5aa7f8d8d41427b70b198c5d..8953ee097ccba1bfd3c5692337b7f46c0070587d 100644 (file)
@@ -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",
index f0bf4ef591103117ea2c7de0540c3239903b3f9d..e9013731c4bdfa3f895855bc73c67f7136c8603e 100644 (file)
@@ -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;
index 148e4a6aa3a0987bb225c2ca375cd0a7669b3bce..4f5f42529c27352eb92ff93024957d12c3c761a7 100644 (file)
@@ -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)
index 5dc8d33f0dc2c2b8ba2a4ef419ae6658dd59d117..4b25c485b8c14d164e90e150330339ef2506462f 100644 (file)
@@ -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."),
@@ -629,15 +627,22 @@ gdbpy_initialize_unwind (void)
        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)
index 9eed258c18167f7cac09bc45924b55711244a259..520508043bab1b18ebafb994668e989e39ccda54 100644 (file)
@@ -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))
This page took 0.037468 seconds and 4 git commands to generate.