Bug 14441 - Need to support DW_TAG_rvalue_reference_type
Summary: Need to support DW_TAG_rvalue_reference_type
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 8.0
Assignee: Keith Seitz
URL:
Keywords:
: 16043 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-07 22:00 UTC by dje
Modified: 2017-03-20 21:52 UTC (History)
10 users (show)

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


Attachments
rvalue-reference.patch (1.56 KB, patch)
2016-04-04 22:48 UTC, Ed Catmur
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dje 2012-08-07 22:00:25 UTC
llvm has apparently starting emitting this.
Comment 1 Tom Tromey 2012-08-08 16:00:47 UTC
(In reply to comment #0)
> llvm has apparently starting emitting this.

gcc does too.
IIRC you can see it in libstdc++.so.
Comment 2 Jonathan Wakely 2012-10-28 13:56:03 UTC
Yes G++ trunk emits it, see http://gcc.gnu.org/PR54773

(gdb) ptype x
type = struct X {
  public:
    X & operator=(<unknown type in /dev/shm/a.out, CU 0x0, DIE 0x4b>);
}
Comment 3 Jonathan Wakely 2012-10-28 14:04:54 UTC
That link should be http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54773
Comment 4 Jan Kratochvil 2013-10-14 16:30:53 UTC
*** Bug 16043 has been marked as a duplicate of this bug. ***
Comment 5 Jan Kratochvil 2013-10-14 16:31:37 UTC
[patch] Support C++11 rvalue (move constructor)
https://sourceware.org/ml/gdb-patches/2013-10/msg00403.html
Comment 6 Jonathan Wakely 2014-11-16 17:38:32 UTC
I can live with printing rvalue refs as <unknown type in /dev/shm/a.out, CU 0x0, DIE 0x4b> but the fact you're unable to do anything with them is a much bigger problem:

struct A { int i; };

int f(A&& a)
{
  return a.i;
}

int main()
{
  return f( A() );
}

Reading symbols from ./a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x4005de: file rv.cc, line 10.
Starting program: /tmp/a.out

Temporary breakpoint 1, main () at rv.cc:10
(gdb) step
f(A&&) (a=<unknown type in /tmp/a.out, CU 0x0, DIE 0x7f>) at rv.cc:5
(gdb) p a.i
Attempt to extract a component of a value that is not a structure.

This makes it almost impossible to debug functions taking rvalues, such as move constructors and move assignment operators.

And sometimes move constructors are really hard to get right and need to be debugged (e.g. std::stringstream is giving me major headaches)
Comment 7 Ori Bar 2015-03-10 14:07:46 UTC
A temporary solution for Jontahan's problem is to write:

p ((A*)a)->i;

This becomes messy for more compilcated types
Comment 8 Avi Kivity 2015-11-13 14:16:33 UTC
It is becoming more and more difficult to debug modern C++ programs due to this bug.
Comment 9 Ed Catmur 2016-04-04 22:48:03 UTC
Created attachment 9152 [details]
rvalue-reference.patch

Updated Jan's patch to apply cleanly against 7.11.
Comment 10 Keith Seitz 2016-04-05 13:01:42 UTC
Also note that there is a patchset for this currently under review:

https://sourceware.org/ml/gdb-patches/2016-03/msg00433.html
Comment 11 Pedro Alves 2017-03-09 16:37:23 UTC
We should really get that series in.  Tentatively setting milestone to 8.0.
Comment 12 Keith Seitz 2017-03-09 17:04:52 UTC
(In reply to Pedro Alves from comment #11)
> We should really get that series in.  Tentatively setting milestone to 8.0.

I'm working on it. Should arrive in the next day or two.
Comment 13 cvs-commit@gcc.gnu.org 2017-03-20 20:50:08 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit f9aeb8d499fa12610610dc19618230304c698f6c
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:30 2017 -0700

    Add definitions for rvalue reference types
    
    This patch introduces preliminal definitions regarding C++11 rvalue references
    to the gdb type system. In addition to an enum type_code entry, a field in
    struct type and an accessor macro for that which are created similarly to the
    lvalue references counterparts, we also introduce a TYPE_REFERENCE convenience
    macro used to check for both kinds of references simultaneously as they are
    equivalent in many contexts.
    
    gdb/Changelog
    
        PR gdb/14441
        * gdbtypes.h (enum type_code) <TYPE_CODE_RVALUE_REF>: New constant.
        (TYPE_IS_REFERENCE): New macro.
        (struct type): Add rvalue_reference_type field.
        (TYPE_RVALUE_REFERENCE_TYPE): New macro.
Comment 14 cvs-commit@gcc.gnu.org 2017-03-20 20:50:14 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit 3b22433085e4cfee83f5c52f3baa8fb9bc67f8dd
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:39 2017 -0700

    Change {lookup,make}_reference_type API
    
    Parameterize lookup_reference_type() and make_reference_type() by the kind of
    reference type we want to look up. Create two wrapper functions
    lookup_{lvalue,rvalue}_reference_type() for lookup_reference_type() to simplify
    the API. Change all callers to use the new API.
    
    gdb/Changelog
    
    	PR gdb/14441
    	* dwarf2read.c (read_tag_reference_type): Use
    	lookup_lvalue_reference_type() instead of lookup_reference_type().
    	* eval.c (evaluate_subexp_standard): Likewise.
    	* f-exp.y: Likewise.
    	* gdbtypes.c (make_reference_type, lookup_reference_type):
    	Generalize with rvalue reference types.
    	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): New
    	convenience wrappers for lookup_reference_type().
    	* gdbtypes.h (make_reference_type, lookup_reference_type): Add a
    	reference kind parameter.
    	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add
    	wrappers for lookup_reference_type().
    	* guile/scm-type.c (gdbscm_type_reference): Use
    	lookup_lvalue_reference_type() instead of lookup_reference_type().
    	* guile/scm-value.c (gdbscm_value_dynamic_type): Likewise.
    	* parse.c (follow_types): Likewise.
    	* python/py-type.c (typy_reference, typy_lookup_type): Likewise.
    	* python/py-value.c (valpy_get_dynamic_type, valpy_getitem):
    	Likewise.
    	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
    	(gdbpy_invoke_xmethod): Likewise.
    	* stabsread.c: Provide extra argument to make_reference_type()
    	call.
    	* valops.c (value_ref, value_rtti_indirect_type): Use
    	lookup_lvalue_reference_type() instead of lookup_reference_type().
Comment 15 cvs-commit@gcc.gnu.org 2017-03-20 20:50:19 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit a65cfae5f8b268158c23a862e7a996d15bbcef0e
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:41 2017 -0700

    Add ability to return rvalue reference values from value_ref
    
    Parameterize value_ref() by the kind of reference type the value of which
    is requested. Change all callers to use the new API.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* ada-lang.c (ada_evaluate_subexp): Adhere to the new
    	value_ref() interface.
    	* c-valprint.c (c_value_print): Likewise.
    	* infcall.c (value_arg_coerce): Likewise.
    	* python/py-value.c (valpy_reference_value): Likewise.
    	* valops.c (value_cast, value_reinterpret_cast)
    	(value_dynamic_cast, typecmp): Likewise.
    	(value_ref): Parameterize by kind of return value reference type.
    	* value.h (value_ref): Add new parameter "refcode".
Comment 16 cvs-commit@gcc.gnu.org 2017-03-20 20:50:25 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit 53cc15f5fe1f5e2358994d4f60f1c2aa9115004d
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:43 2017 -0700

    Support rvalue reference type in parser
    
    This patch implements correct parsing of C++11 rvalue reference typenames.
    This is done in full similarity to the handling of regular references by adding
    a '&&' token handling in c-exp.y, defining an rvalue reference type piece, and
    implementing a follow type derivation in follow_types().
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* c-exp.y (ptr_operator): Handle the '&&' token in the typename.
    	* parse.c (insert_type): Change assert statement.
    	(follow_types): Handle rvalue reference types.
    	* parser-defs.h (enum type_pieces) <tp_rvalue_reference>: New
    	constant.
Comment 17 cvs-commit@gcc.gnu.org 2017-03-20 20:50:30 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit e4347c89f3a14b480fc88581d1363835f7b99b68
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:46 2017 -0700

    Implement demangling for rvalue reference type names
    
    This patch fixes demangling of names containing rvalue reference typenames by
    handling DEMANGLE_COMPONENT_RVALUE_REFERENCE demangle component.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* cp-name-parser.y (ptr_operator): Handle the '&&' token in
    	typename.
    	* cp-support.c (replace_typedefs): Handle
    	DEMANGLE_COMPONENT_RVALUE_REFERENCE.
    	* python/py-type.c (typy_lookup_type): Likewise.
Comment 18 cvs-commit@gcc.gnu.org 2017-03-20 20:50:35 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit e1cb3213476485a01aa11ecedfa186e386cb4bdb
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:48 2017 -0700

    Implement printing of rvalue reference types and values
    
    This patch provides the ability to print out names of rvalue reference types
    and values of those types. This is done in full similarity to regular
    references, and as with them, we don't print out "const" suffix because all
    rvalue references are const.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* c-typeprint.c (c_print_type, c_type_print_varspec_prefix)
    	(c_type_print_modifier, c_type_print_varspec_suffix)
    	(c_type_print_base): Support printing rvalue reference types.
    	* c-valprint.c (c_val_print, c_value_print): Support printing
    	rvalue reference values.
Comment 19 cvs-commit@gcc.gnu.org 2017-03-20 20:50:43 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit 4297a3f0029974c62628d69b6f3f9ef25f01ea7d
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:50 2017 -0700

    Support DW_TAG_rvalue_reference type
    
    Make gdb DWARF reader understand the DW_TAG_rvalue_reference type tag. Handling
    of this tag is done in the existing read_tag_reference_type() function, to
    which we add a new parameter representing the kind of reference type
    (lvalue vs rvalue).
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* dwarf2read.c (process_die, read_type_die_1): Handle the
    	DW_TAG_rvalue_reference_type DIE.
    	(read_tag_reference_type): Add new parameter "refcode".
Comment 20 cvs-commit@gcc.gnu.org 2017-03-20 20:50:47 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit 3fcf899da106890f3948093c2424f9dff67d6fe0
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:52 2017 -0700

    Support rvalue references in the gdb python module (includes doc/)
    
    This patch adds the ability to inspect rvalue reference types and values using
    the gdb python module. This is achieved by creating two wrappers for
    valpy_reference_value(), using the ReferenceExplorer class to handle the
    objects of rvalue reference types and placing necessary checks for a
    TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type
    code.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
    	table of constants.
    	* python/lib/gdb/command/explore.py: Support exploring values
    	of rvalue reference types.
    	* python/lib/gdb/types.py: Implement get_basic_type() for
    	rvalue reference types.
    	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
    	constant.
    	* python/py-value.c (valpy_getitem): Add an rvalue reference
    	check.
    	(valpy_reference_value): Add new parameter "refcode".
    	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
    	New wrappers for valpy_reference_value().
    	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
    	(gdbpy_invoke_xmethod): Likewise.
Comment 21 cvs-commit@gcc.gnu.org 2017-03-20 20:50:53 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit aa0061181ab00081e9907447561e589d6edee9f2
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:54 2017 -0700

    Convert lvalue reference type check to general reference type check
    
    In almost all contexts (except for overload resolution rules and expression
    semantics), lvalue and rvalue references are equivalent. That means that in all
    but these cases we can replace a TYPE_CODE_REF check to a TYPE_IS_REFERENCE
    check and, for switch statements, add a case label for a rvalue reference type
    next to a case label for an lvalue reference type. This patch does exactly
    that.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* aarch64-tdep.c (aarch64_type_align)
    	(aarch64_extract_return_value, aarch64_store_return_value): Change
    	lvalue reference type checks to general reference type checks.
    	* amd64-tdep.c (amd64_classify): Likewise.
    	* amd64-windows-tdep.c (amd64_windows_passed_by_integer_register):
    	Likewise.
    	* arm-tdep.c (arm_type_align, arm_extract_return_value)
    	(arm_store_return_value): Likewise.
    	* ax-gdb.c (gen_fetch, gen_cast): Likewise.
    	* c-typeprint.c (c_print_type): Likewise.
    	* c-varobj.c (adjust_value_for_child_access, c_value_of_variable)
    	(cplus_number_of_children, cplus_describe_child): Likewise.
    	* compile/compile-c-symbols.c (generate_vla_size): Likewise.
    	* completer.c (expression_completer): Likewise.
    	* cp-support.c (make_symbol_overload_list_adl_namespace):
    	Likewise.
    	* darwin-nat-info.c (info_mach_region_command): Likewise.
    	* dwarf2loc.c (entry_data_value_coerce_ref)
    	(value_of_dwarf_reg_entry): Likewise.
    	* eval.c (ptrmath_type_p, evaluate_subexp_standard)
    	(evaluate_subexp_for_address, evaluate_subexp_for_sizeof):
    	Likewise.
    	* findvar.c (extract_typed_address, store_typed_address):
    	Likewise.
    	* gdbtypes.c (rank_one_type): Likewise.
    	* hppa-tdep.c (hppa64_integral_or_pointer_p): Likewise.
    	* infcall.c (value_arg_coerce): Likewise.
    	* language.c (pointer_type): Likewise.
    	* m32c-tdep.c (m32c_reg_arg_type, m32c_m16c_address_to_pointer):
    	Likewise.
    	* m88k-tdep.c (m88k_integral_or_pointer_p): Likewise.
    	* mn10300-tdep.c (mn10300_type_align): Likewise.
    	* msp430-tdep.c (msp430_push_dummy_call): Likewise.
    	* ppc-sysv-tdep.c (do_ppc_sysv_return_value)
    	(ppc64_sysv_abi_push_param, ppc64_sysv_abi_return_value):
    	Likewise.
    	* printcmd.c (print_formatted, x_command): Likewise.
    	* python/py-type.c (typy_get_composite, typy_template_argument):
    	Likewise.
    	* python/py-value.c (valpy_referenced_value)
    	(valpy_get_dynamic_type, value_has_field): Likewise.
    	* s390-linux-tdep.c (s390_function_arg_integer): Likewise.
    	* sparc-tdep.c (sparc_integral_or_pointer_p): Likewise.
    	* sparc64-tdep.c (sparc64_integral_or_pointer_p): Likewise.
    	* spu-tdep.c (spu_scalar_value_p): Likewise.
    	* symtab.c (lookup_symbol_aux): Likewise.
    	* typeprint.c (whatis_exp, print_type_scalar): Likewise.
    	* valarith.c (binop_types_user_defined_p, unop_user_defined_p):
    	Likewise.
    	* valops.c (value_cast_pointers, value_cast)
    	(value_reinterpret_cast, value_dynamic_cast, value_addr, typecmp)
    	(value_struct_elt, value_struct_elt_bitpos)
    	(value_find_oload_method_list, find_overload_match)
    	(value_rtti_indirect_type): Likewise.
    	* valprint.c (val_print_scalar_type_p, generic_val_print):
    	Likewise.
    	* value.c (value_actual_type, value_as_address, unpack_long)
    	(pack_long, pack_unsigned_long, coerce_ref_if_computed)
    	(coerce_ref): Likewise.
    	* varobj.c (varobj_get_value_type): Likewise.
Comment 22 cvs-commit@gcc.gnu.org 2017-03-20 20:50:59 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit 15c0a2a9305648095f5586a02b5a5017e1643e99
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:57 2017 -0700

    Add rvalue references to overloading resolution
    
    This patch introduces changes to rank_one_type() dealing with ranking an rvalue
    reference type when selecting a best viable function from a set of candidate
    functions. The 4 new added rules for rvalue references are:
    
    1) An rvalue argument cannot be bound to a non-const lvalue reference parameter
    and an lvalue argument cannot be bound to an rvalue reference parameter.
    [C++11 13.3.3.1.4p3]
    
    2) If a conversion to one type of reference is an identity conversion, and a
    conversion to the second type of reference is a non-identity conversion, choose
    the first type. [C++11 13.3.3.2p3]
    
    3) An rvalue should be first tried to bind to an rvalue reference, and then to
    an lvalue reference. [C++11 13.3.3.2p3]
    
    4) An lvalue reference to a function gets higher priority than an rvalue
    reference to a function. [C++11 13.3.3.2p3]
    
    This patch is not exactly correct.  See c++/15372 for tracking overload
    resolution bugs.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* gdbtypes.c (rank_one_type): Implement overloading
    	resolution rules regarding rvalue references.
Comment 23 cvs-commit@gcc.gnu.org 2017-03-20 20:51:13 UTC
The master branch has been updated by Keith Seitz <kseitz@sourceware.org>:

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

commit c0f55cc689a57deb342b988b8f0ecb908f0a76e1
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Mon Mar 20 13:47:59 2017 -0700

    Add rvalue reference tests and docs
    
    This patch adds tests for the initial rvalue reference support patchset.  All
    of the new tests are practically mirrored regular references tests and, except
    for the demangler ones, are introduced in new files, which are set to be
    compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
    values, rvalue reference parameters in function overloading, demangling of
    function names containing rvalue reference parameters, casts to rvalue
    reference types, application of the sizeof operator to rvalue reference types
    and values, and support for rvalue references within the gdb python module.
    
    gdb/ChnageLog
    
    	PR gdb/14441
    	* NEWS: Mention support for rvalue references in GDB and python.
    	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
    	supports both lvalue and rvalue references.
    
    gdb/testsuite/ChangeLog
    
    	PR gdb/14441
    	* gdb.cp/demangle.exp: Add rvalue reference tests.
    	* gdb.cp/rvalue-ref-casts.cc: New file.
    	* gdb.cp/rvalue-ref-casts.exp: New file.
    	* gdb.cp/rvalue-ref-overload.cc: New file.
    	* gdb.cp/rvalue-ref-overload.exp: New file.
    	* gdb.cp/rvalue-ref-params.cc: New file.
    	* gdb.cp/rvalue-ref-params.exp: New file.
    	* gdb.cp/rvalue-ref-sizeof.cc: New file.
    	* gdb.cp/rvalue-ref-sizeof.exp: New file.
    	* gdb.cp/rvalue-ref-types.cc: New file.
    	* gdb.cp/rvalue-ref-types.exp: New file.
    	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
    	* gdb.python/py-rvalue-ref-value-cc.exp: New file.
Comment 24 Keith Seitz 2017-03-20 21:52:02 UTC
Pushed in time for 8.0 release.