public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/16040] New: ptype prints the wrong type for members with typedef coming from outside class
@ 2013-10-10 23:36 dje at google dot com
  2014-01-23 18:01 ` [Bug symtab/16040] " keiths at redhat dot com
  2024-01-11 18:24 ` ssbssa at sourceware dot org
  0 siblings, 2 replies; 3+ messages in thread
From: dje at google dot com @ 2013-10-10 23:36 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 16040
           Summary: ptype prints the wrong type for members with typedef
                    coming from outside class
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: dje at google dot com

foo.c:

typedef int my_int;

class c
{
 public:
  my_int x;
  typedef int another_int;
};

c foo;

int
main ()
{
  return 0;
}

(gdb) pty foo
type = class c {
  public:
    another_int x;   <<<<<<<<<<< this can't be right

    typedef int another_int;
}

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


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

* [Bug symtab/16040] ptype prints the wrong type for members with typedef coming from outside class
  2013-10-10 23:36 [Bug symtab/16040] New: ptype prints the wrong type for members with typedef coming from outside class dje at google dot com
@ 2014-01-23 18:01 ` keiths at redhat dot com
  2024-01-11 18:24 ` ssbssa at sourceware dot org
  1 sibling, 0 replies; 3+ messages in thread
From: keiths at redhat dot com @ 2014-01-23 18:01 UTC (permalink / raw)
  To: gdb-prs

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.


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

* [Bug symtab/16040] ptype prints the wrong type for members with typedef coming from outside class
  2013-10-10 23:36 [Bug symtab/16040] New: ptype prints the wrong type for members with typedef coming from outside class dje at google dot com
  2014-01-23 18:01 ` [Bug symtab/16040] " keiths at redhat dot com
@ 2024-01-11 18:24 ` ssbssa at sourceware dot org
  1 sibling, 0 replies; 3+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-11 18:24 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |12.1

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
Fixed since gdb-12.1:
```
(gdb) pt foo
type = class c {
  public:
    my_int x;

    typedef int another_int;
}
```

By this commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=e8db803129822d3df8e773f28dd99105a84d881d

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

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

end of thread, other threads:[~2024-01-11 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-10 23:36 [Bug symtab/16040] New: ptype prints the wrong type for members with typedef coming from outside class dje at google dot com
2014-01-23 18:01 ` [Bug symtab/16040] " keiths at redhat dot com
2024-01-11 18:24 ` ssbssa at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).