From patchwork Mon Nov 14 15:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 17456 Received: (qmail 58677 invoked by alias); 14 Nov 2016 15:04:04 -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 58663 invoked by uid 89); 14 Nov 2016 15:04:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=2.3.0, runto_main, $srcfile, testfile X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Nov 2016 15:03:53 +0000 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAEExN1P115584 for ; Mon, 14 Nov 2016 10:03:52 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 26pqqerb89-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 14 Nov 2016 10:03:52 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Nov 2016 15:03:50 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 Nov 2016 15:03:48 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id CDA992190023 for ; Mon, 14 Nov 2016 15:03:01 +0000 (GMT) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAEF3mfs30670866 for ; Mon, 14 Nov 2016 15:03:48 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uAEF3lsJ016219 for ; Mon, 14 Nov 2016 08:03:48 -0700 Received: from oc1027705133.ibm.com (dyn-9-152-212-182.boeblingen.de.ibm.com [9.152.212.182]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uAEF37di016044 for ; Mon, 14 Nov 2016 08:03:47 -0700 From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH 1/3] Fix PR12616 - gdb does not implement DW_AT_data_bit_offset Date: Mon, 14 Nov 2016 16:02:24 +0100 In-Reply-To: <1479135786-31150-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1479135786-31150-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111415-0020-0000-0000-0000022E0261 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111415-0021-0000-0000-00001E4BE7FD Message-Id: <1479135786-31150-2-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-14_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611140306 X-IsSubscribed: yes The DW_AT_data_bit_offset attribute was introduced by DWARF V4 and allows specifying the offset of a data member within its containing entity. But although the new attribute was intended to replace DW_AT_bit_offset for this purpose, GDB ignores it, and thus GCC still emits DW_AT_bit_offset instead. See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71669. This change fixes GDB's lack of support for DW_AT_data_bit_offset and adds an appropriate test case. gdb/ChangeLog: PR gdb/12616 * dwarf2read.c (dwarf2_add_field): Handle the DWARF V4 attribute DW_AT_data_bit_offset. gdb/testsuite/ChangeLog: PR gdb/12616 * gdb.dwarf2/nonvar-access.exp: New testcase. Check that GDB respects the DW_AT_data_bit_offset attribute. --- gdb/dwarf2read.c | 4 ++ gdb/testsuite/gdb.dwarf2/nonvar-access.exp | 103 +++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/nonvar-access.exp diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 1ad6b00..558159a 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12584,6 +12584,10 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, - bit_offset - FIELD_BITSIZE (*fp))); } } + attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); + if (attr != NULL) + SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp) + + dwarf2_get_attr_constant_value (attr, 0))); /* Get name of field. */ fieldname = dwarf2_name (die, cu); diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp new file mode 100644 index 0000000..21532a6 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp @@ -0,0 +1,103 @@ +# Copyright 2016 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 . + +# Test accessing "non-variable" variables, i.e., variables which are +# optimized to a constant DWARF location expression and/or +# partially/fully optimized out. + +load_lib dwarf.exp + +if {![dwarf2_support]} { return 0 } + +standard_testfile main.c nonvar-access-dw.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] + +Dwarf::assemble $asm_file { + cu {} { + compile_unit { + {DW_AT_name main.c} + } { + declare_labels int_type_label short_type_label + declare_labels struct_s_label + + int_type_label: base_type { + {name "int"} + {encoding @DW_ATE_signed} + {byte_size 4 DW_FORM_sdata} + } + + struct_s_label: structure_type { + {name s} + {byte_size 4 DW_FORM_sdata} + } { + member { + {name a} + {type :$int_type_label} + {data_member_location 0 DW_FORM_udata} + {bit_size 8 DW_FORM_udata} + } + member { + {name b} + {type :$int_type_label} + {data_bit_offset 8 DW_FORM_udata} + {bit_size 24 DW_FORM_udata} + } + } + + DW_TAG_subprogram { + {name main} + {DW_AT_external 1 flag} + {low_pc [gdb_target_symbol main] DW_FORM_addr} + {high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr} + } { + DW_TAG_variable { + {name undef_int} + {type :$int_type_label} + } + DW_TAG_variable { + {name undef_s} + {type :$struct_s_label} + } + DW_TAG_variable { + {name def_s} + {type :$struct_s_label} + {location { + const1u 0 + stack_value + bit_piece 8 0 + const1s -1 + stack_value + bit_piece 24 0 + } SPECIAL_expr} + } + } + } + } +} + +if { [prepare_for_testing ${testfile}.exp ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test "print def_s" " = \\{a = 0, b = -1\\}" +gdb_test "print undef_int" " = " +gdb_test "print undef_s.a" " = "