From edc02ceb9763d414af79990a5fdb5e50aa59ceb6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 28 Mar 2021 10:43:15 -0600 Subject: [PATCH] Simplify DWARF reader initialization Now that the quick functions are separate from the object file format, there's no need to have elfread.c push a new entry on the objfile 'qf' list. Instead, this detail can be pushed into the DWARF reader. That is what this patch implements. I wasn't sure whether lazy reading still makes sense or not. It's still only used by ELF, and only in certain situations (like vfork, I think). It may not be carrying its weight, so we may want to consider removing this in the future. Also, I'm unclear on why the various indices are only used for ELF. This seems sub-optimal. However, I haven't tried to address that here. gdb/ChangeLog 2021-03-28 Tom Tromey * elfread.c (can_lazily_read_symbols): Move to dwarf2/read.c. (elf_symfile_read): Simplify. * dwarf2/read.c (struct lazy_dwarf_reader): Move from elfread.c. (make_lazy_dwarf_reader): New function. (make_dwarf_gdb_index, make_dwarf_debug_names): Now static. (dwarf2_initialize_objfile): Return void. Remove index_kind parameter. Push on 'qf' list. * dwarf2/public.h (dwarf2_initialize_objfile): Change return type. Remove 'index_kind' parameter. (make_dwarf_gdb_index, make_dwarf_debug_names): Don't declare. --- gdb/ChangeLog | 13 ++++++++ gdb/dwarf2/public.h | 11 ++----- gdb/dwarf2/read.c | 73 ++++++++++++++++++++++++++++++--------------- gdb/elfread.c | 37 +---------------------- 4 files changed, 66 insertions(+), 68 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9e8f2f41cc..70e8ad7ebe 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2021-03-28 Tom Tromey + + * elfread.c (can_lazily_read_symbols): Move to dwarf2/read.c. + (elf_symfile_read): Simplify. + * dwarf2/read.c (struct lazy_dwarf_reader): Move from elfread.c. + (make_lazy_dwarf_reader): New function. + (make_dwarf_gdb_index, make_dwarf_debug_names): Now static. + (dwarf2_initialize_objfile): Return void. Remove index_kind + parameter. Push on 'qf' list. + * dwarf2/public.h (dwarf2_initialize_objfile): Change return + type. Remove 'index_kind' parameter. + (make_dwarf_gdb_index, make_dwarf_debug_names): Don't declare. + 2021-03-27 Tom Tromey * elfread.c (elf_sym_fns_lazy_psyms): Don't declare. diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index e6653f4f38..33bb5d4821 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -34,18 +34,13 @@ enum class dw_index_kind DEBUG_NAMES, }; -/* Initialize for reading DWARF for OBJFILE. Return false if this - file will use psymtabs, or true if using an index, in which case - *INDEX_KIND is set to the index variant in use. */ -extern bool dwarf2_initialize_objfile (struct objfile *objfile, - dw_index_kind *index_kind); +/* Initialize for reading DWARF for OBJFILE, and push the appropriate + entry on the objfile's "qf" list. */ +extern void dwarf2_initialize_objfile (struct objfile *objfile); struct psymbol_functions; extern void dwarf2_build_psymtabs (struct objfile *, psymbol_functions *psf = nullptr); extern void dwarf2_build_frame_info (struct objfile *); -extern quick_symbol_functions_up make_dwarf_gdb_index (); -extern quick_symbol_functions_up make_dwarf_debug_names (); - #endif /* DWARF2_PUBLIC_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index b324541ee9..1b98b758c3 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2191,6 +2191,30 @@ struct dwarf2_per_cu_quick_data unsigned int no_file_data : 1; }; +/* A subclass of psymbol_functions that arranges to read the DWARF + partial symbols when needed. */ +struct lazy_dwarf_reader : public psymbol_functions +{ + using psymbol_functions::psymbol_functions; + + bool can_lazily_read_symbols () override + { + return true; + } + + void read_partial_symbols (struct objfile *objfile) override + { + if (dwarf2_has_info (objfile, nullptr)) + dwarf2_build_psymtabs (objfile, this); + } +}; + +static quick_symbol_functions_up +make_lazy_dwarf_reader () +{ + return quick_symbol_functions_up (new lazy_dwarf_reader); +} + struct dwarf2_base_index_functions : public quick_symbol_functions { bool has_symbols (struct objfile *objfile) override; @@ -2292,13 +2316,13 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions enum search_domain kind) override; }; -quick_symbol_functions_up +static quick_symbol_functions_up make_dwarf_gdb_index () { return quick_symbol_functions_up (new dwarf2_gdb_index); } -quick_symbol_functions_up +static quick_symbol_functions_up make_dwarf_debug_names () { return quick_symbol_functions_up (new dwarf2_debug_names_index); @@ -5993,10 +6017,10 @@ get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz) return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res); } -/* See symfile.h. */ +/* See dwarf2/public.h. */ -bool -dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) +void +dwarf2_initialize_objfile (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; @@ -6016,9 +6040,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->using_index) { dwarf_read_debug_printf ("using_index already set"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } per_bfd->using_index = 1; @@ -6037,11 +6061,11 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) struct dwarf2_per_cu_quick_data); } - /* Return 1 so that gdb sees the "quick" functions. However, - these functions will be no-ops because we will have expanded - all symtabs. */ - *index_kind = dw_index_kind::GDB_INDEX; - return true; + /* Arrange for gdb to see the "quick" functions. However, these + functions will be no-ops because we will have expanded all + symtabs. */ + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* Was a debug names index already read when we processed an objfile sharing @@ -6049,9 +6073,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->debug_names_table != nullptr) { dwarf_read_debug_printf ("re-using shared debug names table"); - *index_kind = dw_index_kind::DEBUG_NAMES; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_debug_names ()); + return; } /* Was a GDB index already read when we processed an objfile sharing @@ -6059,9 +6083,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->index_table != nullptr) { dwarf_read_debug_printf ("re-using shared index table"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* There might already be partial symtabs built for this BFD. This happens @@ -6072,15 +6096,16 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->partial_symtabs != nullptr) { dwarf_read_debug_printf ("re-using shared partial symtabs"); - return false; + objfile->qf.push_front (make_lazy_dwarf_reader ()); + return; } if (dwarf2_read_debug_names (per_objfile)) { dwarf_read_debug_printf ("found debug names"); - *index_kind = dw_index_kind::DEBUG_NAMES; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_debug_names ()); + return; } if (dwarf2_read_gdb_index (per_objfile, @@ -6088,9 +6113,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) get_gdb_index_contents_from_section)) { dwarf_read_debug_printf ("found gdb index from file"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* ... otherwise, try to find the index in the index cache. */ @@ -6100,13 +6125,13 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) { dwarf_read_debug_printf ("found gdb index from cache"); global_index_cache.hit (); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } global_index_cache.miss (); - return false; + objfile->qf.push_front (make_lazy_dwarf_reader ()); } diff --git a/gdb/elfread.c b/gdb/elfread.c index f5de913a5c..1dea226242 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -53,24 +53,6 @@ #include "debuginfod-support.h" #include "dwarf2/public.h" -/* A subclass of psymbol_functions that arranges to read the DWARF - partial symbols when needed. */ -struct lazy_dwarf_reader : public psymbol_functions -{ - using psymbol_functions::psymbol_functions; - - bool can_lazily_read_symbols () override - { - return true; - } - - void read_partial_symbols (struct objfile *objfile) override - { - if (dwarf2_has_info (objfile, nullptr)) - dwarf2_build_psymtabs (objfile, this); - } -}; - /* The struct elfinfo is available only during ELF symbol table and psymtab reading. It is destroyed at the completion of psymtab-reading. It's local to elf_symfile_read. */ @@ -1273,24 +1255,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) } if (dwarf2_has_info (objfile, NULL, true)) - { - dw_index_kind index_kind; - - if (dwarf2_initialize_objfile (objfile, &index_kind)) - { - switch (index_kind) - { - case dw_index_kind::GDB_INDEX: - objfile->qf.push_front (make_dwarf_gdb_index ()); - break; - case dw_index_kind::DEBUG_NAMES: - objfile->qf.push_front (make_dwarf_debug_names ()); - break; - } - } - else - objfile->qf.emplace_front (new lazy_dwarf_reader); - } + dwarf2_initialize_objfile (objfile); /* If the file has its own symbol tables it has no separate debug info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with -- 2.34.1