]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add extension_language_ops::shutdown
authorTom Tromey <tromey@adacore.com>
Fri, 23 Feb 2024 20:18:49 +0000 (13:18 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 27 Feb 2024 17:30:29 +0000 (10:30 -0700)
Right now, Python is shut down via a final cleanup.  However, it seems
to me that it is better for extension languages to be shut down
explicitly, after all the ordinary final cleanups are run.  The main
reason for this is that a subsequent patch adds another case like
finalize_values; and rather than add a series of workarounds for
Python shutdown, it seemed better to let these be done via final
cleanups, and then have Python shutdown itself be the special case.

gdb/extension-priv.h
gdb/extension.c
gdb/extension.h
gdb/guile/guile.c
gdb/python/python.c
gdb/top.c

index b709494927d4870c482cec0938a445a4e23fba4f..cb00cb6ff7b9abe6e6403c47bd9754e42d1a2523 100644 (file)
@@ -119,6 +119,10 @@ struct extension_language_ops
      This method is required.  */
   int (*initialized) (const struct extension_language_defn *);
 
+  /* Called just before GDB exits.  This shuts down the extension
+     language.  This can be NULL.  */
+  void (*shutdown) (const struct extension_language_defn *);
+
   /* Process a sequence of commands embedded in GDB's own scripting language.
      E.g.,
      python
index 42e05199d2c88719d2c853c628abee4c06f94c0f..9f403500497fa14806179757a7b1573691173634 100644 (file)
@@ -341,6 +341,18 @@ ext_lang_initialization (void)
     }
 }
 
+/* See extension.h.  */
+
+void
+ext_lang_shutdown ()
+{
+  for (const struct extension_language_defn *extlang : extension_languages)
+    {
+      if (extlang->ops != nullptr && extlang->ops->shutdown != nullptr)
+       extlang->ops->shutdown (extlang);
+    }
+}
+
 /* Invoke the appropriate extension_language_ops.eval_from_control_command
    method to perform CMD, which is a list of commands in an extension language.
 
index 0514d7930a22c378dc849c71001dbb795c6c1c5a..5260bcbde0031956cd19f059942995d652884f5c 100644 (file)
@@ -282,6 +282,9 @@ extern bool ext_lang_auto_load_enabled (const struct extension_language_defn *);
 
 extern void ext_lang_initialization (void);
 
+/* Shut down all extension languages.  */
+extern void ext_lang_shutdown ();
+
 extern void eval_ext_lang_from_control_command (struct command_line *cmd);
 
 extern void auto_load_ext_lang_scripts_for_objfile (struct objfile *);
index 30d1c72fceb95bd9010214307b95abf99f34f260..f0db709e4fec9dab6095c556b74d19cbd9f4b8e9 100644 (file)
@@ -115,6 +115,7 @@ static const struct extension_language_ops guile_extension_ops =
 {
   gdbscm_initialize,
   gdbscm_initialized,
+  nullptr,
 
   gdbscm_eval_from_control_command,
 
index 8f8ee7c06809850ed693edc4b1644e6b48fbbee3..57f6bd571d58ea7b6cd83f892276598eafd70ff4 100644 (file)
@@ -110,6 +110,7 @@ static objfile_script_sourcer_func gdbpy_source_objfile_script;
 static objfile_script_executor_func gdbpy_execute_objfile_script;
 static void gdbpy_initialize (const struct extension_language_defn *);
 static int gdbpy_initialized (const struct extension_language_defn *);
+static void finalize_python (const struct extension_language_defn *);
 static void gdbpy_eval_from_control_command
   (const struct extension_language_defn *, struct command_line *cmd);
 static void gdbpy_start_type_printers (const struct extension_language_defn *,
@@ -147,6 +148,7 @@ static const struct extension_language_ops python_extension_ops =
 {
   gdbpy_initialize,
   gdbpy_initialized,
+  finalize_python,
 
   gdbpy_eval_from_control_command,
 
@@ -2057,7 +2059,7 @@ static struct cmd_list_element *user_show_python_list;
    interpreter.  This lets Python's 'atexit' work.  */
 
 static void
-finalize_python ()
+finalize_python (const struct extension_language_defn *ignore)
 {
   struct active_ext_lang_state *previous_active;
 
@@ -2297,8 +2299,6 @@ init_done:
   /* Release the GIL while gdb runs.  */
   PyEval_SaveThread ();
 
-  add_final_cleanup (finalize_python);
-
   /* Only set this when initialization has succeeded.  */
   gdb_python_initialized = 1;
   return true;
index 5114713baa47ac1dfe3529c2ab99be79c184d1db..67d6670cd9c931a844badffd6524b41ed51dfa49 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1819,6 +1819,8 @@ quit_force (int *exit_arg, int from_tty)
       exception_print (gdb_stderr, ex);
     }
 
+  ext_lang_shutdown ();
+
   exit (exit_code);
 }