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] lookup_transparent_type


This patch tweaks lookup_transparent_type.  This function can get
called when a type is declared but not defined in some particular file
(or at least when GCC doesn't emit the definition in the debug info).
Unfortunately, in that situation, GDB can't figure out whether or not
the type in question lives in a namespace (if GCC isn't generating
namespace debug info), so lookup_transparent_type won't find the
actual definition.

There's really nothing that GDB can do about this that will work in
general: we need more debug info, and we don't have it.  But this
patch improves the situation: it tells lookup_transparent_type, as a
fallback strategy, to look in whatever namespaces are currently in
scope, and sometimes that works.  Still, it's an unfortunate
situation.

David Carlton
carlton@bactrian.org

2003-05-23  David Carlton  <carlton@bactrian.org>

	* Makefile.in (cp-namespace.o): Depend on frame_h.
	* cp-support.h: Declare lookup_transparent_type_namespace,
	lookup_transparent_type_namespace_loop.
	* cp-namespace.c: Include frame.h.
	(lookup_transparent_type_namespace): New.
	(lookup_transparent_type_namespace_loop): New.
	* symtab.h: Declare lookup_transparent_type_aux.
	* symtab.c (lookup_transparent_type): Add FIXME, fork off code
	into lookup_transparent_type_aux, do backup strategy of trying to
	look in namespaces.
	(lookup_transparent_type_aux): New.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.262.2.31
diff -u -p -r1.262.2.31 Makefile.in
--- Makefile.in	23 May 2003 18:40:33 -0000	1.262.2.31
+++ Makefile.in	23 May 2003 22:22:25 -0000
@@ -1625,7 +1625,7 @@ cp-abi.o: cp-abi.c $(defs_h) $(value_h) 
 	$(gdbcmd_h) $(ui_out_h) $(gdb_string_h)
 cp-namespace.o: cp-namespace.c $(defs_h) $(cp_support_h) $(gdb_obstack_h) \
 	$(symtab_h) $(symfile_h) $(gdb_assert_h) $(block_h) $(objfiles_h) \
-	$(gdbtypes_h) $(dictionary_h) $(gdbcmd_h)
+	$(gdbtypes_h) $(dictionary_h) $(gdbcmd_h) $(frame_h)
 cp-support.o: cp-support.c $(defs_h) $(cp_support_h) $(gdb_string_h) \
 	$(demangle_h) $(gdb_assert_h) $(symtab_h) $(gdbcmd_h)
 cp-valprint.o: cp-valprint.c $(defs_h) $(gdb_obstack_h) $(symtab_h) \
Index: cp-namespace.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-namespace.c,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 cp-namespace.c
--- cp-namespace.c	23 May 2003 18:40:35 -0000	1.1.2.4
+++ cp-namespace.c	23 May 2003 22:22:50 -0000
@@ -31,6 +31,7 @@
 #include "gdbtypes.h"
 #include "dictionary.h"
 #include "gdbcmd.h"
+#include "frame.h"
 
 /* When set, the file that we're processing seems to have debugging
    info for C++ namespaces, so cp-namespace.c shouldn't try to guess
@@ -71,6 +72,10 @@ static struct symbol *lookup_symbol_file
 					  struct symtab **symtab,
 					  int anonymous_namespace);
 
+static struct type *lookup_transparent_type_namespace_loop (const char *name,
+							    const char *scope,
+							    int scope_len);
+
 /* This block exists only to store symbols associated to namespaces.
    Normally, try to avoid accessing it directly: instead, use
    get_namespace_block if you can.  Similarly with
@@ -519,6 +524,58 @@ lookup_symbol_file (const char *name,
     }
 
   return NULL;
+}
+
+/* Try to look up the type definition associated to NAME if honest
+   methods don't work: look for NAME in the classes/namespaces that
+   are currently active, on the off chance that it might be there.  */
+
+struct type *
+lookup_transparent_type_namespace (const char *name)
+{
+  const char *scope = block_scope (get_selected_block (0));
+
+  if (strstr (scope, "::") == NULL)
+    return NULL;
+
+  return lookup_transparent_type_namespace_loop (name, scope, 0);
+}
+
+/* Lookup the the type definition associated to NAME in
+   namespaces/classes containing SCOPE other than the global
+   namespace.  */
+
+static struct type *
+lookup_transparent_type_namespace_loop (const char *name, const char *scope,
+					int scope_len)
+{
+  int new_scope_len = scope_len;
+  char *full_name;
+
+  /* If the current scope is followed by "::", skip past that.  */
+  if (new_scope_len != 0)
+    new_scope_len += 2;
+  new_scope_len += cp_find_first_component (scope + new_scope_len);
+
+  if (scope[new_scope_len] == ':')
+    {
+      struct type *retval
+	= lookup_transparent_type_namespace_loop (name, scope, new_scope_len);
+      if (retval != NULL)
+	return retval;
+    }
+
+  /* If there's no enclosing scope, lookup_transparent_type would have
+     found it. */
+  if (scope_len == 0)
+    return NULL;
+
+  full_name = alloca (scope_len + 2 + strlen (name) + 1);
+  strncpy (full_name, scope, scope_len);
+  strncpy (full_name + scope_len, "::", 2);
+  strcpy (full_name + scope_len + 2, name);
+
+  return lookup_transparent_type_aux (full_name);
 }
 
 /* Allocate everything necessary for namespace_block and
Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.1.2.16
diff -u -p -r1.1.2.16 cp-support.h
--- cp-support.h	23 May 2003 18:40:35 -0000	1.1.2.16
+++ cp-support.h	23 May 2003 22:22:50 -0000
@@ -104,6 +104,8 @@ extern struct symbol *cp_lookup_symbol_n
 						  const domain_enum domain,
 						  struct symtab **symtab);
 
+struct type *lookup_transparent_type_namespace (const char *name);
+
 /* The list of "maint cplus" commands.  */
 
 extern struct cmd_list_element *maint_cplus_cmd_list;
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.70.2.38
diff -u -p -r1.70.2.38 symtab.c
--- symtab.c	23 May 2003 18:40:45 -0000	1.70.2.38
+++ symtab.c	23 May 2003 22:24:12 -0000
@@ -1604,9 +1604,29 @@ lookup_partial_symbol (struct partial_sy
    name of the type in question, so this doesn't have to get any
    smarter about namespace stuff.  */
 
+/* FIXME: carlton/2003-05-23: No, sometimes, unfortunately, the name
+   is wrong.  This function gets called when the the type in question
+   is a declaration; in that situation, our type name deduction
+   machinery doesn't work, so if the type is declared in a namespace
+   and GCC isn't giving us namespace debug info, we're screwed.  Sigh.
+   There's nothing we can do to fix this in general, I think.  */
+
 struct type *
 lookup_transparent_type (const char *name)
 {
+  struct type *retval = lookup_transparent_type_aux (name);
+
+  if (retval != NULL)
+    return retval;
+  else
+    /* See above FIXME comment: with proper debug info, this should
+       never be necessary (or even desirable).  */
+    return lookup_transparent_type_namespace (name);
+}
+
+struct type *
+lookup_transparent_type_aux (const char *name)
+{
   register struct symbol *sym;
   register struct symtab *s = NULL;
   register struct partial_symtab *ps;
@@ -1649,9 +1669,7 @@ lookup_transparent_type (const char *nam
 	    block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 	    sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
 	    if (!sym)
-	      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>).",
+	      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, ps->filename, name, name);
 	  }
 	if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
@@ -1696,9 +1714,7 @@ lookup_transparent_type (const char *nam
 	    block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 	    sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
 	    if (!sym)
-	      error ("Internal: static 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>).",
+	      error ("Internal: static 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, ps->filename, name, name);
 	  }
 	if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
@@ -1707,7 +1723,6 @@ lookup_transparent_type (const char *nam
   }
   return (struct type *) 0;
 }
-
 
 /* Find the psymtab containing main(). */
 /* FIXME:  What about languages without main() or specially linked
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.42.2.26
diff -u -p -r1.42.2.26 symtab.h
--- symtab.h	23 May 2003 18:40:46 -0000	1.42.2.26
+++ symtab.h	23 May 2003 22:24:28 -0000
@@ -1123,6 +1123,8 @@ extern void reread_symbols (void);
 
 extern struct type *lookup_transparent_type (const char *);
 
+extern struct type *lookup_transparent_type_aux (const char *name);
+
 
 /* Macro for name of symbol to indicate a file compiled with gcc. */
 #ifndef GCC_COMPILED_FLAG_SYMBOL


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