This is the mail archive of the gdb-patches@sourceware.cygnus.com 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]

RFA: minsyms.c: Fixes for serious demangled hash minsym lookup flaws.


There are two serious problems with the new demangled hash minsym
lookup code, causing lookup of demangled names to fail.

Here is an example, using the overload executable from the testsuite:

pes@eno_709$ gdb testsuite/gdb.c++/overload
GNU gdb 20000204
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.6"...
(gdb) b marker1
Function "marker1" not defined.

There are two reasons:

1) When handling the demangled name in install_minimal_symbols, the 
   current code adds the non-demangled name to the msymbol_demangled_hash
   table, using a non-demangled hash algorithm and the non-demangled hash_next
   link of the msymbol.
   As add_minsym_to_hash_table has little code in common with the demangled
   version, I created a new add_minsym_to_demangled_hash_table function.

2) The intended two pass lookup loop did not work, if 
   objfile->msymbol_hash[hash] was NULL, it never switched to the demangled
   lookup pass.

Here is patch for both problems:

2000-03-21  Peter Schauer   <pes@regent.e-technik.tu-muenchen.de>

	* minsyms.c (add_minsym_to_demangled_hash_table):  New function
	to enter demangled msymbols into the hash table.
	(install_minimal_symbols):  Use it, instead of
	add_minsym_to_hash_table.
	(lookup_minimal_symbol):  Reorganize pass loop so that demangled
	symbols are found even if objfile->msymbol_hash[hash] is NULL.

*** gdb/minsyms.c.orig	Mon Mar 13 19:29:23 2000
--- gdb/minsyms.c	Tue Mar 20 20:35:25 2000
***************
*** 123,129 ****
--- 123,143 ----
      }
  }
  
+ /* Add the minimal symbol SYM to an objfile's minsym demangled hash table,
+    TABLE.  */
+ static void
+ add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
+ 				    struct minimal_symbol **table)
+ {
+   if (sym->demangled_hash_next == NULL)
+     {
+       unsigned int hash = msymbol_hash_iw (SYMBOL_DEMANGLED_NAME (sym));
+       sym->demangled_hash_next = table[hash];
+       table[hash] = sym;
+     }
+ }
  
+ 
  /* Look through all the current minimal symbol tables and find the
     first minimal symbol that matches NAME.  If OBJF is non-NULL, limit
     the search to that objfile.  If SFILE is non-NULL, limit the search
***************
*** 167,226 ****
  	{
  	  /* Do two passes: the first over the ordinary hash table,
  	     and the second over the demangled hash table.  */
! 	  int pass = 1;
  
! 	  msymbol = objfile->msymbol_hash[hash];
! 	  
! 	  while (msymbol != NULL && found_symbol == NULL)
  	    {
! 	      if (SYMBOL_MATCHES_NAME (msymbol, name))
  		{
! 		  switch (MSYMBOL_TYPE (msymbol))
  		    {
! 		    case mst_file_text:
! 		    case mst_file_data:
! 		    case mst_file_bss:
  #ifdef SOFUN_ADDRESS_MAYBE_MISSING
! 		      if (sfile == NULL || STREQ (msymbol->filename, sfile))
! 			found_file_symbol = msymbol;
  #else
! 		      /* We have neither the ability nor the need to
! 		         deal with the SFILE parameter.  If we find
! 		         more than one symbol, just return the latest
! 		         one (the user can't expect useful behavior in
! 		         that case).  */
! 		      found_file_symbol = msymbol;
  #endif
! 		      break;
  
! 		    case mst_solib_trampoline:
  
! 		      /* If a trampoline symbol is found, we prefer to
! 		         keep looking for the *real* symbol. If the
! 		         actual symbol is not found, then we'll use the
! 		         trampoline entry. */
! 		      if (trampoline_symbol == NULL)
! 			trampoline_symbol = msymbol;
! 		      break;
  
! 		    case mst_unknown:
! 		    default:
! 		      found_symbol = msymbol;
! 		      break;
  		    }
- 		}
  
! 	      /* Find the next symbol on the hash chain.  At the end
! 		 of the first pass, try the demangled hash list.  */
! 	      if (pass == 1)
! 		msymbol = msymbol->hash_next;
! 	      else
! 		msymbol = msymbol->demangled_hash_next;
! 	      if (msymbol == NULL)
! 		{
! 		  ++pass;
! 		  if (pass == 2)
! 		    msymbol = objfile->msymbol_demangled_hash[dem_hash];
  		}
  	    }
  	}
--- 181,240 ----
  	{
  	  /* Do two passes: the first over the ordinary hash table,
  	     and the second over the demangled hash table.  */
! 	  int pass;
  
! 	  for (pass = 1; pass <= 2 && found_symbol == NULL; pass++)
  	    {
! 	      /* Select hash list according to pass.  */
! 	      if (pass == 1)
! 		msymbol = objfile->msymbol_hash[hash];
! 	      else
! 		msymbol = objfile->msymbol_demangled_hash[dem_hash];
! 	      
! 	      while (msymbol != NULL && found_symbol == NULL)
  		{
! 		  if (SYMBOL_MATCHES_NAME (msymbol, name))
  		    {
! 		      switch (MSYMBOL_TYPE (msymbol))
! 			{
! 			case mst_file_text:
! 			case mst_file_data:
! 			case mst_file_bss:
  #ifdef SOFUN_ADDRESS_MAYBE_MISSING
! 			  if (sfile == NULL || STREQ (msymbol->filename, sfile))
! 			    found_file_symbol = msymbol;
  #else
! 			  /* We have neither the ability nor the need to
! 			     deal with the SFILE parameter.  If we find
! 			     more than one symbol, just return the latest
! 			     one (the user can't expect useful behavior in
! 			     that case).  */
! 			  found_file_symbol = msymbol;
  #endif
! 			  break;
  
! 			case mst_solib_trampoline:
  
! 			  /* If a trampoline symbol is found, we prefer to
! 			     keep looking for the *real* symbol. If the
! 			     actual symbol is not found, then we'll use the
! 			     trampoline entry. */
! 			  if (trampoline_symbol == NULL)
! 			    trampoline_symbol = msymbol;
! 			  break;
  
! 			case mst_unknown:
! 			default:
! 			  found_symbol = msymbol;
! 			  break;
! 			}
  		    }
  
! 		  /* Find the next symbol on the hash chain.  */
! 		  if (pass == 1)
! 		    msymbol = msymbol->hash_next;
! 		  else
! 		    msymbol = msymbol->demangled_hash_next;
  		}
  	    }
  	}
***************
*** 934,941 ****
  	{
  	  SYMBOL_INIT_DEMANGLED_NAME (msymbols, &objfile->symbol_obstack);
  	  if (SYMBOL_DEMANGLED_NAME (msymbols) != NULL)
! 	    add_minsym_to_hash_table (msymbols,
! 				      objfile->msymbol_demangled_hash);
  	}
      }
  }
--- 948,955 ----
  	{
  	  SYMBOL_INIT_DEMANGLED_NAME (msymbols, &objfile->symbol_obstack);
  	  if (SYMBOL_DEMANGLED_NAME (msymbols) != NULL)
! 	    add_minsym_to_demangled_hash_table (msymbols,
! 					        objfile->msymbol_demangled_hash);
  	}
      }
  }

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de

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