gdb delay guile initialization until gdbscm_finish_initialization

Like with the previous commit, this commit delays the initialisation
of the guile extension language until gdbscm_finish_initialization.

This is mostly about splitting the existing gdbscm_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 gdbscm_initialize_*
functions.

Then the call to code previously in _initialize_guile is moved into
gdbscm_finish_initialization.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* guile/guile.c (gdbscm_set_backtrace): Add declaration.
	(gdbscm_finish_initialization): Add code moved from
	_initialize_guile.
	(_initialize_guile): Move code to gdbscm_finish_initialization.
	* guile/scm-arch.c (gdbscm_initialize_arches): Move some code into
	_initialize_scm_arch.
	(_initialize_scm_arch): New function.
	* guile/scm-block.c (gdbscm_initialize_blocks): Move some code
	into _initialize_scm_block.
	(_initialize_scm_block): New function.
	* guile/scm-frame.c (gdbscm_initialize_frames): Move some code
	into _initialize_scm_frame.
	(_initialize_scm_frame): New function.
	* guile/scm-objfile.c (gdbscm_initialize_objfiles): Move some code
	into _initialize_scm_objfile.
	(_initialize_scm_objfile): New function.
	* guile/scm-progspace.c (gdbscm_initialize_pspaces): Move some
	code into _initialize_scm_progspace.
	(_initialize_scm_progspace): New function.
	* guile/scm-symbol.c (gdbscm_initialize_symbols): Move some code
	into _initialize_scm_symbol.
	(_initialize_scm_symbol): New function.
	* guile/scm-symtab.c (gdbscm_initialize_symtabs): Move some code
	into _initialize_scm_symtab.
	(_initialize_scm_symtab): New function.
	* guile/scm-type.c (gdbscm_initialize_types): Move some code into
	_initialize_scm_type.
	(_initialize_scm_type): New function.
This commit is contained in:
Andrew Burgess
2021-04-22 18:17:01 +01:00
parent 8e3685bf25
commit 880ae75a2b
10 changed files with 109 additions and 42 deletions

View File

@@ -81,6 +81,7 @@ static int gdbscm_initialized (const struct extension_language_defn *);
static void gdbscm_eval_from_control_command
(const struct extension_language_defn *, struct command_line *);
static script_sourcer_func gdbscm_source_script;
static void gdbscm_set_backtrace (int enable);
int gdb_scheme_initialized;
@@ -644,6 +645,40 @@ call_initialize_gdb_module (void *data)
static void
gdbscm_finish_initialization (const struct extension_language_defn *extlang)
{
#if HAVE_GUILE
/* The Python support puts the C side in module "_gdb", leaving the
Python side to define module "gdb" which imports "_gdb". There is
evidently no similar convention in Guile so we skip this. */
#if HAVE_GUILE_MANUAL_FINALIZATION
/* Our SMOB free functions are not thread-safe, as GDB itself is not
intended to be thread-safe. Disable automatic finalization so that
finalizers aren't run in other threads. */
scm_set_automatic_finalization_enabled (0);
#endif
/* Before we initialize Guile, block signals needed by gdb (especially
SIGCHLD). This is done so that all threads created during Guile
initialization have SIGCHLD blocked. PR 17247. Really libgc and
Guile should do this, but we need to work with libgc 7.4.x. */
{
gdb::block_signals blocker;
/* scm_with_guile is the most portable way to initialize Guile. Plus
we need to initialize the Guile support while in Guile mode (e.g.,
called from within a call to scm_with_guile). */
scm_with_guile (call_initialize_gdb_module, NULL);
}
/* Set Guile's backtrace to match the "set guile print-stack" default.
[N.B. The two settings are still separate.] But only do this after
we've initialized Guile, it's nice to see a backtrace if there's an
error during initialization. OTOH, if the error is that gdb/init.scm
wasn't found because gdb is being run from the build tree, the
backtrace is more noise than signal. Sigh. */
gdbscm_set_backtrace (0);
#endif
/* Restore the environment to the user interaction one. */
scm_set_current_module (scm_interaction_environment ());
}
@@ -770,43 +805,4 @@ void
_initialize_guile ()
{
install_gdb_commands ();
#if HAVE_GUILE
{
/* The Python support puts the C side in module "_gdb", leaving the Python
side to define module "gdb" which imports "_gdb". There is evidently no
similar convention in Guile so we skip this. */
#if HAVE_GUILE_MANUAL_FINALIZATION
/* Our SMOB free functions are not thread-safe, as GDB itself is not
intended to be thread-safe. Disable automatic finalization so that
finalizers aren't run in other threads. */
scm_set_automatic_finalization_enabled (0);
#endif
/* Before we initialize Guile, block signals needed by gdb
(especially SIGCHLD).
This is done so that all threads created during Guile initialization
have SIGCHLD blocked. PR 17247.
Really libgc and Guile should do this, but we need to work with
libgc 7.4.x. */
{
gdb::block_signals blocker;
/* scm_with_guile is the most portable way to initialize Guile.
Plus we need to initialize the Guile support while in Guile mode
(e.g., called from within a call to scm_with_guile). */
scm_with_guile (call_initialize_gdb_module, NULL);
}
/* Set Guile's backtrace to match the "set guile print-stack" default.
[N.B. The two settings are still separate.]
But only do this after we've initialized Guile, it's nice to see a
backtrace if there's an error during initialization.
OTOH, if the error is that gdb/init.scm wasn't found because gdb is
being run from the build tree, the backtrace is more noise than signal.
Sigh. */
gdbscm_set_backtrace (0);
}
#endif
}