From: Jan Vrany Date: Fri, 9 Jan 2026 12:47:17 +0000 (+0000) Subject: gdb: introduce expanded_symbols_functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77aa0f0be758e393fb37eb87b2c400c20d5daa49;p=thirdparty%2Fbinutils-gdb.git gdb: introduce expanded_symbols_functions This commit adds new "quick" symbol functions, expanded_symbols_functions, that work purely on examining objfile's compunits. This is useful for example for JIT reader API where symbols are created by user-provided code. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33554 Approved-By: Tom Tromey --- diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 9787cae2601..a2413595983 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1104,6 +1104,7 @@ COMMON_SFILES = \ event-top.c \ exceptions.c \ exec.c \ + expanded-symbol.c \ expprint.c \ extension.c \ f-lang.c \ diff --git a/gdb/expanded-symbol.c b/gdb/expanded-symbol.c new file mode 100644 index 00000000000..2fa601ca85a --- /dev/null +++ b/gdb/expanded-symbol.c @@ -0,0 +1,114 @@ +/* An implementation of "quick" symbol functions for already expanded + symbol tables. + + Copyright (C) 2026-2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "objfiles.h" +#include "symtab.h" +#include "source.h" +#include "expanded-symbol.h" + +/* See readnow-symbols.h. */ + +struct symtab * +expanded_symbols_functions::find_last_source_symtab (struct objfile *objfile) +{ + if (objfile->compunit_symtabs.empty ()) + return nullptr; + else + return objfile->compunit_symtabs.back ().primary_filetab (); +} + +/* See readnow-symbols.h. */ + +enum language +expanded_symbols_functions::lookup_global_symbol_language ( + struct objfile *objfile, const char *name, domain_search_flags domain, + bool *symbol_found_p) +{ + *symbol_found_p = false; + return language_unknown; +} + +/* See readnow-symbols.h. */ + +bool +expanded_symbols_functions::search (struct objfile *objfile, + search_symtabs_file_matcher file_matcher, + const lookup_name_info *lookup_name, + search_symtabs_symbol_matcher symbol_matcher, + search_symtabs_expansion_listener listener, + block_search_flags search_flags, + domain_search_flags domain, + search_symtabs_lang_matcher lang_matcher) +{ + /* This invariant is documented in quick-functions.h. */ + gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); + + for (compunit_symtab &cu : objfile->compunits ()) + { + if (lang_matcher != nullptr && !lang_matcher (cu.language ())) + continue; + + if (file_matcher != nullptr) + { + bool matched = false; + for (auto st : cu.filetabs ()) + { + if (file_matcher (st->filename (), false)) + { + matched = true; + break; + } + if ((basenames_may_differ + || file_matcher (lbasename (st->filename ()), true)) + && file_matcher (symtab_to_fullname (st), false)) + { + matched = true; + break; + } + } + if (!matched) + continue; + } + + /* Here we simply call the listener (if any) without bothering to + consult lookup_name and symbol_matcher (if any). This should be + okay since i) all symtabs are already expanded and ii) listeners + iterate over matching symbols themselves. */ + if (listener != nullptr && !listener (&cu)) + return false; + } + return true; +} + +/* See readnow-symbols.h. */ + +struct symbol * +expanded_symbols_functions::find_symbol_by_address (struct objfile *objfile, + CORE_ADDR address) +{ + for (compunit_symtab &symtab : objfile->compunits ()) + { + struct symbol *sym = symtab.symbol_at_address (address); + if (sym != nullptr) + return sym; + } + + return nullptr; +} diff --git a/gdb/expanded-symbol.h b/gdb/expanded-symbol.h new file mode 100644 index 00000000000..89fa532d1dd --- /dev/null +++ b/gdb/expanded-symbol.h @@ -0,0 +1,92 @@ +/* An implementation of "quick" symbol functions for already expanded + symbol tables. + + Copyright (C) 2026-2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GDB_EXPANDED_SYMBOL_H +#define GDB_EXPANDED_SYMBOL_H + +#include "quick-symbol.h" + +/* An implementation of "quick" symbol functions that relies solely only on + already present symtabs. This is useful in cases where symbols are created + eagerly by user-provided code (such as when using JIT reader API). */ + +struct expanded_symbols_functions : public quick_symbol_functions +{ + bool has_symbols (struct objfile *objfile) override + { + return true; + } + + bool has_unexpanded_symtabs (struct objfile *objfile) override + { + return false; + } + + struct symtab *find_last_source_symtab (struct objfile *objfile) override; + + void forget_cached_source_info (struct objfile *objfile) override + { + } + + enum language lookup_global_symbol_language (struct objfile *objfile, + const char *name, + domain_search_flags domain, + bool *symbol_found_p) override; + void print_stats (struct objfile *objfile, bool print_bcache) override + { + } + + void dump (struct objfile *objfile) override + { + } + + void expand_all_symtabs (struct objfile *objfile) override + { + } + + bool search (struct objfile *objfile, + search_symtabs_file_matcher file_matcher, + const lookup_name_info *lookup_name, + search_symtabs_symbol_matcher symbol_matcher, + search_symtabs_expansion_listener listener, + block_search_flags search_flags, domain_search_flags domain, + search_symtabs_lang_matcher lang_matcher) override; + + struct compunit_symtab *find_pc_sect_compunit_symtab + (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc, + struct obj_section *section, int warn_if_readin) override + { + /* Simply returning NULL here is okay since the (only) caller + find_compunit_symtab_for_pc_sect interates over existing CUs + anyway. */ + return nullptr; + } + + struct symbol *find_symbol_by_address (struct objfile *objfile, + CORE_ADDR address) override; + + void map_symbol_filenames (objfile *objfile, symbol_filename_listener fun, + bool need_fullname) override + { + } +}; + + +#endif /* GDB_EXPANDED_SYMBOL_H */