From: Jan Vrany Date: Mon, 17 Nov 2025 10:15:28 +0000 (+0000) Subject: gdb: change find_compunit_symtab_by_address to find_symbol_by_address X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=722640cbad90c7b97f7262b43bd62f88749cf3f9;p=thirdparty%2Fbinutils-gdb.git gdb: change find_compunit_symtab_by_address to find_symbol_by_address This commit changes objfile::find_compunit_symtab_by_address and corresponding quick_symbol_functions::find_compunit_symtab_by_address to find_symbol_by_address return symbol. This will allow simplifying find_symbol_at_address (the only caller of find_compunit_symtab_by_address) by removing the special-case for -readnow and moving the logic down to readnow_functions. Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 8d11430dd8d..f9ac4519b6f 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -196,7 +196,7 @@ struct cooked_index_functions : public dwarf2_base_index_functions return table; } - struct compunit_symtab *find_compunit_symtab_by_address + struct symbol *find_symbol_by_address (struct objfile *objfile, CORE_ADDR address) override; bool has_unexpanded_symtabs (struct objfile *objfile) override diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 29f100b7638..7a2564c20a4 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -14556,8 +14556,8 @@ cutu_reader::read_toplevel_die (gdb::array_view extra_attrs) return die; } -struct compunit_symtab * -cooked_index_functions::find_compunit_symtab_by_address +struct symbol * +cooked_index_functions::find_symbol_by_address (struct objfile *objfile, CORE_ADDR address) { if (objfile->sect_index_data == -1) @@ -14572,7 +14572,9 @@ cooked_index_functions::find_compunit_symtab_by_address if (per_cu == nullptr) return nullptr; - return dw2_instantiate_symtab (per_cu, per_objfile, false); + struct compunit_symtab *cu = dw2_instantiate_symtab (per_cu, per_objfile, + false); + return cu->symbol_at_address (address); } bool diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 95f00e617c7..992d60528cd 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -1219,7 +1219,7 @@ struct dwarf2_base_index_functions : public quick_symbol_functions CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override; - struct compunit_symtab *find_compunit_symtab_by_address + struct symbol *find_symbol_by_address (struct objfile *objfile, CORE_ADDR address) override { return nullptr; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 35ef6035bc7..31651c4ee57 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -640,7 +640,7 @@ public: void compute_main_name (); /* See quick_symbol_functions. */ - struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address); + struct symbol *find_symbol_by_address (CORE_ADDR address); /* See quick_symbol_functions. */ enum language lookup_global_symbol_language (const char *name, diff --git a/gdb/psymtab.h b/gdb/psymtab.h index ab4173ddc3f..8a66f99754c 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -642,7 +642,7 @@ struct psymbol_functions : public quick_symbol_functions (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override; - struct compunit_symtab *find_compunit_symtab_by_address + struct symbol *find_symbol_by_address (struct objfile *objfile, CORE_ADDR address) override { return nullptr; diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 34dc60bc2c2..4ac1067e96d 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -176,12 +176,10 @@ struct quick_symbol_functions (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc, struct obj_section *section, int warn_if_readin) = 0; - /* Return the comp unit from OBJFILE that contains a symbol at - ADDRESS. Return NULL if there is no such comp unit. Unlike - find_pc_sect_compunit_symtab, any sort of symbol (not just text - symbols) can be considered, and only exact address matches are - considered. */ - virtual struct compunit_symtab *find_compunit_symtab_by_address + /* Return the symbol from OBJFILE at ADDRESS. Return NULL if there is + no such symbol. Any sort of symbol (not just text symbols) can be + considered, and only exact address matches are considered. */ + virtual struct symbol *find_symbol_by_address (struct objfile *objfile, CORE_ADDR address) = 0; /* Call FUN for every file defined in OBJFILE whose symtab is diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index e5ea7264997..68dbc9eca42 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -480,28 +480,28 @@ objfile::compute_main_name () iter->compute_main_name (this); } -struct compunit_symtab * -objfile::find_compunit_symtab_by_address (CORE_ADDR address) +struct symbol * +objfile::find_symbol_by_address (CORE_ADDR address) { if (debug_symfile) gdb_printf (gdb_stdlog, - "qf->find_compunit_symtab_by_address (%s, %s)\n", + "qf->find_symbol_by_address (%s, %s)\n", objfile_debug_name (this), hex_string (address)); - struct compunit_symtab *result = NULL; + struct symbol *result = NULL; for (const auto &iter : qf) { - result = iter->find_compunit_symtab_by_address (this, address); + result = iter->find_symbol_by_address (this, address); if (result != nullptr) break; } if (debug_symfile) gdb_printf (gdb_stdlog, - "qf->find_compunit_symtab_by_address (...) = %s\n", + "qf->find_symbol_by_address (...) = %s\n", result - ? debug_symtab_name (result->primary_filetab ()) + ? result->print_name () : "NULL"); return result; diff --git a/gdb/symtab.c b/gdb/symtab.c index 070d9498034..2634e8fe5c2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2855,14 +2855,9 @@ find_symbol_at_address (CORE_ADDR address) } else { - struct compunit_symtab *symtab - = objfile.find_compunit_symtab_by_address (address); - if (symtab != NULL) - { - struct symbol *sym = symtab->symbol_at_address (address); - if (sym != nullptr) - return sym; - } + struct symbol *sym = objfile.find_symbol_by_address (address); + if (sym != nullptr) + return sym; } }