aboutsummaryrefslogtreecommitdiff
path: root/gdb/objfiles.h
AgeCommit message (Collapse)AuthorFilesLines
2024-01-28Use domain_search_flags in lookup_symbol et alTom Tromey1-1/+1
This changes lookup_symbol and associated APIs to accept domain_search_flags rather than a domain_enum. Note that this introduces some new constants to Python and Guile. I chose to break out the documentation patch for this, because the internals here do not change until a later patch, and it seemed simpler to patch the docs just once, rather than twice.
2024-01-28Use domain_search_flags in lookup_global_symbol_languageTom Tromey1-3/+2
This changes quick_symbol_functions::lookup_global_symbol_language to accept domain_search_flags rather than just a domain_enum, and fixes up the fallout. To avoid introducing any regressions, any code passing VAR_DOMAIN now uses SEARCH_VFT. That is, no visible changes should result from this patch. However, it sets the stage to refine some searches later on.
2024-01-28Replace search_domain with domain_search_flagsTom Tromey1-1/+1
This patch changes gdb to replace search_domain with domain_search_flags everywhere. search_domain is removed.
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-1/+1
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2024-01-08Remove two quick_symbol_functions methodsTom Tromey1-14/+0
quick_symbol_functions::read_partial_symbols is no longer implemented, so both it and quick_symbol_functions::can_lazily_read_symbols can be removed. This allows for other functions to be removed as well. Note that SYMFILE_NO_READ is now pretty much dead. I haven't removed it here -- but could if that's desirable. I tend to think that this functionality would be better implemented in the core; but whenever I dive into the non-DWARF readers it is pretty depressing.
2024-01-08Add quick_symbol_functions::compute_main_nameTom Tromey1-0/+3
This adds a new compute_main_name method to quick_symbol_functions. Currently there are no implementations of this, but a subsequent patch will add one.
2023-12-06Remove quick_symbol_functions::expand_matching_symbolsTom Tromey1-6/+0
The only caller of quick_symbol_functions::expand_matching_symbols was removed, so now this method and all implementations of it can be removed.
2023-11-14gdb: merge debug symbol file lookup code from coffread & elfread pathsAndrew Burgess1-0/+10
This commit merges the code that looks for and loads the separate debug symbol files from coffread.c and elfread.c. The factored out code is moved into a new objfile::find_and_add_separate_symbol_file() method. For the elfread.c path there should be no user visible changes after this commit. For the coffread.c path GDB will now attempt to perform a debuginfod lookup for the missing debug information, assuming that GDB can find a build-id in the COFF file. I don't know if COFF files can include a build-id, but I the existing coffread.c code already includes a call to find_separate_debug_file_by_build-id, so I know that it is at least OK for GDB to ask a COFF file for a build-id. If the COFF file doesn't include a build-id then the debuginfod lookup code will not trigger and the new code is harmless. If the COFF file does include a build-id, then we're going to end up asking debuginfod for the debug file. As build-ids should be unique, this should be harmless, even if debuginfod doesn't contain any suitable debug data, it just costs us one debuginfod lookup, so I'm not too worried about this for now. As with the previous commit, I've done some minimal testing using the mingw toolchain on a Linux machine, GDB seems to still access the split debug information just fine. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-20Remove explanatory comments from includesTom Tromey1-1/+1
I noticed a comment by an include and remembered that I think these don't really provide much value -- sometimes they are just editorial, and sometimes they are obsolete. I think it's better to just remove them. Tested by rebuilding. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-08-31[symtab/27831] Fix OBJF_MAINLINE assertKevin Buettner1-0/+11
This commit fixes a bug mentioned by Florian Weimer during the libpthread/ld.so load order discussion from 2021. Florian provided instructions for reproducing the bug here: https://sourceware.org/pipermail/gdb-patches/2021-April/177923.html That particular test does some interesting things involving forks, threads, and thread local storage. Fortunately, none of that is needed to reproduce the problem. I've made a new test case (which is now found in a separate commit) contained in the files gdb.base/add-symbol-file-attach.{c,exp}. The .c file is fairly simple as is the recipe for reproducing the problem. After separately starting the test case and noting the process id, start gdb (w/ no arguments), and do the following to reproduce the assertion failure - for this run, the process id of the separately started add-symbol-file-attach process is 4103218: (gdb) add-symbol-file add-symbol-file-attach add symbol table from file "add-symbol-file-attach" (y or n) y Reading symbols from add-symbol-file-attach... (gdb) attach 4103218 Attaching to process 4103218 Load new symbol table from "/tmp/add-symbol-file-attach"? (y or n) y Reading symbols from /tmp/add-symbol-file-attach... Reading symbols from /lib64/libc.so.6... (No debugging symbols found in /lib64/libc.so.6) Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007f502130bf27 in pause () from /lib64/libc.so.6 (gdb) p foo symtab.c:6417: internal-error: CORE_ADDR get_msymbol_address(objfile*, const minimal_symbol*): Assertion `(objf->flags & OBJF_MAINLINE) == 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. The add-symbol-file command causes the symbols to be loaded without the SYMFILE_MAINLINE (and hence the OBJFILE_MAINLINE) flags being set. This, in turn, causes the "maybe_copied" flag to be set for the global symbol (named "foo" in the provided test case). The attach command will cause another objfile to be created, but it will reuse the symtabs from the objfile created by add-symbol-file, leading to a situation in which the OBJFILE_MAINLINE flag will be set for the new (attach-created) objfile, however the "maybe_copied" flag will still be set for the global symbol. Had it been loaded anew, this flag would not be set due to OBJFILE_MAINLINE being set for the objfile. At present, minimal_symbol::value_address looks like this: CORE_ADDR minimal_symbol::value_address (objfile *objfile) const { if (this->maybe_copied (objfile)) return get_msymbol_address (objfile, this); else return (CORE_ADDR (this->unrelocated_address ()) + objfile->section_offsets[this->section_index ()]); } So, we can now see the problem: When the "maybe_copied" flag is set, get_msymbol_address() will be called. However, get_msymbol_address() assumes that it won't be called with the OBF_MAINLINE flag set for the objfile in question. It, in fact, contains an assert() which makes sure that this is the case: gdb_assert ((objf->flags & OBJF_MAINLINE) == 0); (If this assert is removed, then get_msymbol_address() recurses infinitely for the case under consideration.) So, the problem here is that the maybe_copied flag is set for the symbol AND the OBJF_MAINLINE flag is set for the objfile. As noted earlier, this happens due to add-symbol-file being used; this causes the maybe_copied flag to be set. Later, when the attach is performed, OBJF_MAINLINE will be set for that objfile, leading to this unfortunate situation. My first cut at a solution involved adjusting the MSYMBOL_VALUE_ADDRESS macro (which has since been changed to be the method noted above) to include a test of the OBJFILE_MAINLINE flag. However, Simon Marchi, in his review of my patch, suggested a better solution. Simon observed that the 'maybe_copied' flag is (was, after this commit) being set/initialized in record_minimal_symbol() using using the objfile in the context in which the symbol was created. Simon further observed: Today, a single copy is created, as symtabs are shared between objfiles. This means that everything that we store into a symbol must be independent of any objfile. However, the value of the maybe_copied field is dependent on the objfile in the context of which the symbol was created. Meaning that when the symbol is re-used in the context of another objfile, the maybe_copied value is not right in the context of that objfile. So I think it means there isn't a single "is this symbol maybe copied" value, but instead "is this symbol maybe copied, in the context of this given objfile". And the answer is yes or no, depending on whether the objfile is mainline. So maybe_copied should become a method that takes an objfile and returns an answer based on that. Simon's full review can be found here: https://sourceware.org/pipermail/gdb-patches/2021-May/178855.html Simon also provided a patch which implements this suggestion. The current patch is mostly his work, though I did make some adjustments during a rebase in addition to making some changes to account for a concern from Tom Tromey. During his review of the v3 series, Tom noted, "The old approach was specific to ELF, while the new approach will be used by any object format." Tom further observed, "...it seems like it could result in an incorrect evaluation in some scenario." This seemed plausible to me, so I introduced the flag 'object_format_has_copy_relocs' to struct objfile. It is set at the end of elf_symfile_read() in elfread.c. The minimal_symbol::maybe_copied method tests this new flag, forcing this method to return false when the flag is not set. If we find that other object file formats use the same copy reloc mechanism as ELF, then 'object_format_has_copy_relocs' should be set for objfiles using those formats. Lastly, I'll note that this is a strange use case. It's far more common to either let gdb figure out which file to load by itself when attaching, i.e. (gdb) attach 4104360 Attaching to process 4104360 Reading symbols from /tmp/add-symbol-file-attach... Reading symbols from /lib64/libc.so.6... (No debugging symbols found in /lib64/libc.so.6) Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007fdb1fc33f27 in pause () from /lib64/libc.so.6 (gdb) p foo $1 = 42 ...or to use the "file" command prior to the attach, like this: (gdb) file add-symbol-file-attach Reading symbols from add-symbol-file-attach... (gdb) attach 4104360 Attaching to program: /tmp/add-symbol-file-attach, process 4104360 Reading symbols from /lib64/libc.so.6... (No debugging symbols found in /lib64/libc.so.6) Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007fdb1fc33f27 in pause () from /lib64/libc.so.6 Both of these more common scenarios work perfectly fine; using "add-symbol-file" to load the program to which you will attach isn't recommended as a normal use case. That said, it's bad for gdb to assert, hence this fix. Reviewed-by: Simon Marchi <simon.marchi@polymtl.ca> Co-Authored-by: Simon Marchi <simon.marchi@polymtl.ca> Approved-by: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27831
2023-08-18Remove most includes of psymtab.hTom Tromey1-1/+0
I found that most spots including psymtab.h do not need it. This patch removes these includes, and also one unnecessary include of psympriv.h.
2023-05-07Remove ALL_OBJFILE_OSECTIONSTom Tromey1-46/+107
This replaces ALL_OBJFILE_OSECTIONS with an iterator so that for-each can be used.
2023-05-07Rename objfile::sectionsTom Tromey1-10/+10
I think objfile::sections makes sense as the name of the method to iterate over an objfile's sections, so this patch renames the existing field to objfile::sections_start in preparation for that.
2023-01-20Use bool in pc_in_* functionsTom Tromey1-2/+2
I noticed that pc_in_unmapped_range had a weird return type -- it was returning a CORE_ADDR but intending to return a bool. This patch changes all the pc_in_* functions to return bool instead.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-12-08gdb: skip objfiles with no BFD in DWARF unwinderJan Vrany1-1/+3
While playing with JIT reader I experienced GDB to crash on null-pointer dereference when stepping through non-jitted code. The problem was that dwarf2_frame_find_fde () assumed that all objfiles have BFD but that's not always true. To address this problem, this commit skips such objfiles. To test the fix we put breakpoint in jit_function_add (). The JIT reader does not know how unwind this function so unwinding eventually falls back to DWARF unwinder which in turn iterates over objfiles. Since the the code is jitted, it is guaranteed it would eventually process JIT objfile. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-10-19internal_error: remove need to pass __FILE__/__LINE__Pedro Alves1-6/+3
Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-08-03Use unique_ptr to destroy per-bfd objectTom Tromey1-2/+7
In some cases, the objfile owns the per-bfd object. This is yet another object that can sometimes be destroyed before the registry is destroyed, possibly reslting in a use-after-free. Also, I noticed that the condition for deleting the object is not the same as the condition used to create it -- so it could possibly result in a memory leak in some situations. This patch fixes the problem by introducing a new unique_ptr that holds this object when necessary.
2022-08-03Use auto_obstack in objfileTom Tromey1-1/+1
This changes objfile to use an auto_obstack. This helps prevent use-after-free bugs, because it ensures that anything allocated on the objfile obstack will live past the point at which the registry object is destroyed.
2022-08-03Use gdb_bfd_ref_ptr in objfileTom Tromey1-6/+6
This changes struct objfile to use a gdb_bfd_ref_ptr. In addition to removing some manual memory management, this fixes a use-after-free that was introduced by the registry rewrite series. The issue there was that, in some cases, registry shutdown could refer to memory that had already been freed. This help fix the bug by delaying the destruction of the BFD reference (and thus the per-bfd object) until after the registry has been shut down.
2022-07-28Rewrite registry.hTom Tromey1-5/+1
This rewrites registry.h, removing all the macros and replacing it with relatively ordinary template classes. The result is less code than the previous setup. It replaces large macros with a relatively straightforward C++ class, and now manages its own cleanup. The existing type-safe "key" class is replaced with the equivalent template class. This approach ended up requiring relatively few changes to the users of the registry code in gdb -- code using the key system just required a small change to the key's declaration. All existing users of the old C-like API are now converted to use the type-safe API. This mostly involved changing explicit deletion functions to be an operator() in a deleter class. The old "save/free" two-phase process is removed, and replaced with a single "free" phase. No existing code used both phases. The old "free" callbacks took a parameter for the enclosing container object. However, this wasn't truly needed and is removed here as well.
2022-05-31Use unique_ptr for objfilesTom Tromey1-1/+1
A while back, I changed objfiles to be held via a shared_ptr. The idea at the time was that this was a step toward writing to the index cache in the background, and this would let gdb keep a reference alive to do so. However, since then we've rewritten the DWARF reader, and the new index can do this without requiring a shared pointer -- in fact there are patches pending to implement this. This patch switches objfile management to unique_ptr, which makes more sense now. Regression tested on x86-64 Fedora 34.
2022-05-26gdb: Require psymtab before calling quick_functions in objfileLancelot SIX1-0/+13
The recent DWARF indexer rewrite introduced a regression when debugging a forking program. Here is a way to reproduce the issue (there might be other ways, but one is enough and this one mimics the situation we encountered). Consider a program which forks, and the child loads a shared library and calls a function in this shared library: if (fork () == 0) { void *solib = dlopen (some_solib, RTLD_NOW); void (*foo) () = dlsym (some_solib, "foo"); foo (); } Suppose that this program is compiled without debug info, but the shared library it loads has debug info enabled. When debugging such program with the following options: - set detach-on-fork off - set follow-fork-mode child we see something like: (gdb) b foo Function "foo" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (foo) pending. (gdb) run Starting program: a.out [Attaching after process 19720 fork to child process 19723] [New inferior 2 (process 19723)] [Switching to process 19723] Thread 2.1 "a.out" hit Breakpoint 1, 0x00007ffff7fc3101 in foo () from .../libfoo.so (gdb) list Fatal signal: Segmentation fault ----- Backtrace ----- 0x55a278f77d76 gdb_internal_backtrace_1 ../../gdb/bt-utils.c:122 0x55a278f77f83 _Z22gdb_internal_backtracev ../../gdb/bt-utils.c:168 0x55a27940b83b handle_fatal_signal ../../gdb/event-top.c:914 0x55a27940bbb1 handle_sigsegv ../../gdb/event-top.c:987 0x7effec0343bf ??? /build/glibc-sMfBJT/glibc-2.31/nptl/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0x55a27924c9d3 _ZNKSt15__uniq_ptr_implI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE6_M_ptrEv /usr/include/c++/9/bits/unique_ptr.h:154 0x55a279248bc9 _ZNKSt10unique_ptrI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE3getEv /usr/include/c++/9/bits/unique_ptr.h:361 0x55a2792ae718 _ZN27dwarf2_base_index_functions23find_last_source_symtabEP7objfile ../../gdb/dwarf2/read.c:3164 0x55a279afb93e _ZN7objfile23find_last_source_symtabEv ../../gdb/symfile-debug.c:139 0x55a279aa3040 _Z20select_source_symtabP6symtab ../../gdb/source.c:365 0x55a279aa22a1 _Z34set_default_source_symtab_and_linev ../../gdb/source.c:268 0x55a27903c44c list_command ../../gdb/cli/cli-cmds.c:1185 0x55a279051233 do_simple_func ../../gdb/cli/cli-decode.c:95 0x55a27905f221 _Z8cmd_funcP16cmd_list_elementPKci ../../gdb/cli/cli-decode.c:2514 0x55a279c3b0ba _Z15execute_commandPKci ../../gdb/top.c:660 0x55a27940a6c3 _Z15command_handlerPKc ../../gdb/event-top.c:598 0x55a27940b032 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE ../../gdb/event-top.c:797 0x55a279caf401 tui_command_line_handler ../../gdb/tui/tui-interp.c:278 0x55a279409098 gdb_rl_callback_handler ../../gdb/event-top.c:230 0x55a279ed5df2 rl_callback_read_char ../../../readline/readline/callback.c:281 0x55a279408bd8 gdb_rl_callback_read_char_wrapper_noexcept ../../gdb/event-top.c:188 0x55a279408de7 gdb_rl_callback_read_char_wrapper ../../gdb/event-top.c:205 0x55a27940a061 _Z19stdin_event_handleriPv ../../gdb/event-top.c:525 0x55a27a23771e handle_file_event ../../gdbsupport/event-loop.cc:574 0x55a27a237f5f gdb_wait_for_event ../../gdbsupport/event-loop.cc:700 0x55a27a235d81 _Z16gdb_do_one_eventv ../../gdbsupport/event-loop.cc:237 0x55a2796c2ef0 start_event_loop ../../gdb/main.c:418 0x55a2796c3217 captured_command_loop ../../gdb/main.c:478 0x55a2796c717b captured_main ../../gdb/main.c:1340 0x55a2796c7217 _Z8gdb_mainP18captured_main_args ../../gdb/main.c:1355 0x55a278d0b381 main ../../gdb/gdb.c:32 --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. The first issue observed is in the message printed when hitting the breakpoint. It says that there was a break in the .so file as if there was no debug info associated with it, but there is. Later, if we try to display the source where the execution stopped, we have a segfault. Note that not having the debug info on the main binary is not strictly required to encounter some issues, it only is to encounter the segfault. If the main binary has debug information, GDB shows some source form the main binary, unrelated to where we stopped. The core of the issue is that GDB never loads the psymtab for the library. It is not loaded when we first see the .so because in case of detach-on-fork off, follow-fork-mode child, infrun.c sets child_inf->symfile_flags = SYMFILE_NO_READ to delay the psymtab loading as much as possible. If we compare to what was done to handle this before the new indexer was activated, the psymatb construction for the shared library was done under psymbol_functions::expand_symtabs_matching: bool psymbol_functions::expand_symtabs_matching (...) { for (partial_symtab *ps : require_partial_symbols (objfile)) ... } The new indexer's expand_symtabs_matching callback does not have a call to the objfile's require_partial_symbols, so if the partial symbol table is not loaded at this point, there is no mechanism to fix this. Instead of requiring each implementation of the quick_functions to check that partial symbols have been read, I think it is safer to enforce this when calling the quick functions. The general pattern for calling the quick functions is: for (auto *iter : qf) iter->the_actual_method_call (...) This patch proposes to wrap the access of the `qf` field with an accessor which ensures that partial symbols have been read before iterating: qf_require_partial_symbols. All calls to quick functions are updated except: - quick_functions::dump - quick_functions::read_partial_symbols (from objfile::require_partial_symbols) - quick_functions::can_lazily_read_symbols and quick_functions::has_symbols (from objfile::has_partial_symbols) Regression tested on x86_64-gnu-linux. Change-Id: I39a13a937fdbaae613a5cf68864b021000554546
2022-05-05gdb: use gdb::function_view for ↵Simon Marchi1-3/+2
gdbarch_iterate_over_objfiles_in_search_order callback A rather straightforward patch to change an instance of callback + void pointer to gdb::function_view, allowing pasing lambdas that capture, and eliminating the need for the untyped pointer. Change-Id: I73ed644e7849945265a2c763f79f5456695b0037
2022-01-18Move gdb obstack code to gdbsupportTom Tromey1-1/+1
This moves the gdb-specific obstack code -- both extensions like obconcat and obstack_strdup, and things like auto_obstack -- to gdbsupport.
2022-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker1-1/+1
This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
2021-10-18CTF: incorrect underlying type setting for enumeration typesWeimin Pan1-0/+5
A bug was filed against the incorrect underlying type setting for an enumeration type, which was caused by a copy and paste error. This patch fixes the problem by setting it by calling objfile_int_type, which was originally dwarf2_per_objfile::int_type, with ctf_type_size bits. Also add error checking on ctf_func_type_info call.
2021-07-30Use iterator_range in more placesTom Tromey1-50/+9
This changes a couple of spots to replace custom iterator range classes with a specialization of iterator_range. Regression tested on x86-64 Fedora 34.
2021-07-06gdb: introduce iterator_range, remove next_adapterSimon Marchi1-4/+2
I was always a bit confused by next_adapter, because it kind of mixes the element type and the iterator type. In reality, it is not much more than a class that wraps two iterators (begin and end). However, it assumes that: - you can construct the begin iterator by passing a pointer to the first element of the iterable - you can default-construct iterator to make the end iterator I think that by generalizing it a little bit, we can re-use it at more places. Rename it to "iterator_range". I think it describes a bit better: it's a range made by wrapping a begin and end iterator. Move it to its own file, since it's not related to next_iterator anymore. iterator_range has two constructors. The variadic one, where arguments are forwarded to construct the underlying begin iterator. The end iterator is constructed through default construction. This is a generalization of what we have today. There is another constructor which receives already constructed begin and end iterators, useful if the end iterator can't be obtained by default-construction. Or, if you wanted to make a range that does not end at the end of the container, you could pass any iterator as the "end". This generalization allows removing some "range" classes, like all_inferiors_range. These classes existed only to pass some arguments when constructing the begin iterator. With iterator_range, those same arguments are passed to the iterator_range constructed and then forwarded to the constructed begin iterator. There is a small functional difference in how iterator_range works compared to next_adapter. next_adapter stored the pointer it received as argument and constructeur an iterator in the `begin` method. iterator_range constructs the begin iterator and stores it as a member. Its `begin` method returns a copy of that iterator. With just iterator_range, uses of next_adapter<foo> would be replaced with: using foo_iterator = next_iterator<foo>; using foo_range = iterator_range<foo_iterator>; However, I added a `next_range` wrapper as a direct replacement for next_adapter<foo>. IMO, next_range is a slightly better name than next_adapter. The rest of the changes are applications of this new class. gdbsupport/ChangeLog: * next-iterator.h (class next_adapter): Remove. * iterator-range.h: New. gdb/ChangeLog: * breakpoint.h (bp_locations_range): Remove. (bp_location_range): New. (struct breakpoint) <locations>: Adjust type. (breakpoint_range): Use iterator_range. (tracepoint_range): Use iterator_range. * breakpoint.c (breakpoint::locations): Adjust return type. * gdb_bfd.h (gdb_bfd_section_range): Use iterator_range. * gdbthread.h (all_threads_safe): Pass argument to all_threads_safe_range. * inferior-iter.h (all_inferiors_range): Use iterator_range. (all_inferiors_safe_range): Use iterator_range. (all_non_exited_inferiors_range): Use iterator_range. * inferior.h (all_inferiors, all_non_exited_inferiors): Pass inferior_list as argument. * objfiles.h (struct objfile) <compunits_range>: Remove. <compunits>: Return compunit_symtab_range. * progspace.h (unwrapping_objfile_iterator) <unwrapping_objfile_iterator>: Take parameter by value. (unwrapping_objfile_range): Use iterator_range. (struct program_space) <objfiles_range>: Define with "using". <objfiles>: Adjust. <objfiles_safe_range>: Define with "using". <objfiles_safe>: Adjust. <solibs>: Return so_list_range, define here. * progspace.c (program_space::solibs): Remove. * psymtab.h (class psymtab_storage) <partial_symtab_iterator>: New. <partial_symtab_range>: Use iterator_range. * solist.h (so_list_range): New. * symtab.h (compunit_symtab_range): New. (symtab_range): New. (compunit_filetabs): Change to a function. * thread-iter.h (inf_threads_range, inf_non_exited_threads_range, safe_inf_threads_range, all_threads_safe_range): Use iterator_range. * top.h (ui_range): New. (all_uis): Use ui_range. Change-Id: Ib7a9d2a3547f45f01aa1c6b24536ba159db9b854
2021-06-28gdb: convert obj_section macros to methodsSimon Marchi1-31/+62
Convert these three macros to methods of obj_section. The problem fixed by the following patch is caused by an out of bound access of the objfile::section_offsets vector. Since this is deep in macros, we don't get a clear backtrace and it's difficult to debug. Changing that to methods means we can step in them and break on them. Because their implementation requires knowing about struct objfile, move struct obj_section below struct objfile in objfiles.h. The obj_section_offset was used in one place as an lvalue to set offsets, in machoread.c. Replace that with a set_offset method. Add the objfile::section_offset and objfile::set_section_offset methods to improve encapsulation (reduce other objects poking into struct objfile's internals). gdb/ChangeLog: * objfiles.h (struct obj_section): Move down. <offset, set_offset, addr, endaddr>: New. (obj_section_offset, obj_section_addr, obj_section_endaddr), replace all users to use obj_section methods. (struct objfile) <section_offset, set_section_offset>: New. Change-Id: I97e8fcae93ab2353fbdadcb4a5ec10d7949a7334
2021-06-25gdb: add new function quick_symbol_functions::has_unexpanded_symbolsAndrew Burgess1-0/+6
Adds a new function to the quick_symbol_functions API to let us know if there are any unexpanded symbols. This functionality is required by a later commit. After this commit the functionality is unused, and untested. The new function objfile::has_unexpanded_symtabs is added to the symfile-debug.c file which is a little strange, but this is (currently) where many of the other objfile::* functions (that call onto the quick_symbol_functions) are defined, so I'm reluctant to break this pattern. There should be no user visible changes after this commit. gdb/ChangeLog: * dwarf2/read.c (struct dwarf2_base_index_functions) <has_unexpanded_symtabs>: Declare. (dwarf2_base_index_functions::has_unexpanded_symtabs): Define new function. * objfiles.h (struct objfile) <has_unexpanded_symtabs>: Declare. * psympriv.h (struct psymbol_functions) <has_unexpanded_symtabs>: Declare. * psymtab.c (psymbol_functions::has_unexpanded_symtabs): Define new function. * quick-symbol.h (struct quick_symbol_functions) <has_unexpanded_symtabs>: Declare. * symfile-debug.c (objfile::has_unexpanded_symtabs): Define new function.
2021-04-17Simplify quick_symbol_functions::map_matching_symbolsTom Tromey1-2/+1
quick_symbol_functions::map_matching_symbols is only used by the Ada code. Currently, it both expands certain psymtabs and then walks over the full symtabs -- including any already-expanded ones -- calling a callback. It appears to work lazily as well, in that if the callback returns false, iteration stops. However, only the psymtab implementation does this; the DWARF index implementations are not lazy. It turns out, though, that the only callback that is ever passed here never returns false. This patch simplifies this method by removing the callback. The method is also renamed. In the new scheme, the caller is responsible for walking the full symtabs, which removes some redundancy as well. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * psymtab.c (psymbol_functions::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * psympriv.h (struct psymbol_functions) <expand_matching_symbols>: Rename from map_matching_symbols. Change parameters. * dwarf2/read.c (struct dwarf2_gdb_index) <expand_matching_symbols>: Rename from map_matching_symbols. Change parameters. (struct dwarf2_debug_names_index) <expand_matching_symbols>: Rename from map_matching_symbols. Change parameters. (dwarf2_gdb_index::expand_matching_symbols): Rename from dw2_map_matching_symbols. Change parameters. (dwarf2_gdb_index::expand_matching_symbols): Remove old implementation. (dwarf2_debug_names_index::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * objfiles.h (struct objfile) <expand_matching_symbols>: Rename from map_matching_symbols. Change parameters. * symfile-debug.c (objfile::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * ada-lang.c (map_matching_symbols): New function. (add_nonlocal_symbols): Update.
2021-04-17Remove quick_symbol_functions::expand_symtabs_with_fullnameTom Tromey1-1/+5
This removes quick_symbol_functions::expand_symtabs_with_fullname, replacing it with a call to expand_symtabs_matching. As with the previous patches, the implementation is consolidated in the objfile method. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * quick-symbol.h (struct quick_symbol_functions) <expand_symtabs_with_fullname>: Remove. * psymtab.c (psymbol_functions::expand_symtabs_with_fullname): Remove. * psympriv.h (struct psymbol_functions) <expand_symtabs_with_fullname>: Remove. * dwarf2/read.c (struct dwarf2_base_index_functions) <expand_symtabs_with_fullname>: Remove. (dwarf2_base_index_functions::expand_symtabs_with_fullname): Remove. * objfiles.h (struct objfile) <expand_symtabs_with_fullname>: Update comment. * symfile-debug.c (objfile::expand_symtabs_with_fullname): Rewrite.
2021-04-17Remove quick_symbol_functions::expand_symtabs_for_functionTom Tromey1-1/+2
This removes quick_symbol_functions::expand_symtabs_for_function, replacing it with a call to expand_symtabs_matching. As with the previous patches, the implementation is consolidated in the objfile method. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symfile-debug.c (objfile::expand_symtabs_for_function): Rewrite. * quick-symbol.h (struct quick_symbol_functions) <expand_symtabs_for_function>: Remove. * psymtab.c (psymbol_functions::expand_symtabs_for_function): Remove. * psympriv.h (struct psymbol_functions) <expand_symtabs_for_function>: Remove. * objfiles.h (struct objfile) <expand_symtabs_for_function>: Update comment. * dwarf2/read.c (struct dwarf2_gdb_index) <expand_symtabs_for_function>: Remove. (struct dwarf2_debug_names_index) <expand_symtabs_for_function>: Remove. (find_slot_in_mapped_hash): Remove. (dw2_symtab_iter_init_common): Merge with dw2_symtab_iter_init. (dw2_symtab_iter_init): Remove one overload. (dwarf2_gdb_index::expand_symtabs_for_function) (dwarf2_debug_names_index::expand_symtabs_for_function): Remove.
2021-04-17Remove quick_symbol_functions::map_symtabs_matching_filenameTom Tromey1-1/+12
This replaces quick_symbol_functions::map_symtabs_matching_filename with a call to expand_symtabs_matching. As with the previous patch, rather than update all callers, the implementation is consolidated in objfile::map_symtabs_matching_filename. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symfile-debug.c (objfile::map_symtabs_matching_filename): Rewrite. * quick-symbol.h (struct quick_symbol_functions) <map_symtabs_matching_filename>: Remove. * psymtab.c (partial_map_expand_apply) (psymbol_functions::map_symtabs_matching_filename): Remove. * psympriv.h (struct psymbol_functions) <map_symtabs_matching_filename>: Remove. * objfiles.h (struct objfile) <map_symtabs_matching_filename>: Update comment. * dwarf2/read.c (struct dwarf2_base_index_functions) <map_symtabs_matching_filename>: Remove. (dw2_map_expand_apply) (dwarf2_base_index_functions::map_symtabs_matching_filename): Remove.
2021-04-17Remove quick_symbol_functions::lookup_symbolTom Tromey1-1/+10
This removes quick_symbol_functions, replacing it with calls to expand_symtabs_matching. Because the replacement is somewhat verbose, objfile::lookup_symbol is not removed. This consolidates some duplicated code into this one spot. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symfile-debug.c (objfile::lookup_symbol): Rewrite. * quick-symbol.h (struct quick_symbol_functions) <lookup_symbol>: Remove. * psymtab.c (psymbol_functions::lookup_symbol): Remove. * psympriv.h (struct psymbol_functions) <lookup_symbol>: Remove. * objfiles.h (struct objfile) <lookup_symbol>: Add comment. * dwarf2/read.c (struct dwarf2_gdb_index) <lookup_symbol>: Remove. (struct dwarf2_debug_names_index) <lookup_symbol>: Remove. (dwarf2_gdb_index::lookup_symbol) (dwarf2_debug_names_index::lookup_symbol): Remove.
2021-04-17Add 'domain' parameter to expand_symtabs_matchingTom Tromey1-0/+1
Currently, expand_symtabs_matching only accepts a search_domain parameter. However, lookup_symbol uses a domain_enum instead, and the two, confusingly, do quite different things -- one cannot emulate the other. So, this patch adds a domain_enum parameter to expand_symtabs_matching, with UNDEF_DOMAIN used as a wildcard. This is another step toward replacing lookup_symbol with expand_symtabs_matching. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symtab.c (global_symbol_searcher::expand_symtabs): Update. * symmisc.c (maintenance_expand_symtabs): Update. * symfile.c (expand_symtabs_matching): Update. * symfile-debug.c (objfile::expand_symtabs_matching): Add 'domain' parameter. * quick-symbol.h (struct quick_symbol_functions) <expand_symtabs_matching>: Add 'domain' parameter. * psymtab.c (recursively_search_psymtabs) (psymbol_functions::expand_symtabs_matching): Add 'domain' parameter. * psympriv.h (struct psymbol_functions) <expand_symtabs_matching>: Add 'domain' parameter. * objfiles.h (struct objfile) <expand_symtabs_matching>: Add 'domain' parameter. * linespec.c (iterate_over_all_matching_symtabs): Update. * dwarf2/read.c (struct dwarf2_gdb_index) <expand_symtabs_matching>: Add 'domain' parameter. (struct dwarf2_debug_names_index) <expand_symtabs_matching>: Add 'domain' parameter. (dw2_expand_symtabs_matching) (dwarf2_gdb_index::expand_symtabs_matching) (dw2_debug_names_iterator) (dwarf2_debug_names_index::expand_symtabs_matching): Add 'domain' parameter.
2021-04-17Add search_flags to expand_symtabs_matchingTom Tromey1-0/+1
This adds a block search flags parameter to expand_symtabs_matching. All callers are updated to search both the static and global blocks, as that was the implied behavior before this patch. This is a step toward replacing lookup_symbol with expand_symtabs_matching. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symtab.c (global_symbol_searcher::expand_symtabs) (default_collect_symbol_completion_matches_break_on): Update. * symmisc.c (maintenance_expand_symtabs): Update. * symfile.h (expand_symtabs_matching): Add search_flags parameter. * symfile.c (expand_symtabs_matching): Add search_flags parameter. * symfile-debug.c (objfile::expand_symtabs_matching): Add search_flags parameter. * quick-symbol.h (struct quick_symbol_functions) <expand_symtabs_matching>: Add search_flags parameter. * python/py-symbol.c (gdbpy_lookup_static_symbols): Update. * psymtab.c (recursively_search_psymtabs) (psymbol_functions::expand_symtabs_matching): Add search_flags parameter. * psympriv.h (struct psymbol_functions) <expand_symtabs_matching>: Add search_flags parameter. * objfiles.h (struct objfile) <expand_symtabs_matching>: Add search_flags parameter. * linespec.c (iterate_over_all_matching_symtabs): Update. * dwarf2/read.c (struct dwarf2_gdb_index) <expand_symtabs_matching>: Add search_flags parameter. (struct dwarf2_debug_names_index) <expand_symtabs_matching>: Add search_flags parameter. (dw2_map_matching_symbols): Update. (dw2_expand_marked_cus, dw2_expand_symtabs_matching) (dwarf2_gdb_index::expand_symtabs_matching): Add search_flags parameter. (dw2_debug_names_iterator): Change block_index to search flags. <m_block_index>: Likewise. (dw2_debug_names_iterator::next) (dwarf2_debug_names_index::lookup_symbol) (dwarf2_debug_names_index::expand_symtabs_for_function) (dwarf2_debug_names_index::map_matching_symbols) (dwarf2_debug_names_index::map_matching_symbols): Update. (dwarf2_debug_names_index::expand_symtabs_matching): Add search_flags parameter. * ada-lang.c (ada_add_global_exceptions) (collect_symbol_completion_matches): Update.
2021-04-17Let expand_symtabs_matching short-circuitTom Tromey1-1/+1
This changes expand_symtabs_exp_notify_ftype to return bool, and updates all the uses. Now, if the notification function returns false, the call is short-circuited and stops examining symtabs. This is a step toward replacing map_symtabs_matching_filename with expand_symtabs_matching. gdb/ChangeLog 2021-04-17 Tom Tromey <tom@tromey.com> * symtab.c (default_collect_symbol_completion_matches_break_on): Update. * symfile.h (expand_symtabs_matching): Return bool. * symfile.c (expand_symtabs_matching): Return bool. * symfile-debug.c (objfile::expand_symtabs_matching): Return bool. * quick-symbol.h (expand_symtabs_exp_notify_ftype): Return bool. (struct quick_symbol_functions) <expand_symtabs_matching>: Return bool. * psymtab.c (psymbol_functions::expand_symtabs_matching): Return bool. * psympriv.h (struct psymbol_functions) <expand_symtabs_matching>: Return bool. * objfiles.h (struct objfile) <expand_symtabs_matching>: Return bool. * dwarf2/read.c (struct dwarf2_gdb_index) <expand_symtabs_matching>: Return bool. (struct dwarf2_debug_names_index) <expand_symtabs_matching>: Return bool. (dw2_expand_symtabs_matching_symbol): Return bool. (dw2_expand_symtabs_matching_one, dw2_expand_marked_cus) (dw2_expand_symtabs_matching) (dwarf2_gdb_index::expand_symtabs_matching) (dwarf2_debug_names_index::expand_symtabs_matching) (dwarf2_debug_names_index::expand_symtabs_matching): Return bool.
2021-04-02gdb: pass objfile_per_bfd_storage instead of objfile to partial_symtabSimon Marchi1-2/+14
Since partial_symtab is supposed to be objfile-independent (since series [1]), I think it would make sense for partial_symtab to not take an objfile as a parameter in its constructor. This patch replaces that parameter with an objfile_per_bfd_storage parameter. The objfile is used for two things: - to get the objfile_name, for debug messages. We can get that name from the bfd instead. - to intern the partial symtab filename. Even though it goes through an objfile method, the request is actually forwarded to the underlying objfile_per_bfd_storage. So we can ask the new objfile_per_bfd_storage instead. In order to get a reference to the BFD from the objfile_per_bfd_storage, the BFD is saved in the objfile_per_bfd_storage object. [1] https://sourceware.org/pipermail/gdb-patches/2021-February/176625.html gdb/ChangeLog: * psympriv.h (struct partial_symtab) <partial_symtab>: Change objfile parameter for objfile_per_bfd_storage, adjust callers. (struct standard_psymtab) <standard_psymtab>: Likewise. (struct legacy_psymtab) <legacy_psymtab>: Likewise. * psymtab.c (partial_symtab::partial_symtab): Likewise. * ctfread.c (struct ctf_psymtab): Likewise. * dwarf2/read.h (struct dwarf2_psymtab): Likewise. * dwarf2/read.c (struct dwarf2_include_psymtab): Likewise. (dwarf2_create_include_psymtab): Likewise. * objfiles.h (struct objfile_per_bfd_storage) <objfile_per_bfd_storage>: Add bfd parameter, adjust callers. <get_bfd>: New method. <m_bfd>: New field. * objfiles.c (get_objfile_bfd_data): Adjust. Change-Id: I2ed3ab5d2e6f27d034bd4dc26ae2fae7b0b8a2b9
2021-04-02gdb: add intern methods to objfile_per_bfd_storageSimon Marchi1-3/+19
This allows keeping the objfile_per_bfd_storage implementation details into objfile_per_bfd_storage, instead of into objfile. And this makes the intern methods usable for code that only has an objfile_per_bfd_storage to work with. gdb/ChangeLog: * objfiles.h (struct objfile_per_bfd_storage) <intern>: New methods. (struct objfile) <intern>: Use objfile::objfile_per_bfd_storage::intern. Change-Id: Ifd54026c5efaeffafac9b84ff84c199acc7ce78a
2021-03-26Use function view in quick_symbol_functions::map_symbol_filenamesTom Tromey1-2/+2
This changes quick_symbol_functions::map_symbol_filenames to use a function_view, and updates all the uses. It also changes the final parameter to 'bool'. A couple of spots are further updated to use operator() rather than a lambda. gdb/ChangeLog 2021-03-26 Tom Tromey <tom@tromey.com> * symtab.c (struct output_source_filename_data): Add 'output' method and operator(). (output_source_filename_data::output): Rename from output_source_filename. (output_partial_symbol_filename): Remove. (info_sources_command): Update. (struct add_partial_filename_data): Add operator(). (add_partial_filename_data::operator()): Rename from maybe_add_partial_symtab_filename. (make_source_files_completion_list): Update. * symfile.c (quick_symbol_functions): Update. * symfile-debug.c (objfile::map_symbol_filenames): Update. * quick-symbol.h (symbol_filename_ftype): Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. (struct quick_symbol_functions) <map_symbol_filenames>: Likewise. * psymtab.c (psymbol_functions::map_symbol_filenames): Update. * psympriv.h (struct psymbol_functions) <map_symbol_filenames>: Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. * objfiles.h (struct objfile) <map_symbol_filenames>: Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. * mi/mi-cmd-file.c (print_partial_file_name): Remove 'ignore' parameter. (mi_cmd_file_list_exec_source_files): Update. * dwarf2/read.c (dwarf2_base_index_functions::map_symbol_filenames): Update.
2021-03-20Allow multiple partial symbol readers per objfileTom Tromey1-11/+0
This patch finally changes gdb so that an objfile can have multiple sources of partial symbols (or mixed partial symbols and other kinds of indices). This is done by having each symbol reader create its own psymbol_functions object and add it to the 'qf' list in the objfile. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * xcoffread.c (xcoff_initial_scan): Create partial symtabs. * symfile.c (syms_from_objfile_1, reread_symbols): Update. * psymtab.h (make_psymbol_functions): Don't declare. * psymtab.c (make_psymbol_functions): Remove. (maintenance_print_psymbols): Update. * psympriv.h (struct psymbol_functions): Add no-argument constructor. * objfiles.h (struct objfile) <reset_psymtabs>: Remove. <partial_symtabs>: Remove. * mdebugread.c (mdebug_build_psymtabs): Create partial symtabs. * elfread.c (read_partial_symbols): Update. (elf_symfile_read): Remove check for existing partial symbols. Don't clear "qf". * dwarf2/read.c (dwarf2_has_info): Remove check for existing partial symbols. (dwarf2_build_psymtabs): Add psymbol_functions parameter. Create partial symtabs. * dwarf2/public.h (dwarf2_build_psymtabs): Add psymbol_functions parameter. * dbxread.c (dbx_symfile_read): Create partial symtabs. * ctfread.c (elfctf_build_psymtabs): Create partial symtabs.
2021-03-20Switch objfile to hold a list of psymbol readersTom Tromey1-1/+2
This changes objfile::qf to be a forward_list, and then updates all the uses to iterate over the list. Note that there is still only ever a single element in the list; this is handled by clearing the list whenever an object is added. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * dwarf2/read.c (dwarf2_build_psymtabs): Update. * symfile.c (syms_from_objfile_1, reread_symbols): Update. * symfile-debug.c (objfile::has_partial_symbols) (objfile::find_last_source_symtab) (objfile::forget_cached_source_info) (objfile::map_symtabs_matching_filename, objfile::lookup_symbol) (objfile::print_stats, objfile::dump) (objfile::expand_symtabs_for_function) (objfile::expand_all_symtabs) (objfile::expand_symtabs_with_fullname) (objfile::map_matching_symbols) (objfile::expand_symtabs_matching) (objfile::find_pc_sect_compunit_symtab) (objfile::map_symbol_filenames) (objfile::find_compunit_symtab_by_address) (objfile::lookup_global_symbol_language) (objfile::require_partial_symbols): Update. * psymtab.c (maintenance_print_psymbols) (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. * objfiles.h (struct objfile) <qf>: Now a forward_list. * objfiles.c (objfile_relocate1): Update. * elfread.c (elf_symfile_read): Update.
2021-03-20Remove objfile::psymtabsTom Tromey1-8/+0
The method objfile::psymtabs is no longer used and can be removed. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * objfiles.h (struct objfile) <psymtabs>: Remove method.
2021-03-20Introduce objfile::require_partial_symbolsTom Tromey1-0/+3
This adds a new method, objfile::require_partial_symbols. This reuses most of the code from the old function in psymtab.c. That function is now made static, and simplified. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * symfile.c (read_symbols): Use objfile method. * symfile-debug.c (objfile::require_partial_symbols): New method. * psymtab.h (require_partial_symbols): Don't declare. * psymtab.c (require_partial_symbols): Use objfile method. Now static. (psymbol_functions::map_symtabs_matching_filename, OBJFILE) (psymbol_functions::lookup_symbol) (psymbol_functions::lookup_global_symbol_language) (psymbol_functions::find_last_source_symtab) (psymbol_functions::forget_cached_source_info) (psymbol_functions::print_stats) (psymbol_functions::expand_symtabs_for_function) (psymbol_functions::expand_all_symtabs) (psymbol_functions::expand_symtabs_with_fullname) (psymbol_functions::map_symbol_filenames) (psymbol_functions::map_matching_symbols) (psymbol_functions::expand_symtabs_matching) (psymbol_functions::find_compunit_symtab_by_address) (maintenance_print_psymbols, maintenance_info_psymtabs) (maintenance_check_psymtabs): Update. * objfiles.h (struct objfile) <require_partial_symbols>: Declare new method.
2021-03-20Move psymtab statistics printing to psymtab.cTom Tromey1-2/+1
This moves all the psymtab statistics printing code form symmisc.c to psymtab.c. This changes the formatting of the output a little, but considering that it is a maint command (and, I assume, a rarely used one), this seems fine to me. This change helps further dissociate the psymtab from the objfile. In the end there will be no direct connect -- only via the quick_symbol_functions interface. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * dwarf2/read.c (dwarf2_base_index_functions::print_stats): Add print_bcache parameter. * symfile-debug.c (objfile::print_stats): Add print_bcache parameter. * quick-symbol.h (struct quick_symbol_functions) <print_stats>: Add print_bcache parameter. * symmisc.c (print_symbol_bcache_statistics, count_psyms): Move code to psymtab.c. (print_objfile_statistics): Move psymtab code to psymtab.c. * psymtab.c (count_psyms): Move from symmisc.c. (psymbol_functions::print_stats): Print partial symbol and bcache statistics. Add print_bcache parameter. * objfiles.h (print_symbol_bcache_statistics): Don't declare. (struct objfile) <print_stats>: Add print_bcache parameter. * maint.c (maintenance_print_statistics): Update. gdb/testsuite/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * gdb.base/maint.exp: Update "maint print statistics" output.
2021-03-20Move psymbol_map out of objfileTom Tromey1-6/+0
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 <tom@tromey.com> * quick-symbol.h (struct quick_symbol_functions) <relocated>: New method. * psymtab.h (struct psymbol_functions) <relocated>: New method. <fill_psymbol_map>: Declare method. <m_psymbol_map>: 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) <psymbol_map>: Remove. * objfiles.c (objfile_relocate1): Update.
2021-03-20Convert quick_symbol_functions to use methodsTom Tromey1-1/+2
This changes quick_symbol_functions to be a base class with pure virtual methods, rather than a struct holding function pointers. Then, objfile is changed to hold a unique_ptr to an instance of this class. struct psymbol_functions is put into psympriv.h, and not psymtab.c, because that is convenient later in the series. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * psympriv.h (struct psymbol_functions): New. * symfile.c (syms_from_objfile_1, reread_symbols): Update. * symfile-debug.c (objfile::find_compunit_symtab_by_address) (objfile::lookup_global_symbol_language): Update. * quick-symbol.h (struct quick_symbol_functions): Convert function pointers to methods. Add virtual destructor. (quick_symbol_functions_up): New typedef. * psymtab.h (psym_functions, dwarf2_gdb_index_functions) (dwarf2_debug_names_functions): Don't declare. (make_psymbol_functions): Declare. * psymtab.c (psymbol_functions::map_symtabs_matching_filename) (psymbol_functions::find_pc_sect_compunit_symtab) (psymbol_functions::lookup_symbol) (psymbol_functions::lookup_global_symbol_language) (psymbol_functions::find_last_source_symtab) (psymbol_functions::forget_cached_source_info) (psymbol_functions::print_stats, psymbol_functions::dump) (psymbol_functions::expand_symtabs_for_function) (psymbol_functions::expand_all_symtabs) (psymbol_functions::expand_symtabs_with_fullname) (psymbol_functions::map_symbol_filenames) (psymbol_functions::map_matching_symbols) (psymbol_functions::expand_symtabs_matching) (psymbol_functions::has_symbols) (psymbol_functions::find_compunit_symtab_by_address): Rename. (psym_functions): Remove. (make_psymbol_functions): New function. * objfiles.h (struct objfile) <qf>: Change type. * elfread.c (elf_symfile_read): Update. * dwarf2/read.c (struct dwarf2_base_index_functions) (struct dwarf2_gdb_index, struct dwarf2_debug_names_index): New. (make_dwarf_gdb_index, make_dwarf_debug_names): New functions. (dwarf2_base_index_functions::find_last_source_symtab) (dwarf2_base_index_functions::forget_cached_source_info) (dwarf2_base_index_functions::map_symtabs_matching_filename) (dwarf2_gdb_index::lookup_symbol) (dwarf2_base_index_functions::print_stats) (dwarf2_gdb_index::dump) (dwarf2_gdb_index::expand_symtabs_for_function) (dwarf2_base_index_functions::expand_all_symtabs) (dwarf2_base_index_functions::expand_symtabs_with_fullname): Rename. (dwarf2_gdb_index::map_matching_symbols): New method. (dwarf2_gdb_index::expand_symtabs_matching): New method. (dwarf2_base_index_functions::find_pc_sect_compunit_symtab) (dwarf2_base_index_functions::map_symbol_filenames) (dwarf2_base_index_functions::has_symbols): Rename. (dwarf2_gdb_index_functions): Remove. (dwarf2_debug_names_index::lookup_symbol) (dwarf2_debug_names_index::dump) (dwarf2_debug_names_index::expand_symtabs_for_function) (dwarf2_debug_names_index::map_matching_symbols) (dwarf2_debug_names_index::expand_symtabs_matching): Rename. (dwarf2_debug_names_functions): Remove. * dwarf2/public.h (make_dwarf_gdb_index, make_dwarf_debug_names): Declare.
2021-03-20Move sym_fns::qf to objfileTom Tromey1-0/+4
Currently the "partial" symbol reader is attached to the objfile's symbol functions. However, in order to allow multiple separate partial symbol readers, this association must be changed. This patch moves the "qf" member out of sym_fns as a step toward that goal. gdb/ChangeLog 2021-03-20 Tom Tromey <tom@tromey.com> * psymtab.c (require_partial_symbols): Check that 'sf' is not null. * xcoffread.c (xcoff_sym_fns): Update. * symfile.h (struct sym_fns) <qf>: Remove. * symfile.c (syms_from_objfile_1, reread_symbols): Update. * symfile-debug.c (objfile::has_partial_symbols) (objfile::find_last_source_symtab) (objfile::forget_cached_source_info) (objfile::map_symtabs_matching_filename, objfile::lookup_symbol) (objfile::print_stats, objfile::dump) (objfile::expand_symtabs_for_function) (objfile::expand_all_symtabs) (objfile::expand_symtabs_with_fullname) (objfile::map_matching_symbols) (objfile::expand_symtabs_matching) (objfile::find_pc_sect_compunit_symtab) (objfile::map_symbol_filenames) (objfile::find_compunit_symtab_by_address) (objfile::lookup_global_symbol_language, debug_sym_fns) (install_symfile_debug_logging): Update. * objfiles.h (struct objfile) <qf>: New member. * mipsread.c (ecoff_sym_fns): Update. * machoread.c (macho_sym_fns): Update. * elfread.c (elf_sym_fns_gdb_index, elf_sym_fns_debug_names): Don't declare. (elf_symfile_read, elf_sym_fns, elf_sym_fns_lazy_psyms): Update. * dbxread.c (aout_sym_fns): Update. * coffread.c (coff_sym_fns): Update.