From patchwork Fri Apr 7 17:38:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 19895 Received: (qmail 21256 invoked by alias); 7 Apr 2017 17:39:44 -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 19871 invoked by uid 89); 7 Apr 2017 17:39:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 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=Quote, 231 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; Fri, 07 Apr 2017 17:39:41 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v37Hceae045003 for ; Fri, 7 Apr 2017 13:39:41 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 29pedttbuy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 07 Apr 2017 13:39:41 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Apr 2017 18:39:39 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 7 Apr 2017 18:39:38 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v37Hdc3p14352678 for ; Fri, 7 Apr 2017 17:39:38 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 916DB11C04A for ; Fri, 7 Apr 2017 18:38:59 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C40211C052 for ; Fri, 7 Apr 2017 18:38:59 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.162]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 7 Apr 2017 18:38:59 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH 1/9] Add test for modifiable DWARF locations Date: Fri, 7 Apr 2017 19:38:08 +0200 In-Reply-To: <1491586736-21296-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1491586736-21296-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17040717-0016-0000-0000-00000475A86E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040717-0017-0000-0000-00002728A2FC Message-Id: <1491586736-21296-2-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-07_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704070144 X-IsSubscribed: yes This adds a test for read/write access to variables with various types of DWARF locations. It uses register- and memory locations and composite locations with register- and memory pieces. Since the new test calls gdb_test_no_output with commands that contain braces, it is necessary for string_to_regexp to quote braces as well. This was not done before. gdb/testsuite/ChangeLog: * gdb.dwarf2/var-access.c: New file. * gdb.dwarf2/var-access.exp: New test. * lib/gdb-utils.exp (string_to_regexp): Quote braces as well. --- gdb/testsuite/gdb.dwarf2/var-access.c | 25 +++++ gdb/testsuite/gdb.dwarf2/var-access.exp | 193 ++++++++++++++++++++++++++++++++ gdb/testsuite/lib/gdb-utils.exp | 2 +- 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/var-access.c create mode 100644 gdb/testsuite/gdb.dwarf2/var-access.exp diff --git a/gdb/testsuite/gdb.dwarf2/var-access.c b/gdb/testsuite/gdb.dwarf2/var-access.c new file mode 100644 index 0000000..108be82 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/var-access.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +char buf[] = {0, 1, 2, 3, 4, 5, 6, 7}; + +int +main (void) +{ + asm volatile ("main_label: .globl main_label"); + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/var-access.exp b/gdb/testsuite/gdb.dwarf2/var-access.exp new file mode 100644 index 0000000..ee93b93 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/var-access.exp @@ -0,0 +1,193 @@ +# 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 . + +# Test reading/writing variables with non-trivial DWARF locations. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +# Choose suitable integer registers for the test. + +set dwarf_regnum {0 1} + +if { [istarget "aarch64*-*-*"] } { + set regname {x0 x1} +} elseif { [istarget "arm*-*-*"] + || [istarget "s390*-*-*" ] + || [istarget "powerpc*-*-*"] + || [istarget "rs6000*-*-aix*"] } { + set regname {r0 r1} +} elseif { [istarget "i?86-*-*"] } { + set regname {eax edx} +} elseif { [istarget "x86_64-*-*"] } { + set regname {rax rdx} +} else { + verbose "Skipping tests for accessing DWARF-described variables." + return +} + +standard_testfile .c ${gdb_test_file_name}-dw.S + +# Make some DWARF for the test. + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + global dwarf_regnum regname + + set main_func \ + [function_range main [list ${srcdir}/${subdir}/$srcfile]] + set buf_var [gdb_target_symbol buf] + + cu {} { + DW_TAG_compile_unit { + {DW_AT_name var-pieces-dw.c} + {DW_AT_comp_dir /tmp} + } { + declare_labels char_type_label + declare_labels int_type_label short_type_label + declare_labels array_a8_label struct_s_label + + char_type_label: base_type { + {name "char"} + {encoding @DW_ATE_unsigned_char} + {byte_size 1 DW_FORM_sdata} + } + + int_type_label: base_type { + {name "int"} + {encoding @DW_ATE_signed} + {byte_size 4 DW_FORM_sdata} + } + + array_a8_label: array_type { + {type :$char_type_label} + } { + subrange_type { + {type :$int_type_label} + {upper_bound 7 DW_FORM_udata} + } + } + + struct_s_label: structure_type { + {name "s"} + {byte_size 4 DW_FORM_sdata} + } { + member { + {name "a"} + {type :$char_type_label} + {data_member_location 0 DW_FORM_udata} + } + member { + {name "b"} + {type :$char_type_label} + {data_member_location 1 DW_FORM_udata} + } + member { + {name "c"} + {type :$char_type_label} + {data_member_location 2 DW_FORM_udata} + } + member { + {name "d"} + {type :$char_type_label} + {data_member_location 3 DW_FORM_udata} + } + } + + DW_TAG_subprogram { + {name "main"} + {DW_AT_external 1 flag} + {low_pc [lindex $main_func 0] DW_FORM_addr} + {high_pc [lindex $main_func 1] DW_FORM_udata} + } { + # Simple memory location. + DW_TAG_variable { + {name "a"} + {type :$array_a8_label} + {location { + addr $buf_var + } SPECIAL_expr} + } + # Memory pieces. + DW_TAG_variable { + {name "s1"} + {type :$struct_s_label} + {location { + addr $buf_var + plus_uconst 2 + piece 2 + addr $buf_var + piece 2 + } SPECIAL_expr} + } + # Register- and memory pieces. + DW_TAG_variable { + {name "s2"} + {type :$struct_s_label} + {location { + regx [lindex $dwarf_regnum 0] + piece 1 + addr "$buf_var + 4" + piece 1 + regx [lindex $dwarf_regnum 1] + piece 1 + addr "$buf_var + 5" + piece 1 + } SPECIAL_expr} + } + } + } + } +} + +if { [prepare_for_testing ${testfile}.exp ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Byte-aligned memory pieces. +gdb_test "print/d s1" " = \\{a = 2, b = 3, c = 0, d = 1\\}" \ + "s1 == re-ordered buf" +gdb_test_no_output "set var s1.a = 63" +gdb_test "print/d s1" " = \\{a = 63, b = 3, c = 0, d = 1\\}" \ + "verify s1.a" +gdb_test "print/d a" " = \\{0, 1, 63, 3, 4, 5, 6, 7\\}" \ + "verify s1.a through a" + +# Byte-aligned register- and memory pieces. +gdb_test_no_output "set var \$[lindex $regname 0] = 81" \ + "init reg for s2.a" +gdb_test_no_output "set var \$[lindex $regname 1] = 28" \ + "init reg for s2.c" +gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 28, d = 5\\}" \ + "initialized s2 from mem and regs" +gdb_test_no_output "set var s2.c += s2.a + s2.b - s2.d" +gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 108, d = 5\\}" \ + "verify s2.c" +gdb_test "print/d \$[lindex $regname 1]" " = 108" \ + "verify s2.c through reg" +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" diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp index ff1b24a..37abb14 100644 --- a/gdb/testsuite/lib/gdb-utils.exp +++ b/gdb/testsuite/lib/gdb-utils.exp @@ -34,6 +34,6 @@ proc gdb_init_commands {} { proc string_to_regexp {str} { set result $str - regsub -all {[]*+.|()^$\[\\]} $str {\\&} result + regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result return $result }