From 75336a5a2aa345953d0a9de73205457b6d9e27c2 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 20 Mar 2021 17:23:40 -0600 Subject: [PATCH] Move psymbol_map out of objfile objfile::psymbol_map is used to implement a Rust feature. It is currently specific to partial symbols -- it isn't used by the DWARF indices. This patch moves it out of objfile and into psymbol_functions, adding a new method to quick_symbol_functions to handle the clearing case. This is needed because the map holds unrelocated addresses. gdb/ChangeLog 2021-03-20 Tom Tromey * quick-symbol.h (struct quick_symbol_functions) : New method. * psymtab.h (struct psymbol_functions) : New method. : Declare method. : New member. * psymtab.c (psymbol_functions::fill_psymbol_map): Rename. (psymbol_functions::find_compunit_symtab_by_address): Update. * objfiles.h (reset_psymtabs): Don't clear psymbol_map. (struct objfile) : Remove. * objfiles.c (objfile_relocate1): Update. --- gdb/ChangeLog | 14 ++++++++++++++ gdb/objfiles.c | 6 +++--- gdb/objfiles.h | 6 ------ gdb/psympriv.h | 17 +++++++++++++++++ gdb/psymtab.c | 37 +++++++++++++++++++------------------ gdb/quick-symbol.h | 7 +++++++ 6 files changed, 60 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1ab402b60ea..14440e73c51 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2021-03-20 Tom Tromey + + * quick-symbol.h (struct quick_symbol_functions) + : New method. + * psymtab.h (struct psymbol_functions) : New + method. + : Declare method. + : New member. + * psymtab.c (psymbol_functions::fill_psymbol_map): Rename. + (psymbol_functions::find_compunit_symtab_by_address): Update. + * objfiles.h (reset_psymtabs): Don't clear psymbol_map. + (struct objfile) : Remove. + * objfiles.c (objfile_relocate1): Update. + 2021-03-20 Tom Tromey * psympriv.h (struct psymbol_functions): New. diff --git a/gdb/objfiles.c b/gdb/objfiles.c index f18f6158fc3..bfa5f0443e3 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -703,9 +703,9 @@ objfile_relocate1 (struct objfile *objfile, } } - /* This stores relocated addresses and so must be cleared. This - will cause it to be recreated on demand. */ - objfile->psymbol_map.clear (); + /* Notify the quick symbol object. */ + if (objfile->qf) + objfile->qf->relocated (); /* Relocate isolated symbols. */ { diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 7235713cbdf..cd136eef788 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -459,7 +459,6 @@ public: void reset_psymtabs () { - psymbol_map.clear (); partial_symtabs.reset (new psymtab_storage ()); } @@ -665,11 +664,6 @@ public: struct obstack objfile_obstack {}; - /* Map symbol addresses to the partial symtab that defines the - object at that address. */ - - std::vector> psymbol_map; - /* Structure which keeps track of functions that manipulate objfile's of the same type as this objfile. I.e. the function to read partial symbols for example. Note that this structure is in statically diff --git a/gdb/psympriv.h b/gdb/psympriv.h index 6b9ee184e9c..73f00a50992 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -535,6 +535,23 @@ struct psymbol_functions : public quick_symbol_functions void map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, void *data, int need_fullname) override; + + void relocated () override + { + m_psymbol_map.clear (); + } + +private: + + void fill_psymbol_map (struct objfile *objfile, + struct partial_symtab *psymtab, + std::set *seen_addrs, + const std::vector &symbols); + + /* Map symbol addresses to the partial symtab that defines the + object at that address. */ + + std::vector> m_psymbol_map; }; #endif /* PSYMPRIV_H */ diff --git a/gdb/psymtab.c b/gdb/psymtab.c index c022daa7894..45a4db71c1f 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1346,13 +1346,14 @@ psymbol_functions::has_symbols (struct objfile *objfile) } /* Helper function for psym_find_compunit_symtab_by_address that fills - in psymbol_map for a given range of psymbols. */ + in m_psymbol_map for a given range of psymbols. */ -static void -psym_fill_psymbol_map (struct objfile *objfile, - struct partial_symtab *psymtab, - std::set *seen_addrs, - const std::vector &symbols) +void +psymbol_functions::fill_psymbol_map + (struct objfile *objfile, + struct partial_symtab *psymtab, + std::set *seen_addrs, + const std::vector &symbols) { for (partial_symbol *psym : symbols) { @@ -1362,7 +1363,7 @@ psym_fill_psymbol_map (struct objfile *objfile, if (seen_addrs->find (addr) == seen_addrs->end ()) { seen_addrs->insert (addr); - objfile->psymbol_map.emplace_back (addr, psymtab); + m_psymbol_map.emplace_back (addr, psymtab); } } } @@ -1375,23 +1376,23 @@ compunit_symtab * psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile, CORE_ADDR address) { - if (objfile->psymbol_map.empty ()) + if (m_psymbol_map.empty ()) { std::set seen_addrs; for (partial_symtab *pst : require_partial_symbols (objfile, true)) { - psym_fill_psymbol_map (objfile, pst, - &seen_addrs, - pst->global_psymbols); - psym_fill_psymbol_map (objfile, pst, - &seen_addrs, - pst->static_psymbols); + fill_psymbol_map (objfile, pst, + &seen_addrs, + pst->global_psymbols); + fill_psymbol_map (objfile, pst, + &seen_addrs, + pst->static_psymbols); } - objfile->psymbol_map.shrink_to_fit (); + m_psymbol_map.shrink_to_fit (); - std::sort (objfile->psymbol_map.begin (), objfile->psymbol_map.end (), + std::sort (m_psymbol_map.begin (), m_psymbol_map.end (), [] (const std::pair &a, const std::pair &b) { @@ -1400,14 +1401,14 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile, } auto iter = std::lower_bound - (objfile->psymbol_map.begin (), objfile->psymbol_map.end (), address, + (m_psymbol_map.begin (), m_psymbol_map.end (), address, [] (const std::pair &a, CORE_ADDR b) { return a.first < b; }); - if (iter == objfile->psymbol_map.end () || iter->first != address) + if (iter == m_psymbol_map.end () || iter->first != address) return NULL; return psymtab_to_symtab (objfile, iter->second); diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 85e7a32eacd..319ffe681c8 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -228,6 +228,13 @@ struct quick_symbol_functions virtual void map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, void *data, int need_fullname) = 0; + + /* This is called when the objfile is relocated. It can be used to + clean up any internal caches. */ + virtual void relocated () + { + /* Do nothing. */ + } }; typedef std::unique_ptr quick_symbol_functions_up; -- 2.30.2