Bug 15154 - Non-POD class causes garbage when printing object from a return value
Summary: Non-POD class causes garbage when printing object from a return value
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.5
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-18 15:43 UTC by Morten Stenshorne
Modified: 2015-02-03 09:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Test case (368 bytes, text/plain)
2013-02-18 15:43 UTC, Morten Stenshorne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Morten Stenshorne 2013-02-18 15:43:42 UTC
Created attachment 6874 [details]
Test case

It seems impossible to print non-POD object values from return values correctly. Also happens with "print function()" when function() returns something non-POD. That even crashes sometimes.

See attachment. Works fine if PREVENT_NONPOD is defined.

This is with gdb 7.4.1-debian , but it also fails when building 7.5 on my own.

Full output from gdb --version:
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Comment 1 cvs-commit@gcc.gnu.org 2014-10-15 11:41:28 UTC
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
Comment 2 Samuel Bronson 2015-02-03 07:13:54 UTC
Still doesn't DTRT with, say, std::list<std::string> and pretty printers; see https://bugs.debian.org/776893 for an example: it seems to copy the object byte-by-byte to some other location and print that one, with the result that the printer goes around the list over and over and over and over because it can never find the link-to-header it expects to indicate the end of the list.
Comment 3 Siva Chandra 2015-02-03 09:06:36 UTC
(In reply to Samuel Bronson from comment #2)
> Still doesn't DTRT with, say, std::list<std::string> and pretty printers;
> see https://bugs.debian.org/776893 for an example: it seems to copy the
> object byte-by-byte to some other location and print that one, with the
> result that the printer goes around the list over and over and over and over
> because it can never find the link-to-header it expects to indicate the end
> of the list.

I do not think the original problem in this PR and the above are related. I think a new/different bug would be good.