This is the mail archive of the gdb-prs@sources.redhat.com 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]

exp/1954: gdb problem with typedefs


>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
>Closed-Date:
>Last-Modified:
>Originator:     Amit Gupta
>Release:        gdb-6.2 and gdb 6.3
>Organization:
>Environment:
2.4.21-4.ELsmp #1 SMP--i686 i386 GNU/Linux.
gdb and source code Compiled using gcc 3.4.0
>Description:
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) 
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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