Make symbol_set_names a member function

This also renames it to make it clearer that this is not a cheap
function (to compute_and_set_names).  Also renames name to m_name
to make the implementation of the renamed function more readable.

Most of the places that access sym->m_name directly were also changed
to call linkage_name () instead, to make it clearer which name they
are accessing.

gdb/ChangeLog:

2019-12-26  Christian Biesinger  <cbiesinger@google.com>

	* ada-lang.c (ada_decode_symbol): Update.
	* buildsym.c (add_symbol_to_list): Update.
	* coffread.c (process_coff_symbol): Update.
	* ctfread.c (ctf_add_enum_member_cb): Update.
	(new_symbol): Update.
	(ctf_add_var_cb): Update.
	* dwarf2read.c (fixup_go_packaging): Update.
	(dwarf2_compute_name): Update.
	(new_symbol): Update.
	* jit.c (finalize_symtab): Update.
	* language.c (language_alloc_type_symbol): Update.
	* mdebugread.c (new_symbol): Update.
	* minsyms.c (minimal_symbol_reader::record_full): Update.
	(minimal_symbol_reader::install): Update.
	* psymtab.c (print_partial_symbols): Update.
	(psymbol_hash): Update.
	(psymbol_compare): Update.
	(add_psymbol_to_bcache): Update.
	(maintenance_check_psymtabs): Update.
	* stabsread.c (define_symbol): Update.
	* symtab.c (symbol_set_names): Rename to...
	(general_symbol_info::compute_and_set_names): ...this.
	(general_symbol_info::natural_name): Update.
	(general_symbol_info::search_name): Update.
	(fixup_section): Update.
	* symtab.h (struct general_symbol_info) <name>: Rename to...
	<m_name>: ...this.
	<compute_and_set_names>: Rename from...
	(symbol_set_names): ...this.
	(SYMBOL_SET_NAMES): Remove.
	(struct symbol) <ctor>: Update.

Change-Id: I8da1f10cab4e0b89f19d5750fa4e6e2ac8d2b24f
This commit is contained in:
Christian Biesinger 2019-11-27 20:52:35 -06:00
parent b0d674e2b4
commit 4d4eaa3005
14 changed files with 106 additions and 81 deletions

View file

@ -1,3 +1,37 @@
2019-12-26 Christian Biesinger <cbiesinger@google.com>
* ada-lang.c (ada_decode_symbol): Update.
* buildsym.c (add_symbol_to_list): Update.
* coffread.c (process_coff_symbol): Update.
* ctfread.c (ctf_add_enum_member_cb): Update.
(new_symbol): Update.
(ctf_add_var_cb): Update.
* dwarf2read.c (fixup_go_packaging): Update.
(dwarf2_compute_name): Update.
(new_symbol): Update.
* jit.c (finalize_symtab): Update.
* language.c (language_alloc_type_symbol): Update.
* mdebugread.c (new_symbol): Update.
* minsyms.c (minimal_symbol_reader::record_full): Update.
(minimal_symbol_reader::install): Update.
* psymtab.c (print_partial_symbols): Update.
(psymbol_hash): Update.
(psymbol_compare): Update.
(add_psymbol_to_bcache): Update.
(maintenance_check_psymtabs): Update.
* stabsread.c (define_symbol): Update.
* symtab.c (symbol_set_names): Rename to...
(general_symbol_info::compute_and_set_names): ...this.
(general_symbol_info::natural_name): Update.
(general_symbol_info::search_name): Update.
(fixup_section): Update.
* symtab.h (struct general_symbol_info) <name>: Rename to...
<m_name>: ...this.
<compute_and_set_names>: Rename from...
(symbol_set_names): ...this.
(SYMBOL_SET_NAMES): Remove.
(struct symbol) <ctor>: Update.
2019-12-26 Christian Biesinger <cbiesinger@google.com> 2019-12-26 Christian Biesinger <cbiesinger@google.com>
* NEWS: Mention that multithreaded symbol loading is now on by * NEWS: Mention that multithreaded symbol loading is now on by

View file

@ -1376,7 +1376,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
if (!gsymbol->ada_mangled) if (!gsymbol->ada_mangled)
{ {
std::string decoded = ada_decode (gsymbol->name); std::string decoded = ada_decode (gsymbol->linkage_name ());
struct obstack *obstack = gsymbol->language_specific.obstack; struct obstack *obstack = gsymbol->language_specific.obstack;
gsymbol->ada_mangled = 1; gsymbol->ada_mangled = 1;

View file

@ -135,7 +135,7 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
struct pending *link; struct pending *link;
/* If this is an alias for another symbol, don't add it. */ /* If this is an alias for another symbol, don't add it. */
if (symbol->name && symbol->name[0] == '#') if (symbol->linkage_name () && symbol->linkage_name ()[0] == '#')
return; return;
/* We keep PENDINGSIZE symbols in each link of the list. If we /* We keep PENDINGSIZE symbols in each link of the list. If we

View file

@ -1568,7 +1568,7 @@ process_coff_symbol (struct coff_symbol *cs,
name = EXTERNAL_NAME (name, objfile->obfd); name = EXTERNAL_NAME (name, objfile->obfd);
sym->set_language (get_current_subfile ()->language, sym->set_language (get_current_subfile ()->language,
&objfile->objfile_obstack); &objfile->objfile_obstack);
SYMBOL_SET_NAMES (sym, name, true, objfile); sym->compute_and_set_names (name, true, objfile->per_bfd);
/* default assumptions */ /* default assumptions */
SYMBOL_VALUE (sym) = cs->c_value; SYMBOL_VALUE (sym) = cs->c_value;

View file

@ -399,7 +399,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
OBJSTAT (ccp->of, n_syms++); OBJSTAT (ccp->of, n_syms++);
sym->set_language (language_c, &ccp->of->objfile_obstack); sym->set_language (language_c, &ccp->of->objfile_obstack);
SYMBOL_SET_NAMES (sym, name, false, ccp->of); sym->compute_and_set_names (name, false, ccp->of->per_bfd);
SYMBOL_ACLASS_INDEX (sym) = LOC_CONST; SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN; SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_TYPE (sym) = fip->ptype; SYMBOL_TYPE (sym) = fip->ptype;
@ -428,7 +428,7 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
OBJSTAT (objfile, n_syms++); OBJSTAT (objfile, n_syms++);
sym->set_language (language_c, &objfile->objfile_obstack); sym->set_language (language_c, &objfile->objfile_obstack);
SYMBOL_SET_NAMES (sym, name.get (), true, objfile); sym->compute_and_set_names (name.get (), true, objfile->per_bfd);
SYMBOL_DOMAIN (sym) = VAR_DOMAIN; SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
@ -1048,7 +1048,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
if (type) if (type)
{ {
sym = new_symbol (ccp, type, id); sym = new_symbol (ccp, type, id);
SYMBOL_SET_NAMES (sym, name, false, ccp->of); sym->compute_and_set_names (name, false, ccp->of->per_bfd);
} }
break; break;
case CTF_K_STRUCT: case CTF_K_STRUCT:
@ -1064,7 +1064,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
SYMBOL_TYPE (sym) = type; SYMBOL_TYPE (sym) = type;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN; SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
SYMBOL_SET_NAMES (sym, name, false, ccp->of); sym->compute_and_set_names (name, false, ccp->of->per_bfd);
add_symbol_to_list (sym, ccp->builder->get_global_symbols ()); add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
break; break;
default: default:

View file

@ -9953,7 +9953,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
sym = allocate_symbol (objfile); sym = allocate_symbol (objfile);
sym->set_language (language_go, &objfile->objfile_obstack); sym->set_language (language_go, &objfile->objfile_obstack);
SYMBOL_SET_NAMES (sym, saved_package_name, false, objfile); sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
/* This is not VAR_DOMAIN because we want a way to ensure a lookup of, /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
e.g., "main" finds the "main" module and not C's main(). */ e.g., "main" finds the "main" module and not C's main(). */
SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
@ -10878,7 +10878,7 @@ dwarf2_compute_name (const char *name,
/* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
but otherwise compute it by typename_concat inside GDB. but otherwise compute it by typename_concat inside GDB.
FIXME: Actually this is not really true, or at least not always true. FIXME: Actually this is not really true, or at least not always true.
It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle It's all very confusing. compute_and_set_names doesn't try to demangle
Fortran names because there is no mangling standard. So new_symbol Fortran names because there is no mangling standard. So new_symbol
will set the demangled name to the result of dwarf2_full_name, and it is will set the demangled name to the result of dwarf2_full_name, and it is
the demangled name that GDB uses if it exists. */ the demangled name that GDB uses if it exists. */
@ -21873,7 +21873,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
/* Cache this symbol's name and the name's demangled form (if any). */ /* Cache this symbol's name and the name's demangled form (if any). */
sym->set_language (cu->language, &objfile->objfile_obstack); sym->set_language (cu->language, &objfile->objfile_obstack);
linkagename = dwarf2_physname (name, die, cu); linkagename = dwarf2_physname (name, die, cu);
SYMBOL_SET_NAMES (sym, linkagename, false, objfile); sym->compute_and_set_names (linkagename, false, objfile->per_bfd);
/* Fortran does not have mangling standard and the mangling does differ /* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */ between gfortran, iFort etc. */

View file

@ -672,7 +672,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
SYMBOL_TYPE (block_name) = lookup_function_type (block_type); SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
SYMBOL_BLOCK_VALUE (block_name) = new_block; SYMBOL_BLOCK_VALUE (block_name) = new_block;
block_name->name = obstack_strdup (&objfile->objfile_obstack, block_name->m_name = obstack_strdup (&objfile->objfile_obstack,
gdb_block_iter.name.get ()); gdb_block_iter.name.get ());
BLOCK_FUNCTION (new_block) = block_name; BLOCK_FUNCTION (new_block) = block_name;

View file

@ -1052,7 +1052,7 @@ language_alloc_type_symbol (enum language lang, struct type *type)
gdbarch = TYPE_OWNER (type).gdbarch; gdbarch = TYPE_OWNER (type).gdbarch;
symbol = new (gdbarch_obstack (gdbarch)) struct symbol (); symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
symbol->name = TYPE_NAME (type); symbol->m_name = TYPE_NAME (type);
symbol->set_language (lang, nullptr); symbol->set_language (lang, nullptr);
symbol->owner.arch = gdbarch; symbol->owner.arch = gdbarch;
SYMBOL_OBJFILE_OWNED (symbol) = 0; SYMBOL_OBJFILE_OWNED (symbol) = 0;

View file

@ -4762,7 +4762,7 @@ new_symbol (const char *name)
struct symbol *s = allocate_symbol (mdebugread_objfile); struct symbol *s = allocate_symbol (mdebugread_objfile);
s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack); s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack);
SYMBOL_SET_NAMES (s, name, true, mdebugread_objfile); s->compute_and_set_names (name, true, mdebugread_objfile->per_bfd);
return s; return s;
} }

View file

@ -1132,10 +1132,10 @@ minimal_symbol_reader::record_full (gdb::string_view name,
&m_objfile->per_bfd->storage_obstack); &m_objfile->per_bfd->storage_obstack);
if (copy_name) if (copy_name)
msymbol->name = obstack_strndup (&m_objfile->per_bfd->storage_obstack, msymbol->m_name = obstack_strndup (&m_objfile->per_bfd->storage_obstack,
name.data (), name.size ()); name.data (), name.size ());
else else
msymbol->name = name.data (); msymbol->m_name = name.data ();
SET_MSYMBOL_VALUE_ADDRESS (msymbol, address); SET_MSYMBOL_VALUE_ADDRESS (msymbol, address);
MSYMBOL_SECTION (msymbol) = section; MSYMBOL_SECTION (msymbol) = section;
@ -1397,22 +1397,23 @@ minimal_symbol_reader::install ()
for (minimal_symbol *msym = start; msym < end; ++msym) for (minimal_symbol *msym = start; msym < end; ++msym)
{ {
size_t idx = msym - msymbols; size_t idx = msym - msymbols;
hash_values[idx].name_length = strlen (msym->name); hash_values[idx].name_length = strlen (msym->linkage_name ());
if (!msym->name_set) if (!msym->name_set)
{ {
/* This will be freed later, by symbol_set_names. */ /* This will be freed later, by compute_and_set_names. */
char *demangled_name char *demangled_name
= symbol_find_demangled_name (msym, msym->name); = symbol_find_demangled_name (msym, msym->linkage_name ());
symbol_set_demangled_name symbol_set_demangled_name
(msym, demangled_name, (msym, demangled_name,
&m_objfile->per_bfd->storage_obstack); &m_objfile->per_bfd->storage_obstack);
msym->name_set = 1; msym->name_set = 1;
} }
/* This mangled_name_hash computation has to be outside of /* This mangled_name_hash computation has to be outside of
the name_set check, or symbol_set_names below will the name_set check, or compute_and_set_names below will
be called with an invalid hash value. */ be called with an invalid hash value. */
hash_values[idx].mangled_name_hash hash_values[idx].mangled_name_hash
= fast_hash (msym->name, hash_values[idx].name_length); = fast_hash (msym->linkage_name (),
hash_values[idx].name_length);
hash_values[idx].minsym_hash hash_values[idx].minsym_hash
= msymbol_hash (msym->linkage_name ()); = msymbol_hash (msym->linkage_name ());
/* We only use this hash code if the search name differs /* We only use this hash code if the search name differs
@ -1431,9 +1432,8 @@ minimal_symbol_reader::install ()
for (minimal_symbol *msym = start; msym < end; ++msym) for (minimal_symbol *msym = start; msym < end; ++msym)
{ {
size_t idx = msym - msymbols; size_t idx = msym - msymbols;
symbol_set_names msym->compute_and_set_names
(msym, (gdb::string_view (msym->linkage_name (),
gdb::string_view(msym->name,
hash_values[idx].name_length), hash_values[idx].name_length),
false, false,
m_objfile->per_bfd, m_objfile->per_bfd,

View file

@ -835,7 +835,7 @@ print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile,
while (count-- > 0) while (count-- > 0)
{ {
QUIT; QUIT;
fprintf_filtered (outfile, " `%s'", (*p)->ginfo.name); fprintf_filtered (outfile, " `%s'", (*p)->ginfo.linkage_name ());
if ((*p)->ginfo.demangled_name () != NULL) if ((*p)->ginfo.demangled_name () != NULL)
{ {
fprintf_filtered (outfile, " `%s'", fprintf_filtered (outfile, " `%s'",
@ -1534,9 +1534,9 @@ psymbol_hash (const void *addr, int length)
h = fast_hash (&lang, sizeof (unsigned int), h); h = fast_hash (&lang, sizeof (unsigned int), h);
h = fast_hash (&domain, sizeof (unsigned int), h); h = fast_hash (&domain, sizeof (unsigned int), h);
h = fast_hash (&theclass, sizeof (unsigned int), h); h = fast_hash (&theclass, sizeof (unsigned int), h);
/* Note that psymbol names are interned via symbol_set_names, so /* Note that psymbol names are interned via compute_and_set_names, so
there's no need to hash the contents of the name here. */ there's no need to hash the contents of the name here. */
h = fast_hash (&psymbol->ginfo.name, sizeof (psymbol->ginfo.name), h); h = fast_hash (&psymbol->ginfo.m_name, sizeof (psymbol->ginfo.m_name), h);
return h; return h;
} }
@ -1557,9 +1557,9 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
&& sym1->domain == sym2->domain && sym1->domain == sym2->domain
&& sym1->aclass == sym2->aclass && sym1->aclass == sym2->aclass
/* Note that psymbol names are interned via /* Note that psymbol names are interned via
symbol_set_names, so there's no need to compare the compute_and_set_names, so there's no need to compare the
contents of the name here. */ contents of the name here. */
&& sym1->ginfo.name == sym2->ginfo.name); && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ());
} }
/* Helper function, initialises partial symbol structure and stashes /* Helper function, initialises partial symbol structure and stashes
@ -1585,8 +1585,7 @@ add_psymbol_to_bcache (gdb::string_view name, bool copy_name,
psymbol.domain = domain; psymbol.domain = domain;
psymbol.aclass = theclass; psymbol.aclass = theclass;
psymbol.ginfo.set_language (language, objfile->partial_symtabs->obstack ()); psymbol.ginfo.set_language (language, objfile->partial_symtabs->obstack ());
symbol_set_names (&psymbol.ginfo, name, copy_name, psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd);
objfile->per_bfd);
/* Stash the partial symbol away in the cache. */ /* Stash the partial symbol away in the cache. */
return ((struct partial_symbol *) return ((struct partial_symbol *)
@ -2110,7 +2109,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
if (!sym) if (!sym)
{ {
printf_filtered ("Static symbol `"); printf_filtered ("Static symbol `");
puts_filtered ((*psym)->ginfo.name); puts_filtered ((*psym)->ginfo.linkage_name ());
printf_filtered ("' only found in "); printf_filtered ("' only found in ");
puts_filtered (ps->filename); puts_filtered (ps->filename);
printf_filtered (" psymtab\n"); printf_filtered (" psymtab\n");
@ -2128,7 +2127,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
if (!sym) if (!sym)
{ {
printf_filtered ("Global symbol `"); printf_filtered ("Global symbol `");
puts_filtered ((*psym)->ginfo.name); puts_filtered ((*psym)->ginfo.linkage_name ());
printf_filtered ("' only found in "); printf_filtered ("' only found in ");
puts_filtered (ps->filename); puts_filtered (ps->filename);
printf_filtered (" psymtab\n"); printf_filtered (" psymtab\n");

View file

@ -749,14 +749,10 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
new_name = cp_canonicalize_string (name); new_name = cp_canonicalize_string (name);
} }
if (!new_name.empty ()) if (!new_name.empty ())
{ sym->compute_and_set_names (new_name, true, objfile->per_bfd);
SYMBOL_SET_NAMES (sym,
new_name,
1, objfile);
}
else else
SYMBOL_SET_NAMES (sym, gdb::string_view (string, p - string), true, sym->compute_and_set_names (gdb::string_view (string, p - string), true,
objfile); objfile->per_bfd);
if (sym->language () == language_cplus) if (sym->language () == language_cplus)
cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym, cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,

View file

@ -855,19 +855,19 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
so the pointer can be discarded after calling this function. */ so the pointer can be discarded after calling this function. */
void void
symbol_set_names (struct general_symbol_info *gsymbol, general_symbol_info::compute_and_set_names (gdb::string_view linkage_name,
gdb::string_view linkage_name, bool copy_name, bool copy_name,
struct objfile_per_bfd_storage *per_bfd, objfile_per_bfd_storage *per_bfd,
gdb::optional<hashval_t> hash) gdb::optional<hashval_t> hash)
{ {
struct demangled_name_entry **slot; struct demangled_name_entry **slot;
if (gsymbol->language () == language_ada) if (language () == language_ada)
{ {
/* In Ada, we do the symbol lookups using the mangled name, so /* In Ada, we do the symbol lookups using the mangled name, so
we can save some space by not storing the demangled name. */ we can save some space by not storing the demangled name. */
if (!copy_name) if (!copy_name)
gsymbol->name = linkage_name.data (); m_name = linkage_name.data ();
else else
{ {
char *name = (char *) obstack_alloc (&per_bfd->storage_obstack, char *name = (char *) obstack_alloc (&per_bfd->storage_obstack,
@ -875,9 +875,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
memcpy (name, linkage_name.data (), linkage_name.length ()); memcpy (name, linkage_name.data (), linkage_name.length ());
name[linkage_name.length ()] = '\0'; name[linkage_name.length ()] = '\0';
gsymbol->name = name; m_name = name;
} }
symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack); symbol_set_demangled_name (this, NULL, &per_bfd->storage_obstack);
return; return;
} }
@ -896,7 +896,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
if (*slot == NULL if (*slot == NULL
/* A C version of the symbol may have already snuck into the table. /* A C version of the symbol may have already snuck into the table.
This happens to, e.g., main.init (__go_init_main). Cope. */ This happens to, e.g., main.init (__go_init_main). Cope. */
|| (gsymbol->language () == language_go && (*slot)->demangled == nullptr)) || (language () == language_go && (*slot)->demangled == nullptr))
{ {
/* A 0-terminated copy of the linkage name. Callers must set COPY_NAME /* A 0-terminated copy of the linkage name. Callers must set COPY_NAME
to true if the string might not be nullterminated. We have to make to true if the string might not be nullterminated. We have to make
@ -920,9 +920,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
allocated from the heap and needs to be freed by us, just allocated from the heap and needs to be freed by us, just
like if we called symbol_find_demangled_name here. */ like if we called symbol_find_demangled_name here. */
gdb::unique_xmalloc_ptr<char> demangled_name gdb::unique_xmalloc_ptr<char> demangled_name
(gsymbol->language_specific.demangled_name (language_specific.demangled_name
? const_cast<char *> (gsymbol->language_specific.demangled_name) ? const_cast<char *> (language_specific.demangled_name)
: symbol_find_demangled_name (gsymbol, linkage_name_copy.data ())); : symbol_find_demangled_name (this, linkage_name_copy.data ()));
/* Suppose we have demangled_name==NULL, copy_name==0, and /* Suppose we have demangled_name==NULL, copy_name==0, and
linkage_name_copy==linkage_name. In this case, we already have the linkage_name_copy==linkage_name. In this case, we already have the
@ -957,18 +957,17 @@ symbol_set_names (struct general_symbol_info *gsymbol,
(gdb::string_view (mangled_ptr, linkage_name.length ())); (gdb::string_view (mangled_ptr, linkage_name.length ()));
} }
(*slot)->demangled = std::move (demangled_name); (*slot)->demangled = std::move (demangled_name);
(*slot)->language = gsymbol->language (); (*slot)->language = language ();
} }
else if (gsymbol->language () == language_unknown else if (language () == language_unknown || language () == language_auto)
|| gsymbol->language () == language_auto) m_language = (*slot)->language;
gsymbol->m_language = (*slot)->language;
gsymbol->name = (*slot)->mangled.data (); m_name = (*slot)->mangled.data ();
if ((*slot)->demangled != nullptr) if ((*slot)->demangled != nullptr)
symbol_set_demangled_name (gsymbol, (*slot)->demangled.get (), symbol_set_demangled_name (this, (*slot)->demangled.get (),
&per_bfd->storage_obstack); &per_bfd->storage_obstack);
else else
symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack); symbol_set_demangled_name (this, NULL, &per_bfd->storage_obstack);
} }
/* See symtab.h. */ /* See symtab.h. */
@ -991,7 +990,7 @@ general_symbol_info::natural_name () const
default: default:
break; break;
} }
return name; return linkage_name ();
} }
/* See symtab.h. */ /* See symtab.h. */
@ -1025,7 +1024,7 @@ const char *
general_symbol_info::search_name () const general_symbol_info::search_name () const
{ {
if (language () == language_ada) if (language () == language_ada)
return name; return linkage_name ();
else else
return natural_name (); return natural_name ();
} }
@ -1670,7 +1669,8 @@ fixup_section (struct general_symbol_info *ginfo,
e.g. on PowerPC64, where the minimal symbol for a function will e.g. on PowerPC64, where the minimal symbol for a function will
point to the function descriptor, while the debug symbol will point to the function descriptor, while the debug symbol will
point to the actual function code. */ point to the actual function code. */
msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->name, objfile); msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->linkage_name (),
objfile);
if (msym) if (msym)
ginfo->section = MSYMBOL_SECTION (msym); ginfo->section = MSYMBOL_SECTION (msym);
else else

View file

@ -389,7 +389,7 @@ struct general_symbol_info
and linkage_name () are different. */ and linkage_name () are different. */
const char *linkage_name () const const char *linkage_name () const
{ return name; } { return m_name; }
/* Return SYMBOL's "natural" name, i.e. the name that it was called in /* Return SYMBOL's "natural" name, i.e. the name that it was called in
the original source code. In languages like C++ where symbols may the original source code. In languages like C++ where symbols may
@ -419,11 +419,11 @@ struct general_symbol_info
/* Set just the linkage name of a symbol; do not try to demangle /* Set just the linkage name of a symbol; do not try to demangle
it. Used for constructs which do not have a mangled name, it. Used for constructs which do not have a mangled name,
e.g. struct tags. Unlike SYMBOL_SET_NAMES, linkage_name must e.g. struct tags. Unlike compute_and_set_names, linkage_name must
be terminated and either already on the objfile's obstack or be terminated and either already on the objfile's obstack or
permanently allocated. */ permanently allocated. */
void set_linkage_name (const char *linkage_name) void set_linkage_name (const char *linkage_name)
{ name = linkage_name; } { m_name = linkage_name; }
enum language language () const enum language language () const
{ return m_language; } { return m_language; }
@ -432,13 +432,21 @@ struct general_symbol_info
depending upon the language for the symbol. */ depending upon the language for the symbol. */
void set_language (enum language language, struct obstack *obstack); void set_language (enum language language, struct obstack *obstack);
/* Set the linkage and natural names of a symbol, by demangling
the linkage name. If linkage_name may not be nullterminated,
copy_name must be set to true. */
void compute_and_set_names (gdb::string_view linkage_name, bool copy_name,
struct objfile_per_bfd_storage *per_bfd,
gdb::optional<hashval_t> hash
= gdb::optional<hashval_t> ());
/* Name of the symbol. This is a required field. Storage for the /* Name of the symbol. This is a required field. Storage for the
name is allocated on the objfile_obstack for the associated name is allocated on the objfile_obstack for the associated
objfile. For languages like C++ that make a distinction between objfile. For languages like C++ that make a distinction between
the mangled name and demangled name, this is the mangled the mangled name and demangled name, this is the mangled
name. */ name. */
const char *name; const char *m_name;
/* Value of the symbol. Which member of this union to use, and what /* Value of the symbol. Which member of this union to use, and what
it means, depends on what kind of symbol this is and its it means, depends on what kind of symbol this is and its
@ -544,18 +552,6 @@ extern CORE_ADDR get_symbol_address (const struct symbol *sym);
extern char *symbol_find_demangled_name (struct general_symbol_info *gsymbol, extern char *symbol_find_demangled_name (struct general_symbol_info *gsymbol,
const char *mangled); const char *mangled);
/* Set the linkage and natural names of a symbol, by demangling
the linkage name. If linkage_name may not be nullterminated,
copy_name must be set to true. */
#define SYMBOL_SET_NAMES(symbol,linkage_name,copy_name,objfile) \
symbol_set_names ((symbol), linkage_name, copy_name, \
(objfile)->per_bfd)
extern void symbol_set_names (struct general_symbol_info *symbol,
gdb::string_view linkage_name, bool copy_name,
struct objfile_per_bfd_storage *per_bfd,
gdb::optional<hashval_t> hash
= gdb::optional<hashval_t> ());
/* Return true if NAME matches the "search" name of SYMBOL, according /* Return true if NAME matches the "search" name of SYMBOL, according
to the symbol's language. */ to the symbol's language. */
#define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \ #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
@ -1092,7 +1088,7 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
{ {
/* We can't use an initializer list for members of a base class, and /* We can't use an initializer list for members of a base class, and
general_symbol_info needs to stay a POD type. */ general_symbol_info needs to stay a POD type. */
name = nullptr; m_name = nullptr;
value.ivalue = 0; value.ivalue = 0;
language_specific.obstack = nullptr; language_specific.obstack = nullptr;
m_language = language_unknown; m_language = language_unknown;