From patchwork Mon May 29 16:25:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 20631 Received: (qmail 43212 invoked by alias); 29 May 2017 16:25:54 -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 43196 invoked by uid 89); 29 May 2017 16:25:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Reverse, H*Ad:U*tom, H*RU:cmgw4, Hx-spam-relays-external:cmgw4 X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 May 2017 16:25:51 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id AC963175C29 for ; Mon, 29 May 2017 10:25:53 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id SGRq1v00f2f2jeq01GRt8E; Mon, 29 May 2017 10:25:53 -0600 X-Authority-Analysis: v=2.2 cv=VKStp5HX c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=tJ8p9aeEuA8A:10 a=NEAV23lmAAAA:8 a=zstS-IiYAAAA:8 a=mDV3o1hIAAAA:8 a=2CSb4kNGYJzt8IQZWXQA:9 a=Gn9xmH2Enzy61V7B:21 a=ZufoHR4Aehxv2n5t:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=_FVE-zBwftR9WsbkzFJk:22 Received: from 174-29-43-217.hlrn.qwest.net ([174.29.43.217]:58850 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dFNUM-0003dx-FH; Mon, 29 May 2017 10:25:50 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full Date: Mon, 29 May 2017 10:25:44 -0600 Message-Id: <20170529162544.8652-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dFNUM-0003dx-FH X-Source-Sender: 174-29-43-217.hlrn.qwest.net (bapiya.Home) [174.29.43.217]:58850 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This Rust bug report: https://github.com/rust-lang/rust/issues/41970 noted an error from gdb. What is happening here (for me, the original report had a different error) is that a pieced DWARF expression is not writing to every byte in the resulting value. GDB errors in this case. However, it seems to me that it is always valid to write fewer bytes; the issue comes from writing too many -- that is, the test is reversed. The test was also checking the sub-object, but this also seems incorrect, as it's expected for the expression to write the entirety of the enclosing object. So, this patch reverses the test and applies it to the outer type, not the subobject type. Regtested on the buildbot. ChangeLog 2017-05-29 Tom Tromey * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size check and apply to outer type. testsuite/ChangeLog 2017-05-29 Tom Tromey * gdb.dwarf2/shortpiece.exp: New file. --- gdb/ChangeLog | 5 ++ gdb/dwarf2loc.c | 4 +- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.dwarf2/shortpiece.exp | 84 +++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/shortpiece.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c0fcb22..24d261f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-05-29 Tom Tromey + + * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size + check and apply to outer type. + 2017-05-21 Tom Tromey PR rust/21466: diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 127167d..9ffe197 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2407,7 +2407,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, for (i = 0; i < ctx.num_pieces; ++i) bit_size += ctx.pieces[i].size; - if (8 * (subobj_byte_offset + TYPE_LENGTH (subobj_type)) > bit_size) + /* Complain if the expression is larger than the size of the + outer type. */ + if (bit_size > 8 * TYPE_LENGTH (type)) invalid_synthetic_pointer (); c = allocate_piece_closure (per_cu, ctx.num_pieces, ctx.pieces, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c16f201..d31679a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-05-29 Tom Tromey + + * gdb.dwarf2/shortpiece.exp: New file. + 2017-05-21 Tom Tromey PR rust/21466: diff --git a/gdb/testsuite/gdb.dwarf2/shortpiece.exp b/gdb/testsuite/gdb.dwarf2/shortpiece.exp new file mode 100644 index 0000000..588f6a1 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/shortpiece.exp @@ -0,0 +1,84 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c shortpiece-dw.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global pair + + cu { addr_size 4 } { + compile_unit {} { + declare_labels int_label ushort_label struct_label + + int_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_udata} + {DW_AT_encoding @DW_ATE_unsigned} + {DW_AT_name "myint"} + } + ushort_label: DW_TAG_base_type { + {DW_AT_byte_size 2 DW_FORM_udata} + {DW_AT_encoding @DW_ATE_unsigned} + {DW_AT_name "myushort"} + } + + struct_label: DW_TAG_structure_type { + {DW_AT_name "S"} + {DW_AT_byte_size 8 DW_FORM_udata} + } { + DW_TAG_member { + {DW_AT_name "a"} + {DW_AT_type :${int_label}} + {DW_AT_data_member_location 0 DW_FORM_udata} + } + + DW_TAG_member { + {DW_AT_name "b"} + {DW_AT_type :${ushort_label}} + {DW_AT_data_member_location 4 DW_FORM_udata} + } + } + + DW_TAG_variable { + {DW_AT_name "s1"} + {DW_AT_type :${struct_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location { + DW_OP_constu 1 + DW_OP_stack_value + DW_OP_piece 4 + DW_OP_constu 0 + DW_OP_stack_value + DW_OP_piece 2 + } SPECIAL_expr} + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test "p s1" " = {a = 1, b = 0}"