From patchwork Tue Jul 22 20:21:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 2147 Received: (qmail 11143 invoked by alias); 22 Jul 2014 20:21:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 11106 invoked by uid 89); 22 Jul 2014 20:21:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 22 Jul 2014 20:21:31 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6MKLScY027557 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 22 Jul 2014 16:21:29 -0400 Received: from host2.jankratochvil.net (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6MKLO1p017358 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Tue, 22 Jul 2014 16:21:26 -0400 Date: Tue, 22 Jul 2014 22:21:24 +0200 From: Jan Kratochvil To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: [commit] Remove setting value address for reference entry value target data value Message-ID: <20140722202124.GB14408@host2.jankratochvil.net> References: <20140709103312.GA27884@host2.jankratochvil.net> <53BD2CE0.1000308@redhat.com> <20140709153121.GA7989@host2.jankratochvil.net> <53C41D5D.9030109@redhat.com> <20140716215838.GA29855@host2.jankratochvil.net> <53C7C02A.2090107@redhat.com> <20140720150727.GA18488@host2.jankratochvil.net> <53CEB93A.4020709@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <53CEB93A.4020709@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Tue, 22 Jul 2014 21:19:22 +0200, Pedro Alves wrote: > Thanks Jan. Indeed I'd much prefer removing it. > It's fine with me to still leave it in 7.8 in case we missed > something. Removed on trunk. Jan commit 45326f6fbe28ef5bac22dac447a4181c44cb945a Author: Jan Kratochvil Date: Tue Jul 22 22:15:27 2014 +0200 Remove setting value address for reference entry value target data value. I cannot reproduce any wrong case having the code removed. I just do not find it correct to have it disabled. But at the same time I do like much / I do not find correct the code myself. It is a bit problematic to have struct value describing a memory content which is no longer present there. What happens there: ------------------------------------------------------------------------------ volatile int vv; static __attribute__((noinline)) int bar (int &ref) { ref = 20; vv++; /* break-here */ return ref; } int main (void) { int var = 10; return bar (var); } ------------------------------------------------------------------------------ <4>: Abbrev Number: 13 (DW_TAG_GNU_call_site_parameter) DW_AT_location : 1 byte block: 55 (DW_OP_reg5 (rdi)) DW_AT_GNU_call_site_value: 2 byte block: 91 74 (DW_OP_fbreg: -12) DW_AT_GNU_call_site_data_value: 1 byte block: 3a (DW_OP_lit10) ------------------------------------------------------------------------------ gdb -ex 'b value_addr' -ex r --args ../gdb ./1 -ex 'watch vv' -ex r -ex 'p &ref@entry' -> 6 return ref; bar (ref=@0x7fffffffd944: 20, ref@entry=@0x7fffffffd944: 10) at 1.C:25 ------------------------------------------------------------------------------ At /* break-here */ struct value variable 'ref' is TYPE_CODE_REF. With FSF GDB HEAD: (gdb) x/gx arg1.contents 0x6004000a4ad0: 0x00007fffffffd944 (gdb) p ((struct value *)arg1.location.computed.closure).lval $1 = lval_memory (gdb) p/x ((struct value *)arg1.location.computed.closure).location.address $3 = 0x7fffffffd944 With your #if0-ed code: (gdb) x/gx arg1.contents 0x6004000a4ad0: 0x00007fffffffd944 (gdb) p ((struct value *)arg1.location.computed.closure).lval $8 = not_lval (gdb) p/x ((struct value *)arg1.location.computed.closure).location.address $9 = 0x0 I do not see how to access ((struct value *)arg1.location.computed.closure).location.address from GDB CLI. Trying (gdb) p &ref@entry will invoke value_addr()'s: if (TYPE_CODE (type) == TYPE_CODE_REF) /* Copy the value, but change the type from (T&) to (T*). We keep the same location information, which is efficient, and allows &(&X) to get the location containing the reference. */ and therefore the address gets fetched already from arg1.contents and not from ((struct value *)arg1.location.computed.closure).location.address . And for any other type than TYPE_CODE_REF this code you removed does not get executed at all. This DW_AT_GNU_call_site_data_value DWARF was meant primarily for Fortran but with -O0 entry values do not get produced and with -Og and higher Fortran always optimizes out the passing by reference. If you do not like the removed code there I am OK with removing it as I do not know how to make it's use reproducible for user anyway. In the worst case - if there really is some way how to exploit it - one should just get Attempt to take address of value not located in memory. instead of some wrong value and it may be easy to fix then. gdb/ 2014-07-22 Jan Kratochvil * dwarf2loc.c (value_of_dwarf_reg_entry): Remove setting value address for reference entry value target data value. Message-ID: <20140720150727.GA18488@host2.jankratochvil.net> diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 73a13d3..687e2fe 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2014-07-22 Jan Kratochvil + * dwarf2loc.c (value_of_dwarf_reg_entry): Remove setting value address + for reference entry value target data value. + +2014-07-22 Jan Kratochvil + * stack.c (read_frame_arg): Verify value_optimized_out before calling value_available_contents_eq. diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index fcab9b9..b1c7ee1 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1312,7 +1312,6 @@ value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame, struct value *outer_val, *target_val, *val; struct call_site_parameter *parameter; struct dwarf2_per_cu_data *caller_per_cu; - CORE_ADDR addr; parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u, &caller_per_cu); @@ -1335,14 +1334,6 @@ value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame, target_type, caller_frame, caller_per_cu); - /* value_as_address dereferences TYPE_CODE_REF. */ - addr = extract_typed_address (value_contents (outer_val), checked_type); - - /* The target entry value has artificial address of the entry value - reference. */ - VALUE_LVAL (target_val) = lval_memory; - set_value_address (target_val, addr); - release_value (target_val); val = allocate_computed_value (type, &entry_data_value_funcs, target_val /* closure */);