exp/1954: gdb problem with typedefs

emailamit@gmail.com emailamit@gmail.com
Wed Jun 1 00:58:00 GMT 2005

>Number:         1954
>Category:       exp
>Synopsis:       gdb problem with typedefs
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 01 00:58:01 UTC 2005
>Originator:     Amit Gupta
>Release:        gdb-6.2 and gdb 6.3
2.4.21-4.ELsmp #1 SMP--i686 i386 GNU/Linux.
gdb and source code Compiled using gcc 3.4.0
gdb seems to have a problem with evaluating expression using typedef's on pointers type. In the following code

 #include <stdio.h>
 class a {
   a(int x) {m = x;}
   ~a() {}
   void printm() {printf("%d\n", m); fflush(stdout);}
   int m;
 typedef   a* aHdl;
 int main()
   aHdl aptr = new a(100);
   a* aRealPtr = new a(4);
   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);
22	  aptr->printm();
23	  aRealPtr->printm();
(gdb) p aRealPtr->printm()
$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



More information about the Gdb-prs mailing list