This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
symtab/1943: method call with typedef'd pointer fails
- From: mln at cray dot com
- To: gdb-gnats at sources dot redhat dot com
- Date: 12 May 2005 03:21:06 -0000
- Subject: symtab/1943: method call with typedef'd pointer fails
- Reply-to: mln at cray dot com
>Number: 1943
>Category: symtab
>Synopsis: method call with typedef'd pointer fails
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu May 12 03:28:00 UTC 2005
>Closed-Date:
>Last-Modified:
>Originator: Mark Niehaus
>Release: 6.3
>Organization:
>Environment:
sparc-sun-solaris2.9
>Description:
When debugging in C++ code, calling a method on an object referenced through a typedef'd pointer fails. For instance, compile the following program with gcc 3.4.3 and set a breakpoint on the return statement. When you hit it, print f->print() and g->print(). With gdb-6.3, the former works, while the latter hits a segfault. The problem is that there is code in valops.c that checks if the object is a pointer, but it neglects to check if the object's type is a typedef of a pointer. A patch follows.
#include <stdio.h>
class foo {
public:
int x;
void print();
};
typedef foo *fooP;
void foo::print() {
printf("%d\n", x);
}
main() {
foo *f;
fooP g;
f = new foo;
g = new foo;
f->x=42;
f->print();
g->x = 84;
g->print();
return 0;
}
>How-To-Repeat:
g++ -g foo.c
gdb a.out
(gdb) b 24
(gdb) run
(gdb) p f->print()
42
$1 = void
(gdb) p g->print()
Program received signal SIGSEGV, Segmentation fault.
0x00010724 in foo::print (this=0x54) at cpl.cc:12
12 printf("%d\n", x);
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 (foo::print()) will be abandoned.
(gdb)
>Fix:
% diff -c valops.c.old valops.c
*** valops.c.old Mon Sep 13 20:01:48 2004
--- valops.c Wed May 11 20:07:48 2005
***************
*** 1973,1979 ****
if (objp)
{
if (TYPE_CODE (VALUE_TYPE (temp)) != TYPE_CODE_PTR
! && TYPE_CODE (VALUE_TYPE (*objp)) == TYPE_CODE_PTR)
{
temp = value_addr (temp);
}
--- 1973,1981 ----
if (objp)
{
if (TYPE_CODE (VALUE_TYPE (temp)) != TYPE_CODE_PTR
! && (TYPE_CODE (VALUE_TYPE (*objp)) == TYPE_CODE_PTR ||
! (TYPE_CODE (VALUE_TYPE (*objp)) == TYPE_CODE_TYPEDEF &&
! TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (*objp))) == TYPE_CODE_PTR)))
{
temp = value_addr (temp);
}
>Release-Note:
>Audit-Trail:
>Unformatted: