[PATCH v2 08/13] gdb: implement readnow_functions::expand_all_symtabs

Jan Vrany
2025-11-24T20:09:20Z

This commit implements readnow_functions::expand_all_symtabs as empty.
This will allow readnow_functions to be used in other cases, for example
in JIT reader.

Prior this code CUs were instantiated by calling objfile::expand_all_symtabs
(which in turn call dwarf2_base_index_functions::expand_all_symtabs)
from symbol_file_add_with_addrs right after the call to syms_from_objfile
(which in turn calls dwarf2_initialize_objfile).

Since now readnow_functions defines its own, empty expand_all_symtabs,
CUs are instantiated earlier in dwarf2_initialize_objfile. This seemed
like a good place because this function actually installs readnow_functions
into the objfile.

Testing on my machine with -readnow shown no regression.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33554
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/dwarf2/read.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 471496bd4be..89e06923320 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1572,6 +1572,10 @@ struct readnow_functions : public dwarf2_base_index_functions
{
}

+ 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,
@@ -1748,6 +1752,24 @@ dw2_instantiate_symtab (dwarf2_per_cu *per_cu, dwarf2_per_objfile *per_objfile,
return per_objfile->get_symtab (per_cu);
}

+
+/* Ensure that the symbols for all CUs have been read in. DWARF2_PER_OBJFILE
+ is the per-objfile for which CUs are instantiated. */
+
+static void
+dw2_instantiate_all_symtabs (dwarf2_per_objfile *per_objfile)
+{
+ for (dwarf2_per_cu *per_cu : all_units_range (per_objfile->per_bfd))
+ {
+ /* We don't want to directly expand a partial CU, because if we
+ read it with the wrong language, then assertion failures can
+ be triggered later on. See PR symtab/23010. So, tell
+ dw2_instantiate_symtab to skip partial CUs -- any important
+ partial CU will be read via DW_TAG_imported_unit anyway. */
+ dw2_instantiate_symtab (per_cu, per_objfile, true);
+ }
+}
+
/* See read.h. */

dwarf2_per_cu_up
@@ -2051,17 +2073,7 @@ dwarf2_base_index_functions::print_stats (struct objfile *objfile,
void
dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
{
- dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
- for (dwarf2_per_cu *per_cu : all_units_range (per_objfile->per_bfd))
- {
- /* We don't want to directly expand a partial CU, because if we
- read it with the wrong language, then assertion failures can
- be triggered later on. See PR symtab/23010. So, tell
- dw2_instantiate_symtab to skip partial CUs -- any important
- partial CU will be read via DW_TAG_imported_unit anyway. */
- dw2_instantiate_symtab (per_cu, per_objfile, true);
- }
+ dw2_instantiate_all_symtabs (get_dwarf2_per_objfile (objfile));
}

/* If FILE_MATCHER is NULL and if CUS_TO_SKIP does not include the
@@ -2441,6 +2453,7 @@ dwarf2_initialize_objfile (struct objfile *objfile,
dwarf_read_debug_printf ("readnow requested");

create_all_units (per_objfile);
+ dw2_instantiate_all_symtabs (per_objfile);
objfile->qf.emplace_front (new readnow_functions);
}
/* Was a GDB index already read when we processed an objfile sharing
--
2.51.0