This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[COMMITTED PATCH] symtab.c (eq_symbol_entry): Use SYMBOL_SEARCH_NAME and symbol_matches_domain.


Hi.

The cache was a bit conservative in checking for hits.
This patch makes the cache use the same tests normal lookup does
for better hit rates.

Regression tested on amd64-linux.

btw, I have a gmonster2 perf testcase that provides an example
of the speedup.

For this program, and 100 shared libraries,

#include <string>

std::string hello ("Hello.");

int
main ()
{
  return 0;
}

Measuring the time to do two "ptype hello" commands in a row
after running to main,

Before (without symbol lookup cache):

gmonster2-ptype cpu_time 1-sos 0.115144
gmonster2-ptype cpu_time 10-sos 0.972049
gmonster2-ptype cpu_time 100-sos 17.313381
gmonster2-ptype wall_time 1-sos 0.115725040436
gmonster2-ptype wall_time 10-sos 0.977412939072
gmonster2-ptype wall_time 100-sos 17.4151601791
gmonster2-ptype vmsize 1-sos 201276
gmonster2-ptype vmsize 10-sos 645708
gmonster2-ptype vmsize 100-sos 5084528

After (with symbol lookup cache, plus this patch):

gmonster2-ptype cpu_time 1-sos 0.018781
gmonster2-ptype cpu_time 10-sos 0.064274
gmonster2-ptype cpu_time 100-sos 0.860109
gmonster2-ptype wall_time 1-sos 0.0188720226288
gmonster2-ptype wall_time 10-sos 0.0647039413452
gmonster2-ptype wall_time 100-sos 0.865196943283
gmonster2-ptype vmsize 1-sos 201352
gmonster2-ptype vmsize 10-sos 645784
gmonster2-ptype vmsize 100-sos 5084584

I ran the experiment a few times by hand to verify the reported numbers are
accurate.  This included diff'ing the before/after output to verify
they're identical.

[btw, seems like the perf test harness needs to truncate wall_time
like cpu_time]

2015-01-11  Doug Evans  <xdje42@gmail.com>

	* symtab.c (eq_symbol_entry): Use SYMBOL_SEARCH_NAME and
	symbol_matches_domain for symbol comparisons.

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7193131..3679b43 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1200,27 +1200,53 @@ eq_symbol_entry (const struct symbol_cache_slot *slot,
     }
   else
     {
-      slot_name = SYMBOL_LINKAGE_NAME (slot->value.found);
+      slot_name = SYMBOL_SEARCH_NAME (slot->value.found);
       slot_domain = SYMBOL_DOMAIN (slot->value.found);
     }
 
   /* NULL names match.  */
   if (slot_name == NULL && name == NULL)
-    ;
-  else if (slot_name != NULL && name != NULL)
     {
-      if (strcmp (slot_name, name) != 0)
+      /* But there's no point in calling symbol_matches_domain in the
+	 SYMBOL_SLOT_FOUND case.  */
+      if (slot_domain != domain)
 	return 0;
     }
+  else if (slot_name != NULL && name != NULL)
+    {
+      /* It's important that we use the same comparison that was done the
+	 first time through.  If the slot records a found symbol, then this
+	 means using strcmp_iw on SYMBOL_SEARCH_NAME.  See dictionary.c.
+	 It also means using symbol_matches_domain for found symbols.
+	 See block.c.
+
+	 If the slot records a not-found symbol, then require a precise match.
+	 We could still be lax with whitespace like strcmp_iw though.  */
+
+      if (slot->state == SYMBOL_SLOT_NOT_FOUND)
+	{
+	  if (strcmp (slot_name, name) != 0)
+	    return 0;
+	  if (slot_domain != domain)
+	    return 0;
+	}
+      else
+	{
+	  struct symbol *sym = slot->value.found;
+
+	  if (strcmp_iw (slot_name, name) != 0)
+	    return 0;
+	  if (!symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+				      slot_domain, domain))
+	    return 0;
+	}
+    }
   else
     {
       /* Only one name is NULL.  */
       return 0;
     }
 
-  if (slot_domain != domain)
-    return 0;
-
   return 1;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]