Bug 36625

Summary: gdb and C++ cast
Product: [Retired] Red Hat Linux Reporter: Jakub Jelinek <jakub>
Component: gdbAssignee: Elena Zannoni <ezannoni>
Status: CLOSED CANTFIX QA Contact: Aaron Brown <abrown>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-10-18 17:29:27 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Jakub Jelinek 2001-04-19 10:48:27 UTC
Compile without optimization:
struct A {
  int i;
  virtual ~A();
};

struct B : public A {
  int j, k;
  virtual ~B();
};

A::~A()
{
}

B::~B()
{
}

int main(void)
{
  A *x;
  B y, *z;
  y.i = 1;
  y.j = 2;
  y.k = 3;
  x = &y;
  z = (B *)x;
}

and in gdb:
(gdb) b 27; n
(gdb) p *z
$2 = {<A> = {i = 1, _vptr. = 0x8049838}, j = 2, k = 3}
(gdb) p y
$3 = {<A> = {i = 1, _vptr. = 0x8049838}, j = 2, k = 3}
(gdb) p *(B *)x
$4 = {<A> = {i = 1, _vptr. = 0x8049838}, j = 0, k = 0}
                                         ^^^^^^^^^^^^
This should IMHO print 2, 3, it is viewing the same memory as y or *z.
Tested with our g++, egcs++, g++ 3.1 branch and both with -g and -gdwarf-2,
happens everywhere, so it looks like gdb issue.

Comment 1 Trond Eivind Glomsrxd 2001-04-20 15:10:22 UTC
Verified.

Comment 2 Trond Eivind Glomsrxd 2001-07-30 20:15:42 UTC
Still a problem with CVS gdb.

Comment 3 Trond Eivind Glomsrxd 2001-11-28 23:57:43 UTC
Still a problem with gdb 5.1

Comment 4 Trond Eivind Glomsrxd 2002-05-07 22:22:44 UTC
And 5.2

Comment 5 Bill Nottingham 2006-08-07 20:05:58 UTC
Red Hat Linux is no longer supported by Red Hat, Inc. If you are still
running Red Hat Linux, you are strongly advised to upgrade to a
current Fedora Core release or Red Hat Enterprise Linux or comparable.
Some information on which option may be right for you is available at
http://www.redhat.com/rhel/migrate/redhatlinux/.

Red Hat apologizes that these issues have not been resolved yet. We do
want to make sure that no important bugs slip through the cracks.
Please check if this issue is still present in a current Fedora Core
release. If so, please change the product and version to match, and
check the box indicating that the requested information has been
provided. Note that any bug still open against Red Hat Linux on will be
closed as 'CANTFIX' on September 30, 2006. Thanks again for your help.


Comment 6 Bill Nottingham 2006-10-18 17:29:27 UTC
Red Hat Linux is no longer supported by Red Hat, Inc. If you are still
running Red Hat Linux, you are strongly advised to upgrade to a
current Fedora Core release or Red Hat Enterprise Linux or comparable.
Some information on which option may be right for you is available at
http://www.redhat.com/rhel/migrate/redhatlinux/.

Closing as CANTFIX.