gdb: pass objfile_per_bfd_storage instead of objfile to partial_symtab

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
This commit is contained in:
Simon Marchi
2021-04-02 11:45:25 -04:00
parent 9984dd9994
commit 0072c87379
11 changed files with 75 additions and 46 deletions

View File

@ -1436,9 +1436,9 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
partial_symtab::partial_symtab (const char *filename,
psymtab_storage *partial_symtabs,
struct objfile *objfile,
objfile_per_bfd_storage *objfile_per_bfd,
CORE_ADDR textlow)
: partial_symtab (filename, partial_symtabs, objfile)
: partial_symtab (filename, partial_symtabs, objfile_per_bfd)
{
set_text_low (textlow);
set_text_high (raw_text_low ()); /* default */
@ -1561,28 +1561,29 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name,
partial_symtab::partial_symtab (const char *filename_,
psymtab_storage *partial_symtabs,
struct objfile *objfile)
objfile_per_bfd_storage *objfile_per_bfd)
: searched_flag (PST_NOT_SEARCHED),
text_low_valid (0),
text_high_valid (0)
{
partial_symtabs->install_psymtab (this);
filename = objfile->intern (filename_);
filename = objfile_per_bfd->intern (filename_);
if (symtab_create_debug)
{
/* Be a bit clever with debugging messages, and don't print objfile
every time, only when it changes. */
static std::string last_objfile_name;
const char *this_objfile_name = objfile_name (objfile);
static std::string last_bfd_name;
const char *this_bfd_name
= bfd_get_filename (objfile_per_bfd->get_bfd ());
if (last_objfile_name.empty () || last_objfile_name != this_objfile_name)
if (last_bfd_name.empty () || last_bfd_name != this_bfd_name)
{
last_objfile_name = this_objfile_name;
last_bfd_name = this_bfd_name;
fprintf_filtered (gdb_stdlog,
"Creating one or more psymtabs for objfile %s ...\n",
this_objfile_name);
"Creating one or more psymtabs for %s ...\n",
this_bfd_name);
}
fprintf_filtered (gdb_stdlog,
"Created psymtab %s for module %s.\n",