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  <tom@tromey.com>

	* 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.
This commit is contained in:
Tom Tromey 2021-03-28 10:43:15 -06:00
parent fff7b4f846
commit edc02ceb97
4 changed files with 66 additions and 68 deletions

View File

@ -1,3 +1,16 @@
2021-03-28 Tom Tromey <tom@tromey.com>
* 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 <tom@tromey.com> 2021-03-27 Tom Tromey <tom@tromey.com>
* elfread.c (elf_sym_fns_lazy_psyms): Don't declare. * elfread.c (elf_sym_fns_lazy_psyms): Don't declare.

View File

@ -34,18 +34,13 @@ enum class dw_index_kind
DEBUG_NAMES, DEBUG_NAMES,
}; };
/* Initialize for reading DWARF for OBJFILE. Return false if this /* Initialize for reading DWARF for OBJFILE, and push the appropriate
file will use psymtabs, or true if using an index, in which case entry on the objfile's "qf" list. */
*INDEX_KIND is set to the index variant in use. */ extern void dwarf2_initialize_objfile (struct objfile *objfile);
extern bool dwarf2_initialize_objfile (struct objfile *objfile,
dw_index_kind *index_kind);
struct psymbol_functions; struct psymbol_functions;
extern void dwarf2_build_psymtabs (struct objfile *, extern void dwarf2_build_psymtabs (struct objfile *,
psymbol_functions *psf = nullptr); psymbol_functions *psf = nullptr);
extern void dwarf2_build_frame_info (struct objfile *); 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 */ #endif /* DWARF2_PUBLIC_H */

View File

@ -2191,6 +2191,30 @@ struct dwarf2_per_cu_quick_data
unsigned int no_file_data : 1; 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 struct dwarf2_base_index_functions : public quick_symbol_functions
{ {
bool has_symbols (struct objfile *objfile) override; 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; enum search_domain kind) override;
}; };
quick_symbol_functions_up static quick_symbol_functions_up
make_dwarf_gdb_index () make_dwarf_gdb_index ()
{ {
return quick_symbol_functions_up (new dwarf2_gdb_index); return quick_symbol_functions_up (new dwarf2_gdb_index);
} }
quick_symbol_functions_up static quick_symbol_functions_up
make_dwarf_debug_names () make_dwarf_debug_names ()
{ {
return quick_symbol_functions_up (new dwarf2_debug_names_index); 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); return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
} }
/* See symfile.h. */ /* See dwarf2/public.h. */
bool void
dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) dwarf2_initialize_objfile (struct objfile *objfile)
{ {
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; 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) if (per_bfd->using_index)
{ {
dwarf_read_debug_printf ("using_index already set"); dwarf_read_debug_printf ("using_index already set");
*index_kind = dw_index_kind::GDB_INDEX;
per_objfile->resize_symtabs (); per_objfile->resize_symtabs ();
return true; objfile->qf.push_front (make_dwarf_gdb_index ());
return;
} }
per_bfd->using_index = 1; 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); struct dwarf2_per_cu_quick_data);
} }
/* Return 1 so that gdb sees the "quick" functions. However, /* Arrange for gdb to see the "quick" functions. However, these
these functions will be no-ops because we will have expanded functions will be no-ops because we will have expanded all
all symtabs. */ symtabs. */
*index_kind = dw_index_kind::GDB_INDEX; objfile->qf.push_front (make_dwarf_gdb_index ());
return true; return;
} }
/* Was a debug names index already read when we processed an objfile sharing /* 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) if (per_bfd->debug_names_table != nullptr)
{ {
dwarf_read_debug_printf ("re-using shared debug names table"); dwarf_read_debug_printf ("re-using shared debug names table");
*index_kind = dw_index_kind::DEBUG_NAMES;
per_objfile->resize_symtabs (); 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 /* 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) if (per_bfd->index_table != nullptr)
{ {
dwarf_read_debug_printf ("re-using shared index table"); dwarf_read_debug_printf ("re-using shared index table");
*index_kind = dw_index_kind::GDB_INDEX;
per_objfile->resize_symtabs (); 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 /* 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) if (per_bfd->partial_symtabs != nullptr)
{ {
dwarf_read_debug_printf ("re-using shared partial symtabs"); 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)) if (dwarf2_read_debug_names (per_objfile))
{ {
dwarf_read_debug_printf ("found debug names"); dwarf_read_debug_printf ("found debug names");
*index_kind = dw_index_kind::DEBUG_NAMES;
per_objfile->resize_symtabs (); per_objfile->resize_symtabs ();
return true; objfile->qf.push_front (make_dwarf_debug_names ());
return;
} }
if (dwarf2_read_gdb_index (per_objfile, 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<dwz_file>)) get_gdb_index_contents_from_section<dwz_file>))
{ {
dwarf_read_debug_printf ("found gdb index from file"); dwarf_read_debug_printf ("found gdb index from file");
*index_kind = dw_index_kind::GDB_INDEX;
per_objfile->resize_symtabs (); 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. */ /* ... 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"); dwarf_read_debug_printf ("found gdb index from cache");
global_index_cache.hit (); global_index_cache.hit ();
*index_kind = dw_index_kind::GDB_INDEX;
per_objfile->resize_symtabs (); per_objfile->resize_symtabs ();
return true; objfile->qf.push_front (make_dwarf_gdb_index ());
return;
} }
global_index_cache.miss (); global_index_cache.miss ();
return false; objfile->qf.push_front (make_lazy_dwarf_reader ());
} }

View File

@ -53,24 +53,6 @@
#include "debuginfod-support.h" #include "debuginfod-support.h"
#include "dwarf2/public.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 /* The struct elfinfo is available only during ELF symbol table and
psymtab reading. It is destroyed at the completion of psymtab-reading. psymtab reading. It is destroyed at the completion of psymtab-reading.
It's local to elf_symfile_read. */ 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)) if (dwarf2_has_info (objfile, NULL, true))
{ dwarf2_initialize_objfile (objfile);
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);
}
/* If the file has its own symbol tables it has no separate debug /* If the file has its own symbol tables it has no separate debug
info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to
SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with