Bug 9059 - gdb problem with typedefs
Summary: gdb problem with typedefs
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: exp (show other bugs)
Version: 6.3
: P2 critical
Target Milestone: 7.0
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-01 00:58 UTC by emailamit
Modified: 2009-02-02 21:51 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description emailamit 2005-06-01 00:58:01 UTC
[Converted from Gnats 1954]

gdb seems to have a problem with evaluating expression using typedef's on pointers type. In the following code

--------------a.cpp-------------------------------------------
------------
 #include <stdio.h>
 
 class a {
  public:
   a(int x) {m = x;}
   ~a() {}
 
   void printm() {printf("%d\n", m); fflush(stdout);}
 
  private:
   int m;
 };
 
 typedef   a* aHdl;
 
 int main()
 {
   aHdl aptr = new a(100);
 
   a* aRealPtr = new a(4);
  
   aptr->printm(); 
   aRealPtr->printm(); //this works
 }
 --------------------------------------------------------------

Running gdb on this code and setting a breakpoint after both aptr and aRealPtr are properly initialized; If I call the function aptr->printm() from the gdb command line, it results into seg-fault. Apparently gdb is treating aptr as of type (class a), rather than (class a*).

-----------LOG OF GDB RUN------------------
~/Y/test> /tools/gcc/3.4.0/bin/gcc -Wall -g a.cpp /tools/linux-ia32/fsf/gcc/3.4.0/lib/libstdc++.a
78:agupta@abel:~/Y/test> /tool/gdb ./a.out
GNU gdb 6.2
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) b main
Breakpoint 1 at 0x8048991: file a.cpp, line 18.
(gdb) r
Starting program: a.out 

Breakpoint 1, main () at a.cpp:18
18	  aHdl aptr = new a(100);
(gdb) n
20	  a* aRealPtr = new a(4);
(gdb) 
22	  aptr->printm();
(gdb) 
100
23	  aRealPtr->printm();
(gdb) p aRealPtr->printm()
4
$1 = void
(gdb) p aptr->printm()
Program received signal SIGSEGV, Segmentation fault.
0x080489fd in a::printm (this=0x64) at a.cpp:8
8	  void printm() {printf("%d\n", m); fflush(stdout);}
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (a::printm()) will be abandoned.
(gdb) p this
$2 = (a * const) 0x64
(gdb)

Release:
gdb-6.2 and gdb 6.3

Environment:
2.4.21-4.ELsmp #1 SMP--i686 i386 GNU/Linux.
gdb and source code Compiled using gcc 3.4.0
Comment 1 Tom Tromey 2008-12-19 23:00:58 UTC
Testing a fix.
Comment 2 Sourceware Commits 2009-02-02 21:50:26 UTC
Subject: Bug 9059

CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2009-02-02 21:50:13

Modified files:
	gdb            : ChangeLog valops.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: call-c.cc call-c.exp 

Log message:
	gdb
	PR exp/9059:
	* valops.c (find_overload_match): Follow typedefs before taking
	address of object argument.
	gdb/testsuite
	PR exp/9059:
	* gdb.cp/call-c.exp: Add regression test.
	* gdb.cp/call-c.cc (FooHandle): New typedef.
	(main): New variable 'handle'.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.10149&r2=1.10150
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/valops.c.diff?cvsroot=src&r1=1.207&r2=1.208
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1797&r2=1.1798
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/call-c.cc.diff?cvsroot=src&r1=1.6&r2=1.7
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/call-c.exp.diff?cvsroot=src&r1=1.6&r2=1.7

Comment 3 Tom Tromey 2009-02-02 21:51:04 UTC
I've checked in the fix.