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]

[drow-cplus-branch] Stabs: basic type inference


This infers the name of classes from the names of their constructors.  I had
the matching DWARF-2 code somewhere but I can't find it, so I'll redo it in
a couple of days.

There's more we could do; theoretically we could use the demangled names to
infer the proper names of types used as method arguments.  I think.  But
that's a great deal of work for very little return, and extremely
complicated.  We could more easily use that to get correct const/volatile
qualifiers on parameters the compiler didn't tell us about.  Same caveat.

Someday (maybe) we'll get GCC to emit proper stabs which contain this
information explicitly; this is just an interim bone thrown to the compilers
which don't give us enough.  Incidentally, Sun's current stabs specification
has extensions describing namespaces etc.  The obvious thing to do would be:
  - Add proper GDB support for the current Sun stabs output.
[definitely, because it gives us much better support for what is currently a
dbx-only task.  but this needs someone with access to Solaris tools and
enough patience.]
  - Add GCC support to generate the Sun stabs.
[If we can think of a reason!]

The ideal thing to do would be:
  - Fix up our lame DWARF-2 reader
[in progress, very slowly while Dan is distracted and Petr is incommunicado
and the other interested individual is in copyright limbo.]
  - Get even more GCC targets to default to DWARF-2 (-3) and shout more loudly
for people to use it if they want C++ to work.

Committed to branch.  As said I'll try to follow up with the equivalent
DWARF-2 patch in a few days.  Then I want to spend some time hammering on
the output, and only then will I add the namespace code to dwarf2read and
start testing with a DWARF-3/namespace-info enabled GCC.

This patch will probably break at least some cases of unstubbing.  Types
that used to be found as "Foo" will now only be found as "Inner::Foo" and we
don't pass the context anywhere when we're looking up the arguments.  That
obviously needs to change!

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-10-05  Daniel Jacobowitz  <drow@mvista.com>

	* stabsread.c (read_member_functions): Update comment.
	Set TYPE_NAME if possible.

Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.41
diff -u -p -r1.41 stabsread.c
--- stabsread.c	19 Sep 2002 03:58:41 -0000	1.41
+++ stabsread.c	6 Oct 2002 03:04:06 -0000
@@ -3116,6 +3116,9 @@ update_method_name_from_physname (char *
    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
    name (such as `+=') and `.' marks the end of the operator name.
 
+   If we read at least one method with a complete physname, set
+   TYPE_NAME (TYPE) appropriately.
+
    Returns 1 for success, 0 for failure.  */
 
 static int
@@ -3248,6 +3251,34 @@ read_member_functions (struct field_info
 	    }
 	  new_sublist->fn_field.physname = savestring (*pp, p - *pp);
 	  *pp = p + 1;
+
+	  /* For classes with qualified names (e.g. nested classes, classes
+	     in namespaces, etc.) we can infer what the fully qualified name
+	     should be.  GCC doesn't output this information directly,
+	     but it does output mangled names for methods:
+	     - Every class will have debug information for at least one
+	     constructor, either user specified or compiler-synthesized.
+	     - For v3 there are no abbreviated physnames, so we can find the
+	     fully qualified class name from such a constructor.
+	     - For v2 constructors (related to the fact that the mangled name
+	     for a constructor starts with a double underscore instead of
+	     with the method name, as for ordinary methods) the full physname
+	     will be included.
+
+	     So from a constructor we can infer the class's qualified name.  */
+
+	  if (TYPE_NAME (type) == NULL
+	      && is_constructor_name (new_sublist->fn_field.physname))
+	    {
+	      char *class_name
+		= class_name_from_physname (new_sublist->fn_field.physname);
+
+	      /* G++ anonymous structures have names starting with '.' or
+		 '$'.  */
+	      if (is_cplus_marker (class_name[0]))
+		TYPE_NAME (type) = obconcat (&objfile->type_obstack, "",
+					     "", class_name);
+	    }
 
 	  /* Set this member function's visibility fields.  */
 	  switch (*(*pp)++)


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