struct objfile_per_bfd_storage *per_bfd)
{
struct demangled_name_entry **slot;
- /* A 0-terminated copy of the linkage name. */
- const char *linkage_name_copy;
if (gsymbol->language == language_ada)
{
if (per_bfd->demangled_names_hash == NULL)
create_demangled_names_hash (per_bfd);
- if (linkage_name[len] != '\0')
- {
- char *alloc_name;
-
- alloc_name = (char *) alloca (len + 1);
- memcpy (alloc_name, linkage_name, len);
- alloc_name[len] = '\0';
-
- linkage_name_copy = alloc_name;
- }
- else
- linkage_name_copy = linkage_name;
-
- struct demangled_name_entry entry (gdb::string_view (linkage_name_copy, len));
+ struct demangled_name_entry entry (gdb::string_view (linkage_name, len));
slot = ((struct demangled_name_entry **)
htab_find_slot (per_bfd->demangled_names_hash.get (),
&entry, INSERT));
This happens to, e.g., main.init (__go_init_main). Cope. */
|| (gsymbol->language == language_go && (*slot)->demangled == nullptr))
{
+ /* 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
+ this copy because demangling needs a nullterminated string. */
+ const char *linkage_name_copy;
+ if (copy_name)
+ {
+ char *alloc_name = (char *) alloca (len + 1);
+ memcpy (alloc_name, linkage_name, len);
+ alloc_name[len] = '\0';
+
+ linkage_name_copy = alloc_name;
+ }
+ else
+ linkage_name_copy = linkage_name;
+
gdb::unique_xmalloc_ptr<char> demangled_name_ptr
(symbol_find_demangled_name (gsymbol, linkage_name_copy));
It turns out that it is actually important to still save such
an entry in the hash table, because storing this name gives
us better bcache hit rates for partial symbols. */
- if (!copy_name && linkage_name_copy == linkage_name)
+ if (!copy_name)
{
*slot
= ((struct demangled_name_entry *)
obstack_alloc (&per_bfd->storage_obstack,
sizeof (demangled_name_entry) + len + 1));
char *mangled_ptr = reinterpret_cast<char *> (*slot + 1);
- strcpy (mangled_ptr, linkage_name_copy);
+ memcpy (mangled_ptr, linkage_name, len);
+ mangled_ptr [len] = '\0';
new (*slot) demangled_name_entry
(gdb::string_view (mangled_ptr, len));
}
(symbol)->ginfo.name = (linkage_name)
/* Set the linkage and natural names of a symbol, by demangling
- the linkage name. */
+ the linkage name. If linkage_name may not be nullterminated,
+ copy_name must be set to true. */
#define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, \
(objfile)->per_bfd)