RFC: remove the symtab "last resort" hack

Tom Tromey tromey@redhat.com
Tue Jan 15 16:51:00 GMT 2013


Two functions in symtab.c have long had a "last resort" branch where
they extend a search "just in case".  That is, if the search was
requested for STATIC_BLOCK, and fails, then the functions will search
GLOBAL_BLOCK; and vice versa.

>From what I can tell, this code doesn't serve any purpose.  It is there
to defend against imagined gdb bugs elsewhere.

Removing this code causes no test suite regressions on x86-64 Fedora 16.
I ran the test suite both with DWARF and -gstabs+, to test the main
symbol readers.

This patch removes the last resort hacks and fixes a FIXME comment in
the process.

My view is that if such a bug actually arises in the future, we should
fix it at the source rather than having a hack in the symbol table
lookup functions.

Comments?

Tom

    	* symtab.c (error_in_psymtab_expansion): New function.
    	(lookup_symbol_aux_quick)
    	(basic_lookup_transparent_type_quick): Remove "last resort"
    	code.  Use error_in_psymtab_expansion.
    
diff --git a/gdb/symtab.c b/gdb/symtab.c
index f4ed8b9..364f9b6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1628,6 +1628,20 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
   return NULL;
 }
 
+/* A helper function that throws an exception when a symbol was found
+   in a psymtab but not in a symtab.  */
+
+static void ATTRIBUTE_NORETURN
+error_in_psymtab_expansion (int kind, const char *name, struct symtab *symtab)
+{
+  error (_("\
+Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n\
+%s may be an inlined function, or may be a template function\n	 \
+(if a template, try specifying an instantiation: %s<type>)."),
+	 kind == GLOBAL_BLOCK ? "global" : "static",
+	 name, symtab->filename, name, name);
+}
+
 /* A helper function for lookup_symbol_aux that interfaces with the
    "quick" symbol table functions.  */
 
@@ -1650,30 +1664,7 @@ lookup_symbol_aux_quick (struct objfile *objfile, int kind,
   block = BLOCKVECTOR_BLOCK (bv, kind);
   sym = lookup_block_symbol (block, name, domain);
   if (!sym)
-    {
-      /* This shouldn't be necessary, but as a last resort try
-	 looking in the statics even though the psymtab claimed
-	 the symbol was global, or vice-versa.  It's possible
-	 that the psymtab gets it wrong in some cases.  */
-
-      /* FIXME: carlton/2002-09-30: Should we really do that?
-	 If that happens, isn't it likely to be a GDB error, in
-	 which case we should fix the GDB error rather than
-	 silently dealing with it here?  So I'd vote for
-	 removing the check for the symbol in the other
-	 block.  */
-      block = BLOCKVECTOR_BLOCK (bv,
-				 kind == GLOBAL_BLOCK ?
-				 STATIC_BLOCK : GLOBAL_BLOCK);
-      sym = lookup_block_symbol (block, name, domain);
-      if (!sym)
-	error (_("\
-Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n\
-%s may be an inlined function, or may be a template function\n\
-(if a template, try specifying an instantiation: %s<type>)."),
-	       kind == GLOBAL_BLOCK ? "global" : "static",
-	       name, symtab->filename, name, name);
-    }
+    error_in_psymtab_expansion (kind, name, symtab);
   return fixup_symbol_section (sym, objfile);
 }
 
@@ -1861,24 +1852,8 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, int kind,
   block = BLOCKVECTOR_BLOCK (bv, kind);
   sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
   if (!sym)
-    {
-      int other_kind = kind == GLOBAL_BLOCK ? STATIC_BLOCK : GLOBAL_BLOCK;
-
-      /* This shouldn't be necessary, but as a last resort
-       * try looking in the 'other kind' even though the psymtab
-       * claimed the symbol was one thing.  It's possible that
-       * the psymtab gets it wrong in some cases.
-       */
-      block = BLOCKVECTOR_BLOCK (bv, other_kind);
-      sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
-      if (!sym)
-	/* FIXME; error is wrong in one case.  */
-	error (_("\
-Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
-%s may be an inlined function, or may be a template function\n\
-(if a template, try specifying an instantiation: %s<type>)."),
-	       name, symtab->filename, name, name);
-    }
+    error_in_psymtab_expansion (kind, name, symtab);
+
   if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
     return SYMBOL_TYPE (sym);
 



More information about the Gdb-patches mailing list