Only clear the minsym array when necessary

The array starts out initialized to zero:
  minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE] {};

So we only need to explicitly clear it if there were previous minsyms
added to it. This patch does that.

gdb/ChangeLog:

2019-10-30  Christian Biesinger  <cbiesinger@google.com>

	* minsyms.c (clear_minimal_symbol_hash_tables): New function.
	(build_minimal_symbol_hash_tables): Code to clear the table moved
	to clear_minimal_symbol_hash_tables.
	(minimal_symbol_reader::install): Call clear_minimal_symbol_hash_tables
	when needed.

Change-Id: I7da994fe6747f67714e7efe9fdbb0dbc4d6ea532
This commit is contained in:
Christian Biesinger
2019-10-29 17:14:48 -05:00
parent 1820262bc9
commit 808590ec5a
2 changed files with 22 additions and 8 deletions

View File

@ -1,3 +1,11 @@
2019-10-30 Christian Biesinger <cbiesinger@google.com>
* minsyms.c (clear_minimal_symbol_hash_tables): New function.
(build_minimal_symbol_hash_tables): Code to clear the table moved
to clear_minimal_symbol_hash_tables.
(minimal_symbol_reader::install): Call clear_minimal_symbol_hash_tables
when needed.
2019-10-29 Simon Marchi <simon.marchi@polymtl.ca> 2019-10-29 Simon Marchi <simon.marchi@polymtl.ca>
* infcmd.c: Remove includes. * infcmd.c: Remove includes.

View File

@ -1238,6 +1238,16 @@ compact_minimal_symbols (struct minimal_symbol *msymbol, int mcount,
return (mcount); return (mcount);
} }
static void
clear_minimal_symbol_hash_tables (struct objfile *objfile)
{
for (size_t i = 0; i < MINIMAL_SYMBOL_HASH_SIZE; i++)
{
objfile->per_bfd->msymbol_hash[i] = 0;
objfile->per_bfd->msymbol_demangled_hash[i] = 0;
}
}
/* Build (or rebuild) the minimal symbol hash tables. This is necessary /* Build (or rebuild) the minimal symbol hash tables. This is necessary
after compacting or sorting the table since the entries move around after compacting or sorting the table since the entries move around
thus causing the internal minimal_symbol pointers to become jumbled. */ thus causing the internal minimal_symbol pointers to become jumbled. */
@ -1248,14 +1258,7 @@ build_minimal_symbol_hash_tables (struct objfile *objfile)
int i; int i;
struct minimal_symbol *msym; struct minimal_symbol *msym;
/* Clear the hash tables. */ /* (Re)insert the actual entries. */
for (i = 0; i < MINIMAL_SYMBOL_HASH_SIZE; i++)
{
objfile->per_bfd->msymbol_hash[i] = 0;
objfile->per_bfd->msymbol_demangled_hash[i] = 0;
}
/* Now, (re)insert the actual entries. */
for ((i = objfile->per_bfd->minimal_symbol_count, for ((i = objfile->per_bfd->minimal_symbol_count,
msym = objfile->per_bfd->msymbols.get ()); msym = objfile->per_bfd->msymbols.get ());
i > 0; i > 0;
@ -1345,6 +1348,9 @@ minimal_symbol_reader::install ()
The strings themselves are also located in the storage_obstack The strings themselves are also located in the storage_obstack
of this objfile. */ of this objfile. */
if (m_objfile->per_bfd->minimal_symbol_count != 0)
clear_minimal_symbol_hash_tables (m_objfile);
m_objfile->per_bfd->minimal_symbol_count = mcount; m_objfile->per_bfd->minimal_symbol_count = mcount;
m_objfile->per_bfd->msymbols = std::move (msym_holder); m_objfile->per_bfd->msymbols = std::move (msym_holder);