Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Christian Biesinger (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: gdb-patches@sourceware.org
Cc: Christian Biesinger <cbiesinger@google.com>
Subject: [review] Only make a nullterminated string if we need to
Date: Tue, 22 Oct 2019 22:30:00 -0000	[thread overview]
Message-ID: <gerrit.1571783424000.I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1571783424000.I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2@gnutoolchain-gerrit.osci.io>

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/222
......................................................................

Only make a nullterminated string if we need to

As of 7bb43059820c5febb4509b15202a93efde442bc6, we no longer need
a nullterminated linkage_name to look up the entry in the hash table.

So this patch makes it so we only make the copy if the entry was
not found.

gdb/ChangeLog:

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

	* symtab.c (symbol_set_names): Only make a nullterminated copy of
	linkage_name if the entry was not found and we need to demangle.

Change-Id: I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2
---
M gdb/symtab.c
1 file changed, 16 insertions(+), 16 deletions(-)



diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0a87fec..787c4b6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -829,8 +829,6 @@
 		  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)
     {
@@ -855,20 +853,7 @@
   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));
@@ -880,6 +865,21 @@
       || (gsymbol->language == language_go
 	  && (*slot)->demangled[0] == '\0'))
     {
+      /* A 0-terminated copy of the linkage name.  */
+      const char *linkage_name_copy;
+      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;
+
       char *demangled_name_ptr
 	= symbol_find_demangled_name (gsymbol, linkage_name_copy);
       gdb::unique_xmalloc_ptr<char> demangled_name (demangled_name_ptr);


       reply	other threads:[~2019-10-22 22:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 22:30 Christian Biesinger (Code Review) [this message]
2019-10-25 17:59 ` Tom Tromey (Code Review)
2019-10-25 18:04 ` Christian Biesinger (Code Review)
2019-10-25 20:02 ` [review v2] " Christian Biesinger (Code Review)
2019-10-25 20:08 ` Christian Biesinger (Code Review)
2019-10-28 18:51 ` [review v3] " Christian Biesinger (Code Review)
2019-10-28 19:01 ` [review v4] " Christian Biesinger (Code Review)
2019-10-29 19:10 ` Tom Tromey (Code Review)
2019-10-29 19:28 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-10-29 19:28 ` Sourceware to Gerrit sync (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gerrit.1571783424000.I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox