forked from Imagelibrary/binutils-gdb
gdb: add all_objfiles_removed observer
The new_objfile observer is currently used to indicate both when a new
objfile is added to program space (when passed non-nullptr) and when all
objfiles of a program space were just removed (when passed nullptr).
I think this is confusing (and Andrew apparently thinks so too [1]).
Add a new "all_objfiles_removed" observer to remove the second role from
"new_objfile".
Some existing users of new_objfile do nothing if the passed objfile is
nullptr. For them, we can simply drop the nullptr check. For others,
add a new all_objfiles_removed callback, and refactor things a bit to
keep the existing behavior as much as possible.
Some callbacks relied on current_program_space, and following
the refactoring now use either objfile->pspace or the pspace passed to
all_objfiles_removed. I think this should be relatively safe, and in
general a step in the right direction.
On the notify side, I found only one call site to change from
new_objfile to all_objfiles_removed, in clear_symtab_users. It is not
entirely clear to me that this is entirely correct. clear_symtab_users
appears to be called in spots that don't remove all objfiles
(functions finish_new_objfile, remove_symbol_file_command, reread_symbols,
do_module_cleanups). But I think that this patch at least makes the
current code clearer.
[1] a0a031bce0
Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
@@ -1138,7 +1138,11 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name)
|
||||
}
|
||||
}
|
||||
|
||||
/* Load any auto-loaded scripts for OBJFILE. */
|
||||
/* Load any auto-loaded scripts for OBJFILE.
|
||||
|
||||
Two flavors of auto-loaded scripts are supported.
|
||||
1) based on the path to the objfile
|
||||
2) from .debug_gdb_scripts section */
|
||||
|
||||
void
|
||||
load_auto_scripts_for_objfile (struct objfile *objfile)
|
||||
@@ -1160,25 +1164,6 @@ load_auto_scripts_for_objfile (struct objfile *objfile)
|
||||
auto_load_section_scripts (objfile, AUTO_SECTION_NAME);
|
||||
}
|
||||
|
||||
/* This is a new_objfile observer callback to auto-load scripts.
|
||||
|
||||
Two flavors of auto-loaded scripts are supported.
|
||||
1) based on the path to the objfile
|
||||
2) from .debug_gdb_scripts section */
|
||||
|
||||
static void
|
||||
auto_load_new_objfile (struct objfile *objfile)
|
||||
{
|
||||
if (!objfile)
|
||||
{
|
||||
/* OBJFILE is NULL when loading a new "main" symbol-file. */
|
||||
clear_section_scripts (current_program_space);
|
||||
return;
|
||||
}
|
||||
|
||||
load_auto_scripts_for_objfile (objfile);
|
||||
}
|
||||
|
||||
/* Collect scripts to be printed in a vec. */
|
||||
|
||||
struct collect_matching_scripts_data
|
||||
@@ -1531,9 +1516,11 @@ _initialize_auto_load ()
|
||||
python_name_help, guile_name_help;
|
||||
const char *suffix;
|
||||
|
||||
gdb::observers::new_objfile.attach (auto_load_new_objfile,
|
||||
gdb::observers::new_objfile.attach (load_auto_scripts_for_objfile,
|
||||
auto_load_new_objfile_observer_token,
|
||||
"auto-load");
|
||||
gdb::observers::all_objfiles_removed.attach (clear_section_scripts,
|
||||
"auto-load");
|
||||
add_setshow_boolean_cmd ("gdb-scripts", class_support,
|
||||
&auto_load_gdb_scripts, _("\
|
||||
Enable or disable auto-loading of canned sequences of commands scripts."), _("\
|
||||
|
||||
Reference in New Issue
Block a user