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]

[commit] Avoid duplicate block searches


This is something I noticed while working on Jan's DW_AT_decl_file
patch.  Two places in ada-lang.c are careful to only search the
blockvector of symtabs with s->primary set, and one loop in
search_symbols checks the previously searched blockvector to avoid
duplicates, but a lot of places don't take care.  Because every
non-primary symtab will share its blockvector with some primary
symtab, we never need to search non-primary ones unless we are
interested in the line table.

So I audited all uses of ALL_OBJFILE_SYMTABS and ALL_SYMTABS,
and used a new ALL_PRIMARY_SYMTABS for each location only
concerned with symbols or blocks.  This should make symbol
lookups rather faster.

Tested on x86_64-pc-linux-gnu and committed.

-- 
Daniel Jacobowitz
CodeSourcery

2007-01-21  Daniel Jacobowitz  <dan@codesourcery.com>

	* objfiles.h (ALL_PRIMARY_SYMTABS): Define.

	* ada-lang.c (symtab_for_sym, ada_lookup_symbol_list)
	(ada_lookup_symbol): Use ALL_PRIMARY_SYMTABS.
	* cp-support.c (make_symbol_overload_list_qualified): Likewise.
	* symtab.c (lookup_symbol_aux_block, lookup_symbol_aux_symtabs)
	(basic_lookup_transparent_type, find_pc_sect_symtab, search_symbols)
	(make_symbol_completion_list): Likewise.

Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.90
diff -u -p -r1.90 ada-lang.c
--- ada-lang.c	8 Jan 2007 04:37:52 -0000	1.90
+++ ada-lang.c	21 Jan 2007 04:23:27 -0000
@@ -4120,7 +4120,7 @@ symtab_for_sym (struct symbol *sym)
   struct dict_iterator iter;
   int j;
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     switch (SYMBOL_CLASS (sym))
       {
@@ -4549,11 +4549,9 @@ ada_lookup_symbol_list (const char *name
   /* Now add symbols from all global blocks: symbol tables, minimal symbol
      tables, and psymtab's.  */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     QUIT;
-    if (!s->primary)
-      continue;
     bv = BLOCKVECTOR (s);
     block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
     ada_add_block_symbols (&symbol_list_obstack, block, name, namespace,
@@ -4619,11 +4617,9 @@ ada_lookup_symbol_list (const char *name
   if (num_defns_collected (&symbol_list_obstack) == 0)
     {
 
-      ALL_SYMTABS (objfile, s)
+      ALL_PRIMARY_SYMTABS (objfile, s)
       {
         QUIT;
-        if (!s->primary)
-          continue;
         bv = BLOCKVECTOR (s);
         block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
         ada_add_block_symbols (&symbol_list_obstack, block, name, namespace,
@@ -4703,7 +4699,7 @@ ada_lookup_symbol (const char *name, con
 
           /* Search the list of symtabs for one which contains the
              address of the start of this block.  */
-          ALL_SYMTABS (objfile, s)
+          ALL_PRIMARY_SYMTABS (objfile, s)
           {
             bv = BLOCKVECTOR (s);
             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
Index: cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.22
diff -u -p -r1.22 cp-support.c
--- cp-support.c	9 Jan 2007 17:58:50 -0000	1.22
+++ cp-support.c	21 Jan 2007 04:23:27 -0000
@@ -750,7 +750,7 @@ make_symbol_overload_list_qualified (con
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     QUIT;
     b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
@@ -764,7 +764,7 @@ make_symbol_overload_list_qualified (con
     }
   }
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     QUIT;
     b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
Index: objfiles.h
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.h,v
retrieving revision 1.43
diff -u -p -r1.43 objfiles.h
--- objfiles.h	9 Jan 2007 17:58:55 -0000	1.43
+++ objfiles.h	21 Jan 2007 04:23:28 -0000
@@ -603,6 +603,14 @@ extern void *objfile_data (struct objfil
   ALL_OBJFILES (objfile)	 \
     ALL_OBJFILE_SYMTABS (objfile, s)
 
+/* Traverse all symtabs in all objfiles, skipping included files
+   (which share a blockvector with their primary symtab).  */
+
+#define ALL_PRIMARY_SYMTABS(objfile, s) \
+  ALL_OBJFILES (objfile)		\
+    ALL_OBJFILE_SYMTABS (objfile, s)	\
+      if ((s)->primary)
+
 /* Traverse all psymtabs in all objfiles.  */
 
 #define	ALL_PSYMTABS(objfile, p) \
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.152
diff -u -p -r1.152 symtab.c
--- symtab.c	9 Jan 2007 22:43:08 -0000	1.152
+++ symtab.c	21 Jan 2007 04:23:29 -0000
@@ -1265,7 +1269,7 @@ lookup_symbol_aux_block (const char *nam
 	{
 	  /* Search the list of symtabs for one which contains the
 	     address of the start of this block.  */
-	  ALL_SYMTABS (objfile, s)
+	  ALL_PRIMARY_SYMTABS (objfile, s)
 	    {
 	      bv = BLOCKVECTOR (s);
 	      b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
@@ -1300,7 +1304,7 @@ lookup_symbol_aux_symtabs (int block_ind
   const struct block *block;
   struct symtab *s;
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     bv = BLOCKVECTOR (s);
     block = BLOCKVECTOR_BLOCK (bv, block_index);
@@ -1715,7 +1719,7 @@ basic_lookup_transparent_type (const cha
      of the desired name as a global, then do psymtab-to-symtab
      conversion on the fly and return the found symbol.  */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     bv = BLOCKVECTOR (s);
     block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
@@ -1763,7 +1767,7 @@ basic_lookup_transparent_type (const cha
      conversion on the fly and return the found symbol.
    */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     bv = BLOCKVECTOR (s);
     block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
@@ -1940,7 +1944,7 @@ find_pc_sect_symtab (CORE_ADDR pc, asect
      It also happens for objfiles that have their functions reordered.
      For these, the symtab we are looking for is not necessarily read in.  */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     bv = BLOCKVECTOR (s);
     b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
@@ -2893,7 +2897,6 @@ search_symbols (char *regexp, domain_enu
   struct symtab *s;
   struct partial_symtab *ps;
   struct blockvector *bv;
-  struct blockvector *prev_bv = 0;
   struct block *b;
   int i = 0;
   struct dict_iterator iter;
@@ -3071,15 +3078,9 @@ search_symbols (char *regexp, domain_enu
       }
     }
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     bv = BLOCKVECTOR (s);
-    /* Often many files share a blockvector.
-       Scan each blockvector only once so that
-       we don't get every symbol many times.
-       It happens that the first symtab in the list
-       for any given blockvector is the main file.  */
-    if (bv != prev_bv)
       for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
 	{
 	  struct symbol_search *prevtail = tail;
@@ -3129,7 +3132,6 @@ search_symbols (char *regexp, domain_enu
 		tail = sort_search_symbols (prevtail, nfound);
 	    }
 	}
-    prev_bv = bv;
   }
 
   /* If there are no eyes, avoid all contact.  I mean, if there are
@@ -3694,7 +3696,7 @@ make_symbol_completion_list (char *text,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     QUIT;
     b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
@@ -3704,7 +3706,7 @@ make_symbol_completion_list (char *text,
       }
   }
 
-  ALL_SYMTABS (objfile, s)
+  ALL_PRIMARY_SYMTABS (objfile, s)
   {
     QUIT;
     b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);


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