From 343cc95202fce70383551053f2efab09c5e02366 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 1 Nov 2019 21:02:38 -0600 Subject: [PATCH] Move free_all_objfiles to program_space This changes free_all_objfiles to be a method on program_space, in line with the other changes to treat program_space as a container for objfiles. gdb/ChangeLog 2019-12-12 Tom Tromey * symfile.c (symbol_file_clear): Update. * progspace.h (struct program_space) : Declare method. * progspace.c (program_space::free_all_objfiles): New method. * objfiles.h (free_all_objfiles): Don't declare. * objfiles.c (free_all_objfiles): Move to program_space. Change-Id: I908b549d2981b6005f7ca181fc0e6d24fc8b7b6f --- gdb/ChangeLog | 9 +++++++++ gdb/objfiles.c | 15 --------------- gdb/objfiles.h | 2 -- gdb/progspace.c | 18 ++++++++++++++++++ gdb/progspace.h | 3 +++ gdb/symfile.c | 2 +- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9b96f3d8fd9..9c1322d2a0d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2019-12-12 Tom Tromey + + * symfile.c (symbol_file_clear): Update. + * progspace.h (struct program_space) : Declare + method. + * progspace.c (program_space::free_all_objfiles): New method. + * objfiles.h (free_all_objfiles): Don't declare. + * objfiles.c (free_all_objfiles): Move to program_space. + 2019-12-12 Tom Tromey * progspace.c (program_space::add_objfile) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 31265c1653d..56854cc5c63 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -618,21 +618,6 @@ objfile::~objfile () get_objfile_pspace_data (pspace)->section_map_dirty = 1; } -/* Free all the object files at once and clean up their users. */ - -void -free_all_objfiles (void) -{ - struct so_list *so; - - /* Any objfile reference would become stale. */ - for (so = master_so_list (); so; so = so->next) - gdb_assert (so->objfile == NULL); - - for (objfile *objfile : current_program_space->objfiles_safe ()) - objfile->unlink (); - clear_symtab_users (0); -} /* A helper function for objfile_relocate1 that relocates a single symbol. */ diff --git a/gdb/objfiles.h b/gdb/objfiles.h index f9bf102bc80..34240558da3 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -662,8 +662,6 @@ extern void build_objfile_section_table (struct objfile *); extern void free_objfile_separate_debug (struct objfile *); -extern void free_all_objfiles (void); - extern void objfile_relocate (struct objfile *, const struct section_offsets *); extern void objfile_rebase (struct objfile *, CORE_ADDR); diff --git a/gdb/progspace.c b/gdb/progspace.c index d1bf0c6aba3..3cb0d4c61e3 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -23,6 +23,7 @@ #include "arch-utils.h" #include "gdbcore.h" #include "solib.h" +#include "solist.h" #include "gdbthread.h" #include "inferior.h" #include @@ -156,6 +157,23 @@ program_space::~program_space () /* See progspace.h. */ +void +program_space::free_all_objfiles () +{ + struct so_list *so; + + /* Any objfile reference would become stale. */ + for (so = master_so_list (); so; so = so->next) + gdb_assert (so->objfile == NULL); + + while (!objfiles_list.empty ()) + objfiles_list.front ()->unlink (); + + clear_symtab_users (0); +} + +/* See progspace.h. */ + void program_space::add_objfile (struct objfile *objfile, struct objfile *before) { diff --git a/gdb/progspace.h b/gdb/progspace.h index a731eb6e24d..6945e38eb92 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -179,6 +179,9 @@ struct program_space return objfiles_list.size () > 1; } + /* Free all the objfiles associated with this program space. */ + void free_all_objfiles (); + /* Pointer to next in linked list. */ struct program_space *next = NULL; diff --git a/gdb/symfile.c b/gdb/symfile.c index 965237191ad..8852e2893a4 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1251,7 +1251,7 @@ symbol_file_clear (int from_tty) objfiles get stale by free_all_objfiles. */ no_shared_libraries (NULL, from_tty); - free_all_objfiles (); + current_program_space->free_all_objfiles (); gdb_assert (symfile_objfile == NULL); if (from_tty) -- 2.30.2