From patchwork Tue May 9 17:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 20347 Received: (qmail 117931 invoked by alias); 9 May 2017 17:54:32 -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 117916 invoked by uid 89); 9 May 2017 17:54:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= 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; Tue, 09 May 2017 17:54:30 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v49Hrfnd001727 for ; Tue, 9 May 2017 13:54:31 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ab91dk91u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 May 2017 13:54:31 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 May 2017 18:54:29 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 May 2017 18:54:28 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v49HsS0p40173616 for ; Tue, 9 May 2017 17:54:28 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C80285204C for ; Tue, 9 May 2017 17:51:51 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.109]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id B27F65204F for ; Tue, 9 May 2017 17:51:51 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 11/19] Add DWARF piece test cases for bit-field access Date: Tue, 9 May 2017 19:46:07 +0200 In-Reply-To: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050917-0040-0000-0000-00000384815A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050917-0041-0000-0000-0000254C9C77 Message-Id: <1494352015-10465-12-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-09_14:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705090098 X-IsSubscribed: yes This verifies some of the previous fixes to the logic in write_pieced_value when accessing bit-fields. gdb/testsuite/ChangeLog: * gdb.dwarf2/var-access.exp: Add tests for accessing bit-fields located in one or more DWARF pieces. --- gdb/testsuite/gdb.dwarf2/var-access.exp | 81 ++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.dwarf2/var-access.exp b/gdb/testsuite/gdb.dwarf2/var-access.exp index bd92a44..3ba2c08 100644 --- a/gdb/testsuite/gdb.dwarf2/var-access.exp +++ b/gdb/testsuite/gdb.dwarf2/var-access.exp @@ -62,7 +62,8 @@ Dwarf::assemble $asm_file { } { declare_labels char_type_label declare_labels int_type_label short_type_label - declare_labels array_a8_label struct_s_label + declare_labels array_a8_label struct_s_label struct_t_label + declare_labels struct_st_label # char char_type_label: base_type { @@ -115,6 +116,51 @@ Dwarf::assemble $asm_file { } } + # struct t { int u, x:9, y:13, z:10; }; + struct_t_label: structure_type { + {name "t"} + {byte_size 8 DW_FORM_sdata} + } { + member { + {name "u"} + {type :$int_type_label} + } + member { + {name "x"} + {type :$int_type_label} + {data_member_location 4 DW_FORM_udata} + {bit_size 9 DW_FORM_udata} + } + member { + {name "y"} + {type :$int_type_label} + {data_bit_offset 41 DW_FORM_udata} + {bit_size 13 DW_FORM_udata} + } + member { + {name "z"} + {type :$int_type_label} + {data_bit_offset 54 DW_FORM_udata} + {bit_size 10 DW_FORM_udata} + } + } + + # struct st { struct s s; struct t t; }; + struct_st_label: structure_type { + {name "st"} + {byte_size 12 DW_FORM_udata} + } { + member { + {name "s"} + {type :$struct_s_label} + } + member { + {name "t"} + {type :$struct_t_label} + {data_member_location 4 DW_FORM_udata} + } + } + DW_TAG_subprogram { {MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }} {DW_AT_external 1 flag} @@ -156,6 +202,19 @@ Dwarf::assemble $asm_file { piece 1 } SPECIAL_expr} } + # Memory pieces for bitfield access: 8 bytes optimized + # out, 3 bytes from &buf[3], and 1 byte from &buf[1]. + DW_TAG_variable { + {name "st1"} + {type :$struct_st_label} + {location { + piece 8 + addr "$buf_var + 3" + piece 3 + addr "$buf_var + 1" + piece 1 + } SPECIAL_expr} + } } } } @@ -170,6 +229,9 @@ if ![runto_main] { return -1 } +# Determine byte order. +set endian [get_endianness] + # Byte-aligned memory pieces. gdb_test "print/d s1" " = \\{a = 2, b = 3, c = 0, d = 1\\}" \ "s1 == re-ordered buf" @@ -200,3 +262,20 @@ gdb_test_no_output "set var s2 = {191, 73, 231, 123}" \ "re-initialize s2" gdb_test "print/d s2" " = \\{a = 191, b = 73, c = 231, d = 123\\}" \ "verify re-initialized s2" + +# Unaligned bitfield access through byte-aligned pieces. +gdb_test_no_output "set var a = { 0 }" +gdb_test_no_output "set var st1.t.x = -7" +gdb_test_no_output "set var st1.t.z = 340" +gdb_test_no_output "set var st1.t.y = 1234" +gdb_test "print st1.t" " = \\{u = , x = -7, y = 1234, z = 340\\}" \ + "verify st1.t" +switch $endian { + little {set val "0x55, 0x0, 0xf9, 0xa5, 0x9"} + big {set val "0x54, 0x0, 0xfc, 0x93, 0x49"} +} +# | -- | z:2-9 | -- | x:0-7 | x:8 y:0-6 | y:7-12 z:0-1 | -- | -- | +# \_______________________________________________/ +# val +gdb_test "print/x a" " = \\{0x0, ${val}, 0x0, 0x0\\}" \ + "verify st1 through a"