Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Is physname mangled or not?  (PR c++/8216)
@ 2011-05-03 18:59 Ulrich Weigand
  2011-05-04 15:09 ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Ulrich Weigand @ 2011-05-03 18:59 UTC (permalink / raw)
  To: gdb-patches

Hello,

PR c++/8216 says:

When doing ptype on a templated class, GDB will print
out constructors as having a return type of void
instead of as having no return type at all.

Code in c-typename.c:c_type_print_base does this in an attempt
to determine whether a method is a constructor:

              char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
              char *name = type_name_no_tag (type);
              int is_constructor = name && strcmp (method_name,
                                                   name) == 0;

              for (j = 0; j < len2; j++)
                {
                  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
                  int is_full_physname_constructor =
                    is_constructor_name (physname)
                    || is_destructor_name (physname)
                    || method_name[0] == '~';

[...]
                  else if (!is_constructor      /* Constructors don't
                                                   have declared
                                                   types.  */
                           && !is_full_physname_constructor  /* " " */
                           && !is_type_conversion_operator (type, i, j))


So basically this says: a method is a constructor if either:
 - the method name equals the type name, or
 - the C++ ABI routine says the physname is a constructor

and, a method is a destructor if either:
 - the method name starts with a ~, or
 - the C++ ABI routine says the physname is a destructor

I'm not quite sure why we need those duplicate checks, but in
any case for the constructor they both fail:

 - For template classes, the method name of a constructor does
   *not* contain the template instance type list, while the type
   name does, and thus the strcmp fails

 - The is_constructor_name C++ ABI callback actually fails
   *always*.  This is because it works only if it gets a 
   *mangled* name as input, but TYPE_FN_FIELD_PHYSNAME returns
   a demangled name (at least with dwarf2read.c) ...

(For destructors, this problem doesn't apply since the ~ test
catches just about everything.  I'm just wondering why we still
try to do the is_destructor_name (physname) check as well ...)

This latter seems to have been due to a deliberate change of
physname: dwarf2read now always sets this to a demangled name,
while e.g. stabsread sets it to a mangled name.

So I guess my question is, how is this supposed to work?  Should
is_constructor_name accept demangled names?  Should there be some
generic routine that instead tests a demangled name for whether
it is a constructor (or destructor)?

Any suggestions to fix this would be appreciated ...

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-05-05 17:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-03 18:59 Is physname mangled or not? (PR c++/8216) Ulrich Weigand
2011-05-04 15:09 ` Jan Kratochvil
2011-05-04 17:00   ` Daniel Jacobowitz
2011-05-04 17:10     ` Jan Kratochvil
2011-05-04 17:33   ` Ulrich Weigand
2011-05-04 17:57     ` Jan Kratochvil
2011-05-04 17:58     ` Daniel Jacobowitz
2011-05-05 17:10       ` Ulrich Weigand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox