public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Avoid some copying in psymtab.c
Date: Wed,  1 Apr 2020 13:55:38 +0000 (GMT)	[thread overview]
Message-ID: <20200401135538.254E3385DC31@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8c072cb6a19abdc9d4b93c19a1d609fe1a486c32

commit 8c072cb6a19abdc9d4b93c19a1d609fe1a486c32
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Apr 1 07:47:13 2020 -0600

    Avoid some copying in psymtab.c
    
    I noticed that psymtab.c was always copying the search string in
    psymtab_search_name, even when it wasn't necessary.  This patch
    removes this function in favor of using the make_ignore_params feature
    of lookup_name_info.
    
    Once I had done that, I noticed that lookup_partial_symbol was
    creating a lookup_name_info.  However, this function called in loops,
    causing even more excess allocation.  This patch further fixes this by
    hosting the creation of the lookup_name_info into the callers.
    
    gdb/ChangeLog
    2020-04-01  Tom Tromey  <tromey@adacore.com>
    
            * psymtab.c (psymtab_search_name): Remove function.
            (psym_lookup_symbol): Create search name and lookup name here.
            (lookup_partial_symbol): Remove "name" parameter; add
            lookup_name.
            (psym_expand_symtabs_for_function): Update.

Diff:
---
 gdb/ChangeLog |  8 ++++++++
 gdb/psymtab.c | 59 +++++++++++++++++------------------------------------------
 2 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 116a9b36dcd..7c1d84c330f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2020-04-01  Tom Tromey  <tromey@adacore.com>
+
+	* psymtab.c (psymtab_search_name): Remove function.
+	(psym_lookup_symbol): Create search name and lookup name here.
+	(lookup_partial_symbol): Remove "name" parameter; add
+	lookup_name.
+	(psym_expand_symtabs_for_function): Update.
+
 2020-03-31  Joel Jones  <joelkevinjones@gmail.com>
 
 	PR tui/25597:
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 56c1b68b541..d5e61f88dc6 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -39,7 +39,8 @@
 
 static struct partial_symbol *lookup_partial_symbol (struct objfile *,
 						     struct partial_symtab *,
-						     const char *, int,
+						     const lookup_name_info &,
+						     int,
 						     domain_enum);
 
 static const char *psymtab_to_fullname (struct partial_symtab *ps);
@@ -482,9 +483,12 @@ psym_lookup_symbol (struct objfile *objfile,
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
+  lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
+
   for (partial_symtab *ps : require_partial_symbols (objfile, true))
     {
-      if (!ps->readin_p () && lookup_partial_symbol (objfile, ps, name,
+      if (!ps->readin_p () && lookup_partial_symbol (objfile, ps,
+						     psym_lookup_name,
 						     psymtab_index, domain))
 	{
 	  struct symbol *sym, *with_opaque = NULL;
@@ -612,42 +616,14 @@ match_partial_symbol (struct objfile *objfile,
   return NULL;
 }
 
-/* Returns the name used to search psymtabs.  Unlike symtabs, psymtabs do
-   not contain any method/function instance information (since this would
-   force reading type information while reading psymtabs).  Therefore,
-   if NAME contains overload information, it must be stripped before searching
-   psymtabs.  */
-
-static gdb::unique_xmalloc_ptr<char>
-psymtab_search_name (const char *name)
-{
-  switch (current_language->la_language)
-    {
-    case language_cplus:
-      {
-	if (strchr (name, '('))
-	  {
-	    gdb::unique_xmalloc_ptr<char> ret = cp_remove_params (name);
-
-	    if (ret)
-	      return ret;
-	  }
-      }
-      break;
-
-    default:
-      break;
-    }
-
-  return make_unique_xstrdup (name);
-}
-
-/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
-   Check the global symbols if GLOBAL, the static symbols if not.  */
+/* Look, in partial_symtab PST, for symbol whose natural name is
+   LOOKUP_NAME.  Check the global symbols if GLOBAL, the static
+   symbols if not.  */
 
 static struct partial_symbol *
 lookup_partial_symbol (struct objfile *objfile,
-		       struct partial_symtab *pst, const char *name,
+		       struct partial_symtab *pst,
+		       const lookup_name_info &lookup_name,
 		       int global, domain_enum domain)
 {
   struct partial_symbol **start, **psym;
@@ -658,10 +634,6 @@ lookup_partial_symbol (struct objfile *objfile,
   if (length == 0)
     return NULL;
 
-  gdb::unique_xmalloc_ptr<char> search_name = psymtab_search_name (name);
-
-  lookup_name_info lookup_name (search_name.get (), symbol_name_match_type::FULL);
-
   start = (global ?
 	   &objfile->partial_symtabs->global_psymbols[pst->globals_offset] :
 	   &objfile->partial_symtabs->static_psymbols[pst->statics_offset]);
@@ -686,7 +658,7 @@ lookup_partial_symbol (struct objfile *objfile,
 	    internal_error (__FILE__, __LINE__,
 			    _("failed internal consistency check"));
 	  if (strcmp_iw_ordered ((*center)->ginfo.search_name (),
-				 search_name.get ()) >= 0)
+				 lookup_name.name ().c_str ()) >= 0)
 	    {
 	      top = center;
 	    }
@@ -1044,14 +1016,17 @@ static void
 psym_expand_symtabs_for_function (struct objfile *objfile,
 				  const char *func_name)
 {
+  lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
+  lookup_name_info lookup_name = base_lookup.make_ignore_params ();
+
   for (partial_symtab *ps : require_partial_symbols (objfile, true))
     {
       if (ps->readin_p ())
 	continue;
 
-      if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN)
+      if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN)
 	   != NULL)
-	  || (lookup_partial_symbol (objfile, ps, func_name, 0, VAR_DOMAIN)
+	  || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN)
 	      != NULL))
 	psymtab_to_symtab (objfile, ps);
     }


                 reply	other threads:[~2020-04-01 13:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200401135538.254E3385DC31@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).