This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
[Bug c++/13403] New: invalid vptr after gdb prints the return valueof a virtual function member on x86_64 system
- From: "zbojthe at urdeso dot hu" <sourceware-bugzilla at sourceware dot org>
- To: gdb-prs at sourceware dot org
- Date: Fri, 11 Nov 2011 12:43:17 +0000
- Subject: [Bug c++/13403] New: invalid vptr after gdb prints the return valueof a virtual function member on x86_64 system
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=13403
Bug #: 13403
Summary: invalid vptr after gdb prints the return value of a
virtual function member on x86_64 system
Product: gdb
Version: 7.3
Status: NEW
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned@sourceware.org
ReportedBy: zbojthe@urdeso.hu
Classification: Unclassified
Created attachment 6051
--> http://sourceware.org/bugzilla/attachment.cgi?id=6051
c++ code, build/run scripts, outputs
The virtual function getMyVal() of MyClass returns a MyVal object as value, and
MyVal object size is small, and MyVal object has copy constructor.
When I use "p myClass->getMyVal()", the gdb calls the copy ctor of MyVal badly,
and copy ctor overwrite the vptr of the myClass.
When I remove the copy ctor of MyVal, or I add some dummy members to MyVal, the
gdb will work correctly.
Tested in Ubuntu 11.10, 64 bit. (On Ubuntu 11.10, 32 bit, work correctly)
See attached files.
--8<--
a.cc:
class MyVal
{
int val;
// when added next line, the gdb print work correctly when dimension >= 4
// int dummy[4];
public:
MyVal() { val = 42; }
MyVal(int _val) { val = _val; }
// when remove the next copy ctor, the gdb print work correctly
MyVal(const MyVal& other) { val = other.val; }
};
class MyClassBase
{
public:
virtual MyVal getMyVal() = 0;
};
class MyClass : public MyClassBase
{
MyVal myVal;
public:
virtual MyVal getMyVal() { return myVal; }
};
int main(int argc, const char **argv)
{
MyClassBase *myClass = new MyClass();
MyVal m;
m = myClass->getMyVal();
m = myClass->getMyVal();
}
--8<--
debugging:
gdb a.out
start
n
n
p *myClass
# {_vptr.MyClassBase = <valid_vptr_address>}
p myClass->getMyVal()
# {val = <address of myClass>}
p *myClass
# {_vptr.MyClassBase = 0x0}
p myClass->getMyVal()
#Cannot access memory at address 0x0
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.