This is the mail archive of the gdb-patches@sources.redhat.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]
Other format: [Raw text]

[dictionary] commit for 2003-03-06


Following Andrew's lead, I'm going to try to remember to post my
commits to carlton_dictionary-branch.  They won't always be the
prettiest commits: I usually commit once at the end of each day that
I've done any work on the branch, assuming that I leave it in a
working state (which I almost always do!); this means that a commit
may contain something that I plan to continue the next day, and it
also may contain bits of unrelated tasks that I'm working on.  Also,
the ChangeLogs aren't great: they're written in a way that is easy to
generate, as opposed to a way that is easiest to review years in the
future.  (I'm much more careful with the ChangeLogs on the mainline,
don't worry!)

This branch has as its primarily task to improve C++ namespace
support; it also contains cleanups related to symbol names, linespec,
and const correctness.  (All of which I intend to move to the
mainline; I'm doing so gradually.)  It's probably not as focussed a
branch as Andrew would like; it works for me, though.

Today's commits are the start of cleaning up minimal symbol names and
accessors (which will be an ongoing task), and fixes a few (but not
all) FAILing regexps in gdb.c++/templates.exp (also ongoing, though
actually I think I'm more likely to try to get rid of the differences
in behavior rather than make the regexps more generous).

Question for those of you who have read this far: now that
lookup_symbol_aux_minsyms is on its last legs (it's gone on the
branch), do you think we could get rid of the demangled hash table for
minsyms?  I'll try to audit uses of lookup_minimal_symbol tomorrow or
next week.

David Carlton
carlton at math dot stanford dot edu

2003-03-06  David Carlton  <carlton at math dot stanford dot edu>

	* minsyms.c (add_minsym_to_hash_table): Use SYMBOL_LINKAGE_NAME.
	(add_minsym_to_demangled_hash_table): Use SYMBOL_NATURAL_NAME.
	(build_minimal_symbol_hash_tables): Add all minsyms to demangled
	hash table.
	(install_minimal_symbols): Use SYMBOL_LINKAGE_NAME.
	(find_solib_trampoline_target): Ditto.
	(compare_minimal_symbols): Ditto.
	(compact_minimal_symbols): Ditto.
	* symtab.h (DEPRECATED_SYMBOL_MATCHES_NAME): Delete.
	* minsyms.c (lookup_minimal_symbol_text): Replace use of
	DEPRECATED_SYMBOL_MATCHES_NAME by strcmp on linkage name.
	(lookup_minimal_symbol_solib_trampoline): Ditto.
	* symtab.h: Declare lookup_minimal_symbol_linkage,
	lookup_minimal_symbol_natural.
	* minsyms.c (lookup_minimal_symbol_aux): New function.
	(lookup_minimal_symbol_linkage): Ditto.
	(lookup_minimal_symbol_natural): Ditto.
	(lookup_minimal_symbol): Move body into
	lookup_minimal_symbol_aux.

2003-03-06  David Carlton  <carlton at math dot stanford dot edu>

	* gdb.c++/templates.exp (do_tests): Make expressions for 'ptype
	Bar' and 'ptype Qux' more generous.

Index: minsyms.c
===================================================================
RCS file: /cvs/src/src/gdb/minsyms.c,v
retrieving revision 1.22.8.4
diff -u -p -r1.22.8.4 minsyms.c
--- minsyms.c	6 Mar 2003 00:56:30 -0000	1.22.8.4
+++ minsyms.c	7 Mar 2003 00:30:04 -0000
@@ -76,6 +76,11 @@ static int msym_bunch_index;
 
 static int msym_count;
 
+static struct minimal_symbol *lookup_minimal_symbol_aux (const char *name,
+							 int linkage,
+							 const char *sfile,
+							 struct objfile *objf);
+
 /* Compute a hash code based using the same criteria as `strcmp_iw'.  */
 
 unsigned int
@@ -113,7 +118,8 @@ add_minsym_to_hash_table (struct minimal
 {
   if (sym->hash_next == NULL)
     {
-      unsigned int hash = msymbol_hash (DEPRECATED_SYMBOL_NAME (sym)) % MINIMAL_SYMBOL_HASH_SIZE;
+      unsigned int hash
+	= msymbol_hash (SYMBOL_LINKAGE_NAME (sym)) % MINIMAL_SYMBOL_HASH_SIZE;
       sym->hash_next = table[hash];
       table[hash] = sym;
     }
@@ -123,11 +129,13 @@ add_minsym_to_hash_table (struct minimal
    TABLE.  */
 static void
 add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
-                                  struct minimal_symbol **table)
+				    struct minimal_symbol **table)
 {
   if (sym->demangled_hash_next == NULL)
     {
-      unsigned int hash = msymbol_hash_iw (SYMBOL_DEMANGLED_NAME (sym)) % MINIMAL_SYMBOL_HASH_SIZE;
+      unsigned int hash
+	= (msymbol_hash_iw (SYMBOL_NATURAL_NAME (sym))
+	   % MINIMAL_SYMBOL_HASH_SIZE);
       sym->demangled_hash_next = table[hash];
       table[hash] = sym;
     }
@@ -144,20 +152,66 @@ add_minsym_to_demangled_hash_table (stru
    Note:  One instance where there may be duplicate minimal symbols with
    the same name is when the symbol tables for a shared library and the
    symbol tables for an executable contain global symbols with the same
-   names (the dynamic linker deals with the duplication).  */
+   names (the dynamic linker deals with the duplication).
+
+   This function first searches for matches via linkage names; if it
+   doesn't find a match there, it then searches via natural names.  */
 
 struct minimal_symbol *
 lookup_minimal_symbol (register const char *name, const char *sfile,
 		       struct objfile *objf)
 {
+  struct minimal_symbol *msymbol;
+
+  msymbol = lookup_minimal_symbol_linkage (name, sfile, objf);
+
+  if (msymbol != NULL)
+    return msymbol;
+  else
+    return lookup_minimal_symbol_natural (name, sfile, objf);
+}
+
+/* Search for a minimal symbol via linkage names; args are as in
+   lookup_minimal_symbol.  */
+
+struct minimal_symbol *
+lookup_minimal_symbol_linkage (const char *name, const char *sfile,
+			       struct objfile *objf)
+{
+  return lookup_minimal_symbol_aux (name, 1, sfile, objf);
+}
+
+/* Search for a minimal symbol via natural names; args are as in
+   lookup_minimal_symbol.  */
+
+struct minimal_symbol *
+lookup_minimal_symbol_natural (const char *name, const char *sfile,
+			       struct objfile *objf)
+{
+  return lookup_minimal_symbol_aux (name, 0, sfile, objf);
+}
+
+/* Helper function for lookup_minimal_symbol and friends, which only
+   searches for matches via linkage names or natural names but not
+   both.  Args are in lookup_minimal_symbol; if LINKAGE is non-zero,
+   search in linkage names, if zero, search in natural names.  */
+
+static struct minimal_symbol *
+lookup_minimal_symbol_aux (const char *name, int linkage,
+			   const char *sfile, struct objfile *objf)
+{
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
   struct minimal_symbol *found_symbol = NULL;
   struct minimal_symbol *found_file_symbol = NULL;
   struct minimal_symbol *trampoline_symbol = NULL;
 
-  unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
-  unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
+  unsigned int hash;
+
+  if (linkage)
+    hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
+  else
+    hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
 
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
   if (sfile != NULL)
@@ -174,66 +228,61 @@ lookup_minimal_symbol (register const ch
     {
       if (objf == NULL || objf == objfile)
 	{
-	  /* Do two passes: the first over the ordinary hash table,
-	     and the second over the demangled hash table.  */
-        int pass;
+	  if (linkage)
+	    msymbol = objfile->msymbol_hash[hash];
+	  else
+	    msymbol = objfile->msymbol_demangled_hash[hash];
 
-        for (pass = 1; pass <= 2 && found_symbol == NULL; pass++)
+	  while (msymbol != NULL && found_symbol == NULL)
 	    {
-            /* 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 (linkage
+		  ? strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0
+		  : SYMBOL_MATCHES_NATURAL_NAME (msymbol, name))
 		{
-                if (DEPRECATED_SYMBOL_MATCHES_NAME (msymbol, name))
+		  switch (MSYMBOL_TYPE (msymbol))
 		    {
-                    switch (MSYMBOL_TYPE (msymbol))
-                      {
-                      case mst_file_text:
-                      case mst_file_data:
-                      case mst_file_bss:
+		    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;
+		      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;
+		      /* 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;
+		      break;
 
-                      case mst_solib_trampoline:
+		    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;
-                      }
-		    }
+		      /* 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;
 
-                /* Find the next symbol on the hash chain.  */
-                if (pass == 1)
-                  msymbol = msymbol->hash_next;
-                else
-                  msymbol = msymbol->demangled_hash_next;
+		    case mst_unknown:
+		    default:
+		      found_symbol = msymbol;
+		      break;
+		    }
 		}
+
+	      /* Find the next symbol on the hash chain.  */
+	      if (linkage)
+		msymbol = msymbol->hash_next;
+	      else
+		msymbol = msymbol->demangled_hash_next;
 	    }
 	}
     }
+
   /* External symbols are best.  */
   if (found_symbol)
     return found_symbol;
@@ -288,7 +337,7 @@ lookup_minimal_symbol_text (register con
 	       msymbol != NULL && found_symbol == NULL;
 	       msymbol = msymbol->hash_next)
 	    {
-	      if (DEPRECATED_SYMBOL_MATCHES_NAME (msymbol, name) &&
+	      if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
 		  (MSYMBOL_TYPE (msymbol) == mst_text ||
 		   MSYMBOL_TYPE (msymbol) == mst_file_text))
 		{
@@ -364,7 +413,7 @@ lookup_minimal_symbol_solib_trampoline (
 	       msymbol != NULL && found_symbol == NULL;
 	       msymbol = msymbol->hash_next)
 	    {
-	      if (DEPRECATED_SYMBOL_MATCHES_NAME (msymbol, name) &&
+	      if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
 		  MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
 		return msymbol;
 	    }
@@ -659,8 +708,8 @@ compare_minimal_symbols (const void *fn1
   else
     /* addrs are equal: sort by name */
     {
-      char *name1 = DEPRECATED_SYMBOL_NAME (fn1);
-      char *name2 = DEPRECATED_SYMBOL_NAME (fn2);
+      char *name1 = SYMBOL_LINKAGE_NAME (fn1);
+      char *name2 = SYMBOL_LINKAGE_NAME (fn2);
 
       if (name1 && name2)	/* both have names */
 	return strcmp (name1, name2);
@@ -752,7 +801,8 @@ compact_minimal_symbols (struct minimal_
 	{
 	  if (SYMBOL_VALUE_ADDRESS (copyfrom) ==
 	      SYMBOL_VALUE_ADDRESS ((copyfrom + 1)) &&
-	      (STREQ (DEPRECATED_SYMBOL_NAME (copyfrom), DEPRECATED_SYMBOL_NAME ((copyfrom + 1)))))
+	      (STREQ (SYMBOL_LINKAGE_NAME (copyfrom),
+		      SYMBOL_LINKAGE_NAME ((copyfrom + 1)))))
 	    {
 	      if (MSYMBOL_TYPE ((copyfrom + 1)) == mst_unknown)
 		{
@@ -795,9 +845,8 @@ build_minimal_symbol_hash_tables (struct
       add_minsym_to_hash_table (msym, objfile->msymbol_hash);
 
       msym->demangled_hash_next = 0;
-      if (SYMBOL_DEMANGLED_NAME (msym) != NULL)
-	add_minsym_to_demangled_hash_table (msym,
-                                            objfile->msymbol_demangled_hash);
+      add_minsym_to_demangled_hash_table (msym,
+					  objfile->msymbol_demangled_hash);
     }
 }
 
@@ -867,9 +916,9 @@ install_minimal_symbols (struct objfile 
 	  for (bindex = 0; bindex < msym_bunch_index; bindex++, mcount++)
 	    {
 	      msymbols[mcount] = bunch->contents[bindex];
-	      if (DEPRECATED_SYMBOL_NAME (&msymbols[mcount])[0] == leading_char)
+	      if (SYMBOL_LINKAGE_NAME (&msymbols[mcount])[0] == leading_char)
 		{
-		  DEPRECATED_SYMBOL_NAME (&msymbols[mcount])++;
+		  SYMBOL_LINKAGE_NAME (&msymbols[mcount])++;
 		}
 	    }
 	  msym_bunch_index = BUNCH_SIZE;
@@ -898,7 +947,7 @@ install_minimal_symbols (struct objfile 
          symbol count does *not* include this null symbol, which is why it
          is indexed by mcount and not mcount-1. */
 
-      DEPRECATED_SYMBOL_NAME (&msymbols[mcount]) = NULL;
+      SYMBOL_LINKAGE_NAME (&msymbols[mcount]) = NULL;
       SYMBOL_VALUE_ADDRESS (&msymbols[mcount]) = 0;
       MSYMBOL_INFO (&msymbols[mcount]) = NULL;
       MSYMBOL_TYPE (&msymbols[mcount]) = mst_unknown;
@@ -918,7 +967,7 @@ install_minimal_symbols (struct objfile 
 
 	for (i = 0; i < mcount; i++)
 	  {
-	    const char *name = DEPRECATED_SYMBOL_NAME (&objfile->msymbols[i]);
+	    const char *name = SYMBOL_LINKAGE_NAME (&objfile->msymbols[i]);
 	    if (name[0] == '_' && name[1] == 'Z')
 	      {
 		set_cp_abi_as_auto_default ("gnu-v3");
@@ -981,7 +1030,8 @@ find_solib_trampoline_target (CORE_ADDR 
       ALL_MSYMBOLS (objfile, msymbol)
       {
 	if (MSYMBOL_TYPE (msymbol) == mst_text
-	    && STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (tsymbol)))
+	    && STREQ (SYMBOL_LINKAGE_NAME (msymbol),
+		      SYMBOL_LINKAGE_NAME (tsymbol)))
 	  return SYMBOL_VALUE_ADDRESS (msymbol);
       }
     }
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.42.2.22
diff -u -p -r1.42.2.22 symtab.h
--- symtab.h	6 Mar 2003 00:56:32 -0000	1.42.2.22
+++ symtab.h	7 Mar 2003 00:30:05 -0000
@@ -211,23 +211,6 @@ extern const char *symbol_demangled_name
 #define SYMBOL_PRINT_NAME(symbol)					\
   (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
 
-/* Macro that tests a symbol for a match against a specified name string.
-   First test the unencoded name, then looks for and test a C++ encoded
-   name if it exists.  Note that whitespace is ignored while attempting to
-   match a C++ encoded name, so that "foo::bar(int,long)" is the same as
-   "foo :: bar (int, long)".
-   Evaluates to zero if the match fails, or nonzero if it succeeds. */
-
-/* FIXME: carlton/2003-02-27: This is an unholy mixture of linkage
-   names and natural names.  If you want to test the linkage names
-   with strcmp, do that.  If you want to test the natural names with
-   strcmp_iw, use SYMBOL_MATCHES_NATURAL_NAME.  */
-
-#define DEPRECATED_SYMBOL_MATCHES_NAME(symbol, name)			\
-  (STREQ (DEPRECATED_SYMBOL_NAME (symbol), (name))			\
-   || (SYMBOL_DEMANGLED_NAME (symbol) != NULL				\
-       && strcmp_iw (SYMBOL_DEMANGLED_NAME (symbol), (name)) == 0))
-
 /* Macro that tests a symbol for a match against a specified name
    string.  It tests against SYMBOL_NATURAL_NAME, and it ignores
    whitespace and trailing parentheses.  (See strcmp_iw for details
@@ -1140,6 +1123,14 @@ add_minsym_to_hash_table (struct minimal
 extern struct minimal_symbol *lookup_minimal_symbol (const char *,
 						     const char *,
 						     struct objfile *);
+
+extern struct minimal_symbol *lookup_minimal_symbol_linkage (const char *,
+							     const char *,
+							     struct objfile *);
+
+extern struct minimal_symbol *lookup_minimal_symbol_natural (const char *,
+							     const char *,
+							     struct objfile *);
 
 extern struct minimal_symbol *lookup_minimal_symbol_text (const char *,
 							  const char *,
Index: testsuite/gdb.c++/templates.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/templates.exp,v
retrieving revision 1.12.16.2
diff -u -p -r1.12.16.2 templates.exp
--- testsuite/gdb.c++/templates.exp	6 Mar 2003 00:56:36 -0000	1.12.16.2
+++ testsuite/gdb.c++/templates.exp	7 Mar 2003 00:30:10 -0000
@@ -353,7 +353,7 @@ send_gdb "ptype Bar\n"   
 gdb_expect {   
     -re "type = template <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)1>\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)33>\r\n$gdb_prompt $" { pass "ptype Bar" }
     -re "type = <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" { xfail "ptype Bar" }
-    -re "ptype Bar\r\ntype = class Bar<int,33> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);\r\n}\r\n$gdb_prompt $"
+    -re "ptype Bar\r\ntype = class Bar<int, ?33> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);\r\n}\r\n$gdb_prompt $"
     { # GCC 3.1, DWARF-2 output.
 	kfail "gdb/57" "ptype Bar" }
     -re "No symbol \"Bar\" in current context.\r\n$gdb_prompt $"
@@ -461,7 +461,7 @@ send_gdb "ptype Spec\n"   
 gdb_expect {   
     -re "type = template <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Spec<int,int \\*>\r\n\[ \t\]*(class |)Spec<int,char>\r\n$gdb_prompt $" { pass "ptype Spec" }
     -re "type = <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { xfail "ptype Spec" }
-    -re "type = class Spec<int,char> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $"
+    -re "type = class Spec<int, ?char> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $"
     { # GCC 3.1, DWARF-2 output.
 	kfail "gdb/57" "ptype Spec" }
     -re "No symbol \"Spec\" in current context.\r\n$gdb_prompt $"


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