From: Jan Vrany Date: Mon, 17 Nov 2025 10:15:28 +0000 (+0000) Subject: gdb: change search_symtab helper to be a method X-Git-Tag: binutils-2_46~911 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8343ee09a258f0af9815a713b699aa4bf75ba68c;p=thirdparty%2Fbinutils-gdb.git gdb: change search_symtab helper to be a method This commit changes search_symtab helper in find_symbol_at_address to be a method. Approved-By: Tom Tromey --- diff --git a/gdb/block.c b/gdb/block.c index c518f6c4f17..9fb04635975 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -840,6 +840,25 @@ blockvector::contains (CORE_ADDR addr) const return lookup (addr) != nullptr; } +/* See block.h. */ + +struct symbol * +blockvector::symbol_at_address (CORE_ADDR addr) const +{ + for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) + { + const struct block *b = block (i); + + for (struct symbol *sym : block_iterator_range (b)) + { + if (sym->loc_class () == LOC_STATIC && sym->value_address () == addr) + return sym; + } + } + + return nullptr; +} + blockvector::~blockvector () { for (struct block *bl : m_blocks) diff --git a/gdb/block.h b/gdb/block.h index f12e9d16263..df03231ca4c 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -509,6 +509,10 @@ struct blockvector /* Return true if the blockvector contains ADDR, false otherwise. */ bool contains (CORE_ADDR addr) const; + /* Return symbol at ADDR or NULL if no symbol is found. Only exact matches + for ADDR are considered. */ + struct symbol *symbol_at_address (CORE_ADDR addr) const; + private: /* An address map mapping addresses to blocks in this blockvector. This pointer is zero if the blocks' start and end addresses are diff --git a/gdb/symtab.c b/gdb/symtab.c index 1d9a06a52f3..070d9498034 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -505,6 +505,14 @@ compunit_symtab::forget_cached_source_info () /* See symtab.h. */ +struct symbol * +compunit_symtab::symbol_at_address (CORE_ADDR addr) const +{ + return blockvector ()->symbol_at_address (addr); +} + +/* See symtab.h. */ + compunit_symtab::compunit_symtab (struct objfile *objfile, const char *name_) : m_objfile (objfile), @@ -2831,26 +2839,6 @@ find_compunit_symtab_for_pc (CORE_ADDR pc) struct symbol * find_symbol_at_address (CORE_ADDR address) { - /* A helper function to search a given symtab for a symbol matching - ADDR. */ - auto search_symtab = [] (compunit_symtab *symtab, CORE_ADDR addr) -> symbol * - { - const struct blockvector *bv = symtab->blockvector (); - - for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) - { - const struct block *b = bv->block (i); - - for (struct symbol *sym : block_iterator_range (b)) - { - if (sym->loc_class () == LOC_STATIC - && sym->value_address () == addr) - return sym; - } - } - return nullptr; - }; - for (objfile &objfile : current_program_space->objfiles ()) { /* If this objfile was read with -readnow, then we need to @@ -2859,7 +2847,8 @@ find_symbol_at_address (CORE_ADDR address) { for (compunit_symtab &symtab : objfile.compunits ()) { - struct symbol *sym = search_symtab (&symtab, address); + struct symbol *sym + = symtab.symbol_at_address (address); if (sym != nullptr) return sym; } @@ -2870,7 +2859,7 @@ find_symbol_at_address (CORE_ADDR address) = objfile.find_compunit_symtab_by_address (address); if (symtab != NULL) { - struct symbol *sym = search_symtab (symtab, address); + struct symbol *sym = symtab->symbol_at_address (address); if (sym != nullptr) return sym; } diff --git a/gdb/symtab.h b/gdb/symtab.h index 9c7fe0fbf1a..845c49e057d 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1963,6 +1963,10 @@ struct compunit_symtab : intrusive_list_node /* Clear any cached source file names. */ void forget_cached_source_info (); + /* Return symbol at ADDR or NULL if no symbol is found. Only exact matches + for ADDR are considered. */ + struct symbol *symbol_at_address (CORE_ADDR addr) const; + /* Object file from which this symtab information was read. */ struct objfile *m_objfile;