Introduce partial_symtab::expand_psymtab method

The symbol readers generally used two functions to expand a partial
symtab: an outer function (now the "read_symtab" method), and an inner
function, typically named something like "psymtab_to_symtab".

This patch changes this second step to be a method on partial_symtab,
and updates all the callers.  For legacy_psymtab, a new function
pointer member is introduced.

This patch enables a subsequent cleanup.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_psymtab_to_symtab_1): Change argument order.
	Call expand_psymtab.
	(xcoff_read_symtab): Call expand_psymtab.
	(xcoff_start_psymtab, xcoff_end_psymtab): Set
	legacy_expand_psymtab.
	* psympriv.h (struct partial_symtab) <expand_psymtab>: New
	method.
	(struct legacy_psymtab) <expand_psymtab>: Implement.
	<legacy_expand_psymtab>: New member.
	* mdebugread.c (mdebug_read_symtab): Call expand_psymtab.
	(parse_partial_symbols): Set legacy_expand_psymtab.
	(psymtab_to_symtab_1): Change argument order.  Call
	expand_psymtab.
	(new_psymtab): Set legacy_expand_psymtab.
	* dwarf2read.h (struct dwarf2_psymtab) <expand_psymtab>: Declare.
	* dwarf2read.c (dwarf2_psymtab::read_symtab): Call
	expand_psymtab.
	(dwarf2_psymtab::expand_psymtab): Rename from
	psymtab_to_symtab_1.  Call expand_psymtab.
	* dbxread.c (start_psymtab): Set legacy_expand_psymtab.
	(dbx_end_psymtab): Likewise.
	(dbx_psymtab_to_symtab_1): Change argument order. Call
	expand_psymtab.
	(dbx_read_symtab): Call expand_psymtab.
	* ctfread.c (struct ctf_psymtab) <expand_psymtab>: Declare.
	(ctf_psymtab::expand_psymtab): Rename from psymtab_to_symtab.
	(ctf_psymtab::read_symtab): Call expand_psymtab.

Change-Id: Ic39a2d7aa7b424088d910b59dbd21271fa1c3430
This commit is contained in:
Tom Tromey
2019-10-23 09:40:54 -06:00
parent 077cbab270
commit 8566b89b73
8 changed files with 82 additions and 38 deletions

View File

@ -1,3 +1,33 @@
2020-01-26 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_psymtab_to_symtab_1): Change argument order.
Call expand_psymtab.
(xcoff_read_symtab): Call expand_psymtab.
(xcoff_start_psymtab, xcoff_end_psymtab): Set
legacy_expand_psymtab.
* psympriv.h (struct partial_symtab) <expand_psymtab>: New
method.
(struct legacy_psymtab) <expand_psymtab>: Implement.
<legacy_expand_psymtab>: New member.
* mdebugread.c (mdebug_read_symtab): Call expand_psymtab.
(parse_partial_symbols): Set legacy_expand_psymtab.
(psymtab_to_symtab_1): Change argument order. Call
expand_psymtab.
(new_psymtab): Set legacy_expand_psymtab.
* dwarf2read.h (struct dwarf2_psymtab) <expand_psymtab>: Declare.
* dwarf2read.c (dwarf2_psymtab::read_symtab): Call
expand_psymtab.
(dwarf2_psymtab::expand_psymtab): Rename from
psymtab_to_symtab_1. Call expand_psymtab.
* dbxread.c (start_psymtab): Set legacy_expand_psymtab.
(dbx_end_psymtab): Likewise.
(dbx_psymtab_to_symtab_1): Change argument order. Call
expand_psymtab.
(dbx_read_symtab): Call expand_psymtab.
* ctfread.c (struct ctf_psymtab) <expand_psymtab>: Declare.
(ctf_psymtab::expand_psymtab): Rename from psymtab_to_symtab.
(ctf_psymtab::read_symtab): Call expand_psymtab.
2020-01-26 Tom Tromey <tom@tromey.com> 2020-01-26 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_read_symtab): Remove prints. Add assert. * xcoffread.c (xcoff_read_symtab): Remove prints. Add assert.

View File

@ -124,6 +124,7 @@ struct ctf_psymtab : public partial_symtab
} }
void read_symtab (struct objfile *) override; void read_symtab (struct objfile *) override;
void expand_psymtab (struct objfile *) override;
struct ctf_context *context; struct ctf_context *context;
}; };
@ -160,8 +161,6 @@ struct ctf_field_info
/* Local function prototypes */ /* Local function prototypes */
static void psymtab_to_symtab (ctf_psymtab *);
static int ctf_add_type_cb (ctf_id_t tid, void *arg); static int ctf_add_type_cb (ctf_id_t tid, void *arg);
static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid); static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid);
@ -1216,15 +1215,15 @@ ctf_end_symtab (ctf_psymtab *pst,
/* Read in full symbols for PST, and anything it depends on. */ /* Read in full symbols for PST, and anything it depends on. */
static void void
psymtab_to_symtab (ctf_psymtab *pst) ctf_psymtab::expand_psymtab (struct objfile *objfile)
{ {
struct symbol *sym; struct symbol *sym;
struct ctf_context *ccp; struct ctf_context *ccp;
gdb_assert (!pst->readin); gdb_assert (!readin);
ccp = pst->context; ccp = context;
/* Iterate over entries in data types section. */ /* Iterate over entries in data types section. */
if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR) if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR)
@ -1254,7 +1253,7 @@ psymtab_to_symtab (ctf_psymtab *pst)
set_symbol_address (ccp->of, sym, sym->linkage_name ()); set_symbol_address (ccp->of, sym, sym->linkage_name ());
} }
pst->readin = true; readin = true;
} }
/* Expand partial symbol table PST into a full symbol table. /* Expand partial symbol table PST into a full symbol table.
@ -1279,7 +1278,7 @@ ctf_psymtab::read_symtab (struct objfile *objfile)
offset = get_objfile_text_range (objfile, &tsize); offset = get_objfile_text_range (objfile, &tsize);
ctf_start_symtab (this, objfile, offset); ctf_start_symtab (this, objfile, offset);
psymtab_to_symtab (this); expand_psymtab (objfile);
set_text_low (offset); set_text_low (offset);
set_text_high (offset + tsize); set_text_high (offset + tsize);

View File

@ -268,7 +268,7 @@ static void read_ofile_symtab (struct objfile *, legacy_psymtab *);
static void dbx_read_symtab (legacy_psymtab *self, static void dbx_read_symtab (legacy_psymtab *self,
struct objfile *objfile); struct objfile *objfile);
static void dbx_psymtab_to_symtab_1 (struct objfile *, legacy_psymtab *); static void dbx_psymtab_to_symtab_1 (legacy_psymtab *, struct objfile *);
static void read_dbx_symtab (minimal_symbol_reader &, struct objfile *); static void read_dbx_symtab (minimal_symbol_reader &, struct objfile *);
@ -1909,6 +1909,7 @@ start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
XOBNEW (&objfile->objfile_obstack, struct symloc); XOBNEW (&objfile->objfile_obstack, struct symloc);
LDSYMOFF (result) = ldsymoff; LDSYMOFF (result) = ldsymoff;
result->legacy_read_symtab = dbx_read_symtab; result->legacy_read_symtab = dbx_read_symtab;
result->legacy_expand_psymtab = dbx_psymtab_to_symtab_1;
SYMBOL_SIZE (result) = symbol_size; SYMBOL_SIZE (result) = symbol_size;
SYMBOL_OFFSET (result) = symbol_table_offset; SYMBOL_OFFSET (result) = symbol_table_offset;
STRING_OFFSET (result) = string_table_offset; STRING_OFFSET (result) = string_table_offset;
@ -2039,6 +2040,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
subpst->number_of_dependencies = 1; subpst->number_of_dependencies = 1;
subpst->legacy_read_symtab = pst->legacy_read_symtab; subpst->legacy_read_symtab = pst->legacy_read_symtab;
subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
} }
if (num_includes == 0 if (num_includes == 0
@ -2064,7 +2066,7 @@ dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
} }
static void static void
dbx_psymtab_to_symtab_1 (struct objfile *objfile, legacy_psymtab *pst) dbx_psymtab_to_symtab_1 (legacy_psymtab *pst, struct objfile *objfile)
{ {
int i; int i;
@ -2091,8 +2093,7 @@ dbx_psymtab_to_symtab_1 (struct objfile *objfile, legacy_psymtab *pst)
wrap_here (""); /* Flush output. */ wrap_here (""); /* Flush output. */
gdb_flush (gdb_stdout); gdb_flush (gdb_stdout);
} }
dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]->expand_psymtab (objfile);
(legacy_psymtab *) pst->dependencies[i]);
} }
if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */ if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */
@ -2135,7 +2136,7 @@ dbx_read_symtab (legacy_psymtab *self, struct objfile *objfile)
data_holder.reset (stabs_data); data_holder.reset (stabs_data);
} }
dbx_psymtab_to_symtab_1 (objfile, self); self->expand_psymtab (objfile);
} }
/* Match with global symbols. This only needs to be done once, /* Match with global symbols. This only needs to be done once,

View File

@ -1513,8 +1513,6 @@ static void add_partial_subprogram (struct partial_die_info *pdi,
CORE_ADDR *lowpc, CORE_ADDR *highpc, CORE_ADDR *lowpc, CORE_ADDR *highpc,
int need_pc, struct dwarf2_cu *cu); int need_pc, struct dwarf2_cu *cu);
static void psymtab_to_symtab_1 (dwarf2_psymtab *);
static abbrev_table_up abbrev_table_read_table static abbrev_table_up abbrev_table_read_table
(struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwarf2_section_info *, (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwarf2_section_info *,
sect_offset); sect_offset);
@ -9510,7 +9508,7 @@ dwarf2_psymtab::read_symtab (struct objfile *objfile)
dwarf2_per_objfile->reading_partial_symbols = 0; dwarf2_per_objfile->reading_partial_symbols = 0;
psymtab_to_symtab_1 (this); expand_psymtab (objfile);
process_cu_includes (dwarf2_per_objfile); process_cu_includes (dwarf2_per_objfile);
} }
@ -9661,18 +9659,18 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
/* Read in full symbols for PST, and anything it depends on. */ /* Read in full symbols for PST, and anything it depends on. */
static void void
psymtab_to_symtab_1 (dwarf2_psymtab *pst) dwarf2_psymtab::expand_psymtab (struct objfile *objfile)
{ {
struct dwarf2_per_cu_data *per_cu; struct dwarf2_per_cu_data *per_cu;
int i; int i;
if (pst->readin) if (readin)
return; return;
for (i = 0; i < pst->number_of_dependencies; i++) for (i = 0; i < number_of_dependencies; i++)
if (!pst->dependencies[i]->readin if (!dependencies[i]->readin
&& pst->dependencies[i]->user == NULL) && dependencies[i]->user == NULL)
{ {
/* Inform about additional files that need to be read in. */ /* Inform about additional files that need to be read in. */
if (info_verbose) if (info_verbose)
@ -9682,20 +9680,20 @@ psymtab_to_symtab_1 (dwarf2_psymtab *pst)
wrap_here (""); wrap_here ("");
fputs_filtered ("and ", gdb_stdout); fputs_filtered ("and ", gdb_stdout);
wrap_here (""); wrap_here ("");
printf_filtered ("%s...", pst->dependencies[i]->filename); printf_filtered ("%s...", dependencies[i]->filename);
wrap_here (""); /* Flush output. */ wrap_here (""); /* Flush output. */
gdb_flush (gdb_stdout); gdb_flush (gdb_stdout);
} }
psymtab_to_symtab_1 ((dwarf2_psymtab *) pst->dependencies[i]); dependencies[i]->expand_psymtab (objfile);
} }
per_cu = pst->per_cu_data; per_cu = per_cu_data;
if (per_cu == NULL) if (per_cu == NULL)
{ {
/* It's an include file, no symbols to read for it. /* It's an include file, no symbols to read for it.
Everything is in the parent symtab. */ Everything is in the parent symtab. */
pst->readin = true; readin = true;
return; return;
} }

View File

@ -285,6 +285,7 @@ struct dwarf2_psymtab : public partial_symtab
} }
void read_symtab (struct objfile *) override; void read_symtab (struct objfile *) override;
void expand_psymtab (struct objfile *) override;
struct dwarf2_per_cu_data *per_cu_data; struct dwarf2_per_cu_data *per_cu_data;
}; };

View File

@ -253,8 +253,8 @@ static void sort_blocks (struct symtab *);
static legacy_psymtab *new_psymtab (const char *, struct objfile *); static legacy_psymtab *new_psymtab (const char *, struct objfile *);
static void psymtab_to_symtab_1 (struct objfile *objfile, static void psymtab_to_symtab_1 (legacy_psymtab *pst,
legacy_psymtab *, const char *); struct objfile *objfile);
static void add_block (struct block *, struct symtab *); static void add_block (struct block *, struct symtab *);
@ -279,7 +279,7 @@ mdebug_read_symtab (legacy_psymtab *self, struct objfile *objfile)
{ {
next_symbol_text_func = mdebug_next_symbol_text; next_symbol_text_func = mdebug_next_symbol_text;
psymtab_to_symtab_1 (objfile, self, self->filename); self->expand_psymtab (objfile);
/* Match with global symbols. This only needs to be done once, /* Match with global symbols. This only needs to be done once,
after all of the symtabs and dependencies have been read in. */ after all of the symtabs and dependencies have been read in. */
@ -2613,6 +2613,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
/* The way to turn this into a symtab is to call... */ /* The way to turn this into a symtab is to call... */
pst->legacy_read_symtab = mdebug_read_symtab; pst->legacy_read_symtab = mdebug_read_symtab;
pst->legacy_expand_psymtab = psymtab_to_symtab_1;
/* Set up language for the pst. /* Set up language for the pst.
The language from the FDR is used if it is unambigious (e.g. cfront The language from the FDR is used if it is unambigious (e.g. cfront
@ -3834,8 +3835,7 @@ mdebug_next_symbol_text (struct objfile *objfile)
The flow of control and even the memory allocation differs. FIXME. */ The flow of control and even the memory allocation differs. FIXME. */
static void static void
psymtab_to_symtab_1 (struct objfile *objfile, psymtab_to_symtab_1 (legacy_psymtab *pst, struct objfile *objfile)
legacy_psymtab *pst, const char *filename)
{ {
bfd_size_type external_sym_size; bfd_size_type external_sym_size;
bfd_size_type external_pdr_size; bfd_size_type external_pdr_size;
@ -3872,9 +3872,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
wrap_here (""); /* Flush output */ wrap_here (""); /* Flush output */
gdb_flush (gdb_stdout); gdb_flush (gdb_stdout);
} }
/* We only pass the filename for debug purposes. */ pst->dependencies[i]->expand_psymtab (objfile);
psymtab_to_symtab_1 (objfile, (legacy_psymtab *) pst->dependencies[i],
pst->dependencies[i]->filename);
} }
/* Do nothing if this is a dummy psymtab. */ /* Do nothing if this is a dummy psymtab. */
@ -4664,6 +4662,7 @@ new_psymtab (const char *name, struct objfile *objfile)
/* The way to turn this into a symtab is to call... */ /* The way to turn this into a symtab is to call... */
psymtab->legacy_read_symtab = mdebug_read_symtab; psymtab->legacy_read_symtab = mdebug_read_symtab;
psymtab->legacy_expand_psymtab = psymtab_to_symtab_1;
return (psymtab); return (psymtab);
} }

View File

@ -129,6 +129,11 @@ struct partial_symtab
table. */ table. */
virtual void read_symtab (struct objfile *) = 0; virtual void read_symtab (struct objfile *) = 0;
/* Psymtab expansion is done in two steps. The first step is a call
to read_symtab; but while that is in progress, calls to
expand_psymtab can be made. */
virtual void expand_psymtab (struct objfile *) = 0;
/* Return the raw low text address of this partial_symtab. */ /* Return the raw low text address of this partial_symtab. */
CORE_ADDR raw_text_low () const CORE_ADDR raw_text_low () const
{ {
@ -311,11 +316,21 @@ struct legacy_psymtab : public partial_symtab
(*legacy_read_symtab) (this, objf); (*legacy_read_symtab) (this, objf);
} }
void expand_psymtab (struct objfile *objf) override
{
(*legacy_expand_psymtab) (this, objf);
}
/* Pointer to function which will read in the symtab corresponding to /* Pointer to function which will read in the symtab corresponding to
this psymtab. */ this psymtab. */
void (*legacy_read_symtab) (legacy_psymtab *, struct objfile *) = nullptr; void (*legacy_read_symtab) (legacy_psymtab *, struct objfile *) = nullptr;
/* Pointer to function which will actually expand this psymtab into
a full symtab. */
void (*legacy_expand_psymtab) (legacy_psymtab *, struct objfile *) = nullptr;
/* Information that lets read_symtab() locate the part of the symbol table /* Information that lets read_symtab() locate the part of the symbol table
that this psymtab corresponds to. This information is private to the that this psymtab corresponds to. This information is private to the
format-dependent symbol reading routines. For further detail examine format-dependent symbol reading routines. For further detail examine

View File

@ -1817,7 +1817,7 @@ find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
} }
static void static void
xcoff_psymtab_to_symtab_1 (struct objfile *objfile, legacy_psymtab *pst) xcoff_psymtab_to_symtab_1 (legacy_psymtab *pst, struct objfile *objfile)
{ {
int i; int i;
@ -1847,8 +1847,7 @@ xcoff_psymtab_to_symtab_1 (struct objfile *objfile, legacy_psymtab *pst)
wrap_here (""); /* Flush output */ wrap_here (""); /* Flush output */
gdb_flush (gdb_stdout); gdb_flush (gdb_stdout);
} }
xcoff_psymtab_to_symtab_1 (objfile, pst->dependencies[i]->expand_psymtab (objfile);
(legacy_psymtab *) pst->dependencies[i]);
} }
if (((struct symloc *) pst->read_symtab_private)->numsyms != 0) if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
@ -1876,7 +1875,7 @@ xcoff_read_symtab (legacy_psymtab *self, struct objfile *objfile)
{ {
next_symbol_text_func = xcoff_next_symbol_text; next_symbol_text_func = xcoff_next_symbol_text;
xcoff_psymtab_to_symtab_1 (objfile, self); self->expand_psymtab (objfile);
/* Match with global symbols. This only needs to be done once, /* Match with global symbols. This only needs to be done once,
after all of the symtabs and dependencies have been read in. */ after all of the symtabs and dependencies have been read in. */
@ -1997,6 +1996,7 @@ xcoff_start_psymtab (struct objfile *objfile,
XOBNEW (&objfile->objfile_obstack, struct symloc); XOBNEW (&objfile->objfile_obstack, struct symloc);
((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum; ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
result->legacy_read_symtab = xcoff_read_symtab; result->legacy_read_symtab = xcoff_read_symtab;
result->legacy_expand_psymtab = xcoff_psymtab_to_symtab_1;
/* Deduce the source language from the filename for this psymtab. */ /* Deduce the source language from the filename for this psymtab. */
psymtab_language = deduce_language_from_filename (filename); psymtab_language = deduce_language_from_filename (filename);
@ -2059,6 +2059,7 @@ xcoff_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
subpst->number_of_dependencies = 1; subpst->number_of_dependencies = 1;
subpst->legacy_read_symtab = pst->legacy_read_symtab; subpst->legacy_read_symtab = pst->legacy_read_symtab;
subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
} }
if (num_includes == 0 if (num_includes == 0