Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: gdb-patches@sourceware.org
Subject: Is physname mangled or not?  (PR c++/8216)
Date: Tue, 03 May 2011 18:59:00 -0000	[thread overview]
Message-ID: <201105031858.p43IwneJ006235@d06av02.portsmouth.uk.ibm.com> (raw)

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


             reply	other threads:[~2011-05-03 18:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03 18:59 Ulrich Weigand [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201105031858.p43IwneJ006235@d06av02.portsmouth.uk.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox