diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-10-03 22:20:21 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-10-05 13:20:50 -0400 |
commit | 74daa597e743462d272522512efbe3f65659c4c0 (patch) | |
tree | 4a264692ec166433ac1cccae229566b85e1a48ac /gdb/auxv.c | |
parent | 74ce4f8ecf8b9b3a41821eec73b8952447e84eef (diff) | |
download | gdb-74daa597e743462d272522512efbe3f65659c4c0.zip gdb-74daa597e743462d272522512efbe3f65659c4c0.tar.gz gdb-74daa597e743462d272522512efbe3f65659c4c0.tar.bz2 |
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] https://gitlab.com/gnutools/binutils-gdb/-/commit/a0a031bce0527b1521788b5dad640e7883b3a252
Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/auxv.c')
-rw-r--r-- | gdb/auxv.c | 22 |
1 files changed, 7 insertions, 15 deletions
@@ -344,23 +344,14 @@ invalidate_auxv_cache_inf (struct inferior *inf) auxv_inferior_data.clear (inf); } -/* Invalidate current inferior's auxv cache when all symbol table data is - cleared (indicated by OBJFILE being nullptr). */ +/* Invalidate the auxv cache for all inferiors using PSPACE. */ static void -auxv_new_objfile_observer (struct objfile *objfile) +auxv_all_objfiles_removed (program_space *pspace) { - if (objfile == nullptr) - { - /* When OBJFILE is nullptr, this indicates that all symbol files have - been unloaded from the current program space. Discard cached auxv - information from any inferior within the effected program space. */ - for (inferior *inf : all_inferiors ()) - { - if (inf->pspace == current_program_space) - invalidate_auxv_cache_inf (inf); - } - } + for (inferior *inf : all_inferiors ()) + if (inf->pspace == current_program_space) + invalidate_auxv_cache_inf (inf); } /* See auxv.h. */ @@ -624,5 +615,6 @@ This is information provided by the operating system at program startup.")); /* Observers used to invalidate the auxv cache when needed. */ gdb::observers::inferior_exit.attach (invalidate_auxv_cache_inf, "auxv"); gdb::observers::inferior_appeared.attach (invalidate_auxv_cache_inf, "auxv"); - gdb::observers::new_objfile.attach (auxv_new_objfile_observer, "auxv"); + gdb::observers::all_objfiles_removed.attach (auxv_all_objfiles_removed, + "auxv"); } |