This is the mail archive of the gdb-prs@sourceware.org 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]

[Bug symtab/16040] ptype prints the wrong type for members with typedef coming from outside class


https://sourceware.org/bugzilla/show_bug.cgi?id=16040

Keith Seitz <keiths at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |keiths at redhat dot com

--- Comment #1 from Keith Seitz <keiths at redhat dot com> ---
I was playing around a bit today and took a look at what was going on.

This regression was introduced by the following commit:

commit bd69fc683f383772bb8fab43c5d4af8d0cd4a8b4
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 12 17:37:38 2012 +0000

        * c-typeprint.c (find_typedef_for_canonicalize,
        print_name_maybe_canonical): New functions.
        (c_print_type): Look up type name.
[snip]

When c_print_type goes to print `x', it attempts to look up the typedef in the
typedef hash:

  local_name = find_typedef_in_hash (flags, type);

find_typedef_in_hash eventually calls hash_typedef_field, which simply does:

hash_typedef_field (const void *p)
{
  const struct typedef_field *tf = p;
  struct type *t = check_typedef (tf->type);

  return htab_hash_string (TYPE_SAFE_NAME (t));
}

As you can see, it reduces all typedefs to their corresponding fundamental
type. In this case it is `int'. As a result, since the current scope (class c)
defines a typedef for `int' as `another_int', that is what is returned.

Anytime there are multiple typedefs that exist for the same type, this hash
lookup will likely return the wrong typedef name. I used a class which defined
three typedefs for int: int1, int2, int3. As expected, `ptype CLASS' shows all
three typedefs as int1, even though `whatis' shows the proper typedef names for
all three member variables.

[Note about the supplied test case, one must add a reference to another_int in
order for this to demonstrate the failure.]

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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