Bug 8888 - Gdb can't lookup class typedef when in methods of the class
Summary: Gdb can't lookup class typedef when in methods of the class
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 7.6
Assignee: Tom Tromey
URL:
Keywords:
: 9376 11912 12563 12585 13544 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-22 20:38 UTC by James Ingham
Modified: 2012-12-14 21:23 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
main.cpp (186 bytes, application/octet-stream)
, James Ingham
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Ingham 2004-09-22 20:38:01 UTC
[Converted from Gnats 1783]

If you try to ptype the type name for a class (or cast something to the type name) when the current block is in a method of the class, the ptype will fail.

The exact failure mode changes depending on how the class is defined, sometimes it prints the type of the class constructor, sometimes it tries to lookup the name as a struct element of the "this" pointer.

I have an example of the latter case in the How-To-Repeat section.

This bug was introduced when the cp_lookup_symbol_nonlocal was added to lookup_symbol_aux.  When we go to lookup types, we look first in the namespace for the current block, and in this case, there is something in that namespace with the name we are providing, though it isn't what we want...

You can work around this by always using (class ClassName) instead of just ClassName, but this is unnatural to most C++ programmers...

Not sure how to fix this without breaking other legitimate cases of namespace lookup, however.

Release:
Current TOT (as of 9-22-04)

Environment:
x86 Linux - FedoreCore2

How-To-Repeat:
Compile the attached file:

$ g++ -g -O0 main.cpp

Then run it under gdb:

$ gdb a.out
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) break main
Breakpoint 1 at 0x8048591: file main.cpp, line 21.
(gdb) break Foo::callMe
Breakpoint 2 at 0x80485ce: file main.cpp, line 12.
(gdb) run
Starting program: /home/jingham/testme 

Breakpoint 1, main () at main.cpp:21
21        Foo *mine = new Foo(5);
(gdb) set debug expression 1
(gdb) ptype Foo
Dump of expression @ 0xa064758'
        Language c++, 3 elements, 12 bytes each.
        Index                Opcode         Hex Value  String Value
            0               OP_TYPE  -73782349824786339  ]...X.......
            1   <unknown 165277912>  -73782349659508520  ....X.......
            2               OP_TYPE  -73782349824786339  ]...X.......
Dump of expression @ 0xa064758, after conversion to prefix form:
Expression: `Type printing not yet supported....'
        Language c++, 3 elements, 12 bytes each.


            0  OP_TYPE               Type @0x9d9f0d8 (Foo)
type = class Foo {
  private:
    int intVal;

  public:
    Foo(int);
    void callMe();
    Foo & operator=(Foo const&);
    Foo(Foo const&);
}
(gdb) c
Continuing.

Breakpoint 2, Foo::callMe (this=0x9b1d008) at main.cpp:12
12          printf ("I have a value of %d\n", intVal);
(gdb) ptype Foo
Dump of expression @ 0x9e0bc00'
        Language c++, 7 elements, 12 bytes each.
        Index                Opcode         Hex Value  String Value
            0               OP_THIS  -73782349824786344  X...X.......
            1               OP_THIS  -73782349824786344  X...X.......
            2          STRUCTOP_PTR  -73782349824786345  W...X.......
            3             BINOP_MUL  3  ............
            4     <unknown 7302982>  7302982  Foo.....HH..
            5             BINOP_MUL  3  ............
            6          STRUCTOP_PTR  87  W...........
Dump of expression @ 0x9e0bc00, after conversion to prefix form:
Expression: `this->Foo'
        Language c++, 7 elements, 12 bytes each.


            0  STRUCTOP_PTR          Element name: `Foo'
            5    OP_THIS               Unknown format
            6  OP_THIS               Unknown format
Dump of expression @ 0x9e0bd30'
        Language c++, 7 elements, 12 bytes each.
        Index                Opcode         Hex Value  String Value
            0               OP_THIS  88  X...........
            1               OP_THIS  88  X...........
            2          STRUCTOP_PTR  87  W...........
            3             BINOP_MUL  3  ............
            4     <unknown 7302982>  51430515389984582  Foo.....2...
            5             BINOP_MUL  3  ............
            6          STRUCTOP_PTR  87  W...........
Dump of expression @ 0x9e0bd30, after conversion to prefix form:
Expression: `this->Foo'
        Language c++, 7 elements, 12 bytes each.


            0  STRUCTOP_PTR          Element name: `Foo'
            5    OP_THIS               Unknown format
            6  OP_THIS               Unknown format
Type Foo has no component named Foo.
(gdb)

Note that when you were stopped in Main, gdb was able to successfully print the type Foo.  But in a method of the class Foo, it can't.
Comment 1 Tom Tromey 2010-01-25 16:33:31 UTC
*** Bug 9376 has been marked as a duplicate of this bug. ***
Comment 2 Tom Tromey 2012-11-09 16:30:54 UTC
*** Bug 14819 has been marked as a duplicate of this bug. ***
Comment 3 Tom Tromey 2012-11-21 19:44:45 UTC
Testing a fix.
Comment 4 Tom Tromey 2012-11-21 21:37:23 UTC
*** Bug 12585 has been marked as a duplicate of this bug. ***
Comment 5 Tom Tromey 2012-11-21 21:47:03 UTC
*** Bug 13544 has been marked as a duplicate of this bug. ***
Comment 6 Tom Tromey 2012-11-28 17:24:37 UTC
*** Bug 12563 has been marked as a duplicate of this bug. ***
Comment 7 Tom Tromey 2012-12-14 19:25:05 UTC
*** Bug 11912 has been marked as a duplicate of this bug. ***
Comment 8 Sourceware Commits 2012-12-14 21:19:16 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2012-12-14 21:19:11

Modified files:
	gdb            : ChangeLog c-exp.y symtab.c 
	gdb/testsuite  : ChangeLog 
Added files:
	gdb/testsuite/gdb.cp: member-name.cc member-name.exp 

Log message:
	PR c++/8888:
	* symtab.c (lookup_symbol_aux): If constructor is found, consider
	returning the type instead.
	* c-exp.y (classify_name): Check STRUCT_DOMAIN if a constructor is
	found.
	testsuite
	* gdb.cp/member-name.exp: New file.
	* gdb.cp/member-name.cc: New file.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.14926&r2=1.14927
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/c-exp.y.diff?cvsroot=src&r1=1.107&r2=1.108
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/symtab.c.diff?cvsroot=src&r1=1.329&r2=1.330
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3491&r2=1.3492
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/member-name.cc.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/member-name.exp.diff?cvsroot=src&r1=NONE&r2=1.1
Comment 9 Tom Tromey 2012-12-14 21:23:03 UTC
Fix checked in.