public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
@ 2011-11-11 12:43 zbojthe at urdeso dot hu
  2011-11-11 12:44 ` [Bug c++/13403] " zbojthe at urdeso dot hu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zbojthe at urdeso dot hu @ 2011-11-11 12:43 UTC (permalink / raw)
  To: gdb-prs

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
@ 2011-11-11 12:44 ` zbojthe at urdeso dot hu
  2011-12-15  8:45 ` zbojthe at urdeso dot hu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zbojthe at urdeso dot hu @ 2011-11-11 12:44 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13403

Zoltan Bojthe <zbojthe at urdeso dot hu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zbojthe at urdeso dot hu

-- 
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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
  2011-11-11 12:44 ` [Bug c++/13403] " zbojthe at urdeso dot hu
@ 2011-12-15  8:45 ` zbojthe at urdeso dot hu
  2012-03-15 12:18 ` gbenson at redhat dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zbojthe at urdeso dot hu @ 2011-12-15  8:45 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13403

Zoltan Bojthe <zbojthe at urdeso dot hu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical

-- 
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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
  2011-11-11 12:44 ` [Bug c++/13403] " zbojthe at urdeso dot hu
  2011-12-15  8:45 ` zbojthe at urdeso dot hu
@ 2012-03-15 12:18 ` gbenson at redhat dot com
  2014-06-18 12:52 ` sivachandra at google dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gbenson at redhat dot com @ 2012-03-15 12:18 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13403

Gary Benson <gbenson at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gbenson at redhat dot com
         AssignedTo|unassigned at sourceware    |gbenson at redhat dot com
                   |dot org                     |

-- 
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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
                   ` (2 preceding siblings ...)
  2012-03-15 12:18 ` gbenson at redhat dot com
@ 2014-06-18 12:52 ` sivachandra at google dot com
  2014-06-18 13:14 ` gbenson at redhat dot com
  2014-10-15 11:41 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: sivachandra at google dot com @ 2014-06-18 12:52 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13403

Siva Chandra <sivachandra at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sivachandra at google dot com

--- Comment #1 from Siva Chandra <sivachandra at google dot com> ---
I think the source of the problem is bad calling convention.

FWIW, amd64-tdep.c does not align with
http://mentorembedded.github.io/cxx-abi/abi.html#return-value. I do not think
the fix is straight forward (consider c++11 with =default annotations on the
destructors and constructors which is not emitted in the DWARF by gcc
currently). One could probably come up with a fix which can improve the
situation but not fix this problem thoroughly.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
                   ` (3 preceding siblings ...)
  2014-06-18 12:52 ` sivachandra at google dot com
@ 2014-06-18 13:14 ` gbenson at redhat dot com
  2014-10-15 11:41 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: gbenson at redhat dot com @ 2014-06-18 13:14 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13403

Gary Benson <gbenson at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gbenson at redhat dot com          |

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/13403] invalid vptr after gdb prints the return value of a virtual function member on x86_64 system
  2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
                   ` (4 preceding siblings ...)
  2014-06-18 13:14 ` gbenson at redhat dot com
@ 2014-10-15 11:41 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2014-10-15 11:41 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13403

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  ebb8ece2ef50ba3f86e8b4ab7a22a4c7734d114b (commit)
       via  2d1c107c1b8835f4e85c35320d8595a4a6fcaebe (commit)
       via  82c48ac732edb0155288a93ef3dd39625ff2d2e1 (commit)
       via  778811d5e7eb96b5ecb848033ffaa2df455a921e (commit)
      from  91dc4e0a22515bec2d60a8a402970bca5042f26f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ebb8ece2ef50ba3f86e8b4ab7a22a4c7734d114b

commit ebb8ece2ef50ba3f86e8b4ab7a22a4c7734d114b
Author: Siva Chandra <sivachandra@chromium.org>
Date:   Tue Sep 9 06:50:26 2014 -0700

    Fix gnuv3_pass_by_reference to treat dynamic classes as non-trivial.

    gdb/ChangeLog:

        * gnu-v3-abi.c (gnuv3_pass_by_reference): Treat dynamic classes
        as non-trivial.

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d1c107c1b8835f4e85c35320d8595a4a6fcaebe

commit 2d1c107c1b8835f4e85c35320d8595a4a6fcaebe
Author: Siva Chandra <sivachandra@chromium.org>
Date:   Tue Sep 9 06:46:14 2014 -0700

    Add new non-trial return value tests.

    gdb/testsuite/ChangeLog:

        * gdb.cp/non-trivial-retval.cc: Add new test cases.
        * gdb.cp/non-trivial-retval.exp: Add new tests.

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=82c48ac732edb0155288a93ef3dd39625ff2d2e1

commit 82c48ac732edb0155288a93ef3dd39625ff2d2e1
Author: Siva Chandra <sivachandra@chromium.org>
Date:   Tue Sep 9 06:03:42 2014 -0700

    Fix gnuv3_pass_by_reference to lookup copy c-tors with qualified args.

    Before this, a copy constructor declared as in the following snippet was
    not being treated as a copy constructor.

    class A
    {
    public:
      A (A &); // OK.
      A (const A &); // Not being treated as a copy constructor because of the
                     // 'const' qualifier.
    };

    gdb/ChangeLog:

        PR c++/13403
        PR c++/15154
        * gnu-v3-abi.c (gnuv3_pass_by_reference): Lookup copy constructors
        with qualified args.

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=778811d5e7eb96b5ecb848033ffaa2df455a921e

commit 778811d5e7eb96b5ecb848033ffaa2df455a921e
Author: Siva Chandra <sivachandra@chromium.org>
Date:   Mon Sep 8 07:04:59 2014 -0700

    Non trivial return value tests.

    gdb/testsuite/ChangeLog:

        PR c++/13403
        PR c++/15154
        * gdb.cp/non-trivial-retval.cc: New file.
        * gdb.cp/non-trivial-retval.exp: New file.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                               |   12 +++
 gdb/gnu-v3-abi.c                            |   21 ++++-
 gdb/testsuite/ChangeLog                     |   12 +++
 gdb/testsuite/gdb.cp/non-trivial-retval.cc  |  119 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.cp/non-trivial-retval.exp |   36 ++++++++
 5 files changed, 195 insertions(+), 5 deletions(-)
 create mode 100644 gdb/testsuite/gdb.cp/non-trivial-retval.cc
 create mode 100644 gdb/testsuite/gdb.cp/non-trivial-retval.exp

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-10-15 11:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-11 12:43 [Bug c++/13403] New: invalid vptr after gdb prints the return value of a virtual function member on x86_64 system zbojthe at urdeso dot hu
2011-11-11 12:44 ` [Bug c++/13403] " zbojthe at urdeso dot hu
2011-12-15  8:45 ` zbojthe at urdeso dot hu
2012-03-15 12:18 ` gbenson at redhat dot com
2014-06-18 12:52 ` sivachandra at google dot com
2014-06-18 13:14 ` gbenson at redhat dot com
2014-10-15 11:41 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).