Blame SOURCES/gdb-rhbz1420304-s390x-10of35.patch

e1d87d
commit 0567c9861e113a573cc905002a59cb1bc3d78450
e1d87d
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
e1d87d
Date:   Tue Jun 13 15:20:25 2017 +0200
e1d87d
e1d87d
    Add test for modifiable DWARF locations
e1d87d
    
e1d87d
    This adds a test for read/write access to variables with various types of
e1d87d
    DWARF locations.  It uses register- and memory locations and composite
e1d87d
    locations with register- and memory pieces.
e1d87d
    
e1d87d
    Since the new test calls gdb_test_no_output with commands that contain
e1d87d
    braces, it is necessary for string_to_regexp to quote braces as well.
e1d87d
    This was not done before.
e1d87d
    
e1d87d
    gdb/testsuite/ChangeLog:
e1d87d
    
e1d87d
            * gdb.dwarf2/var-access.c: New file.
e1d87d
            * gdb.dwarf2/var-access.exp: New test.
e1d87d
            * lib/gdb-utils.exp (string_to_regexp): Quote braces as well.
e1d87d
e1d87d
### a/gdb/testsuite/ChangeLog
e1d87d
### b/gdb/testsuite/ChangeLog
e1d87d
## -1,3 +1,9 @@
e1d87d
+2017-06-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
e1d87d
+
e1d87d
+	* gdb.dwarf2/var-access.c: New file.
e1d87d
+	* gdb.dwarf2/var-access.exp: New test.
e1d87d
+	* lib/gdb-utils.exp (string_to_regexp): Quote braces as well.
e1d87d
+
e1d87d
 2017-06-12  Tom Tromey  <tom@tromey.com>
e1d87d
 
e1d87d
 	* gdb.dwarf2/formdata16.exp: Add tests.
e1d87d
--- /dev/null
e1d87d
+++ b/gdb/testsuite/gdb.dwarf2/var-access.c
e1d87d
@@ -0,0 +1,25 @@
e1d87d
+/* This testcase is part of GDB, the GNU debugger.
e1d87d
+
e1d87d
+   Copyright 2017 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+   This program is free software; you can redistribute it and/or modify
e1d87d
+   it under the terms of the GNU General Public License as published by
e1d87d
+   the Free Software Foundation; either version 3 of the License, or
e1d87d
+   (at your option) any later version.
e1d87d
+
e1d87d
+   This program is distributed in the hope that it will be useful,
e1d87d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+   GNU General Public License for more details.
e1d87d
+
e1d87d
+   You should have received a copy of the GNU General Public License
e1d87d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
e1d87d
+
e1d87d
+char buf[] = {0, 1, 2, 3, 4, 5, 6, 7};
e1d87d
+
e1d87d
+int
e1d87d
+main (void)
e1d87d
+{
e1d87d
+  asm volatile ("main_label: .globl main_label");
e1d87d
+  return 0;
e1d87d
+}
e1d87d
--- /dev/null
e1d87d
+++ b/gdb/testsuite/gdb.dwarf2/var-access.exp
e1d87d
@@ -0,0 +1,197 @@
e1d87d
+# Copyright 2017 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+# This program is free software; you can redistribute it and/or modify
e1d87d
+# it under the terms of the GNU General Public License as published by
e1d87d
+# the Free Software Foundation; either version 3 of the License, or
e1d87d
+# (at your option) any later version.
e1d87d
+#
e1d87d
+# This program is distributed in the hope that it will be useful,
e1d87d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+# GNU General Public License for more details.
e1d87d
+#
e1d87d
+# You should have received a copy of the GNU General Public License
e1d87d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
e1d87d
+
e1d87d
+# Test reading/writing variables with non-trivial DWARF locations.  In
e1d87d
+# particular the test uses register- and memory locations as well as
e1d87d
+# composite locations with register- and memory pieces.
e1d87d
+
e1d87d
+load_lib dwarf.exp
e1d87d
+
e1d87d
+# This test can only be run on targets which support DWARF-2 and use gas.
e1d87d
+if {![dwarf2_support]} {
e1d87d
+    return 0
e1d87d
+}
e1d87d
+
e1d87d
+# Choose suitable integer registers for the test.
e1d87d
+
e1d87d
+set dwarf_regnum {0 1}
e1d87d
+
e1d87d
+if { [istarget "aarch64*-*-*"] } {
e1d87d
+    set regname {x0 x1}
e1d87d
+} elseif { [istarget "arm*-*-*"]
e1d87d
+	   || [istarget "s390*-*-*" ]
e1d87d
+	   || [istarget "powerpc*-*-*"]
e1d87d
+	   || [istarget "rs6000*-*-aix*"] } {
e1d87d
+    set regname {r0 r1}
e1d87d
+} elseif { [istarget "i?86-*-*"] } {
e1d87d
+    set regname {eax edx}
e1d87d
+} elseif { [istarget "x86_64-*-*"] } {
e1d87d
+    set regname {rax rdx}
e1d87d
+} else {
e1d87d
+    verbose "Skipping tests for accessing DWARF-described variables."
e1d87d
+    return
e1d87d
+}
e1d87d
+
e1d87d
+standard_testfile .c ${gdb_test_file_name}-dw.S
e1d87d
+
e1d87d
+# Make some DWARF for the test.
e1d87d
+
e1d87d
+set asm_file [standard_output_file $srcfile2]
e1d87d
+Dwarf::assemble $asm_file {
e1d87d
+    global srcdir subdir srcfile
e1d87d
+    global dwarf_regnum regname
e1d87d
+
e1d87d
+    set buf_var [gdb_target_symbol buf]
e1d87d
+
e1d87d
+    cu {} {
e1d87d
+	DW_TAG_compile_unit {
e1d87d
+		{DW_AT_name var-pieces-dw.c}
e1d87d
+		{DW_AT_comp_dir /tmp}
e1d87d
+	} {
e1d87d
+	    declare_labels char_type_label
e1d87d
+	    declare_labels int_type_label short_type_label
e1d87d
+	    declare_labels array_a8_label struct_s_label
e1d87d
+
e1d87d
+	    # char
e1d87d
+	    char_type_label: base_type {
e1d87d
+		{name "char"}
e1d87d
+		{encoding @DW_ATE_unsigned_char}
e1d87d
+		{byte_size 1 DW_FORM_sdata}
e1d87d
+	    }
e1d87d
+
e1d87d
+	    # int
e1d87d
+	    int_type_label: base_type {
e1d87d
+		{name "int"}
e1d87d
+		{encoding @DW_ATE_signed}
e1d87d
+		{byte_size 4 DW_FORM_sdata}
e1d87d
+	    }
e1d87d
+
e1d87d
+	    # char [8]
e1d87d
+	    array_a8_label: array_type {
e1d87d
+		{type :$char_type_label}
e1d87d
+	    } {
e1d87d
+		subrange_type {
e1d87d
+		    {type :$int_type_label}
e1d87d
+		    {upper_bound 7 DW_FORM_udata}
e1d87d
+		}
e1d87d
+	    }
e1d87d
+
e1d87d
+	    # struct s { char a, b, c, d; };
e1d87d
+	    struct_s_label: structure_type {
e1d87d
+		{name "s"}
e1d87d
+		{byte_size 4 DW_FORM_sdata}
e1d87d
+	    } {
e1d87d
+		member {
e1d87d
+		    {name "a"}
e1d87d
+		    {type :$char_type_label}
e1d87d
+		    {data_member_location 0 DW_FORM_udata}
e1d87d
+		}
e1d87d
+		member {
e1d87d
+		    {name "b"}
e1d87d
+		    {type :$char_type_label}
e1d87d
+		    {data_member_location 1 DW_FORM_udata}
e1d87d
+		}
e1d87d
+		member {
e1d87d
+		    {name "c"}
e1d87d
+		    {type :$char_type_label}
e1d87d
+		    {data_member_location 2 DW_FORM_udata}
e1d87d
+		}
e1d87d
+		member {
e1d87d
+		    {name "d"}
e1d87d
+		    {type :$char_type_label}
e1d87d
+		    {data_member_location 3 DW_FORM_udata}
e1d87d
+		}
e1d87d
+	    }
e1d87d
+
e1d87d
+	    DW_TAG_subprogram {
e1d87d
+		{MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }}
e1d87d
+		{DW_AT_external 1 flag}
e1d87d
+	    } {
e1d87d
+		# Simple memory location.
e1d87d
+		DW_TAG_variable {
e1d87d
+		    {name "a"}
e1d87d
+		    {type :$array_a8_label}
e1d87d
+		    {location {
e1d87d
+			addr $buf_var
e1d87d
+		    } SPECIAL_expr}
e1d87d
+		}
e1d87d
+		# Memory pieces: two bytes from &buf[2], and two bytes
e1d87d
+		# from &buf[0].
e1d87d
+		DW_TAG_variable {
e1d87d
+		    {name "s1"}
e1d87d
+		    {type :$struct_s_label}
e1d87d
+		    {location {
e1d87d
+			addr $buf_var
e1d87d
+			plus_uconst 2
e1d87d
+			piece 2
e1d87d
+			addr $buf_var
e1d87d
+			piece 2
e1d87d
+		    } SPECIAL_expr}
e1d87d
+		}
e1d87d
+		# Register- and memory pieces: one byte each from r0,
e1d87d
+		# &buf[4], r1, and &buf[5].
e1d87d
+		DW_TAG_variable {
e1d87d
+		    {name "s2"}
e1d87d
+		    {type :$struct_s_label}
e1d87d
+		    {location {
e1d87d
+			regx [lindex $dwarf_regnum 0]
e1d87d
+			piece 1
e1d87d
+			addr "$buf_var + 4"
e1d87d
+			piece 1
e1d87d
+			regx [lindex $dwarf_regnum 1]
e1d87d
+			piece 1
e1d87d
+			addr "$buf_var + 5"
e1d87d
+			piece 1
e1d87d
+		    } SPECIAL_expr}
e1d87d
+		}
e1d87d
+	    }
e1d87d
+	}
e1d87d
+    }
e1d87d
+}
e1d87d
+
e1d87d
+if { [prepare_for_testing ${testfile}.exp ${testfile} \
e1d87d
+	  [list $srcfile $asm_file] {nodebug}] } {
e1d87d
+    return -1
e1d87d
+}
e1d87d
+
e1d87d
+if ![runto_main] {
e1d87d
+    return -1
e1d87d
+}
e1d87d
+
e1d87d
+# Byte-aligned memory pieces.
e1d87d
+gdb_test "print/d s1" " = \\{a = 2, b = 3, c = 0, d = 1\\}" \
e1d87d
+    "s1 == re-ordered buf"
e1d87d
+gdb_test_no_output "set var s1.a = 63"
e1d87d
+gdb_test "print/d s1" " = \\{a = 63, b = 3, c = 0, d = 1\\}" \
e1d87d
+    "verify s1.a"
e1d87d
+gdb_test "print/d a" " = \\{0, 1, 63, 3, 4, 5, 6, 7\\}" \
e1d87d
+    "verify s1.a through a"
e1d87d
+
e1d87d
+# Byte-aligned register- and memory pieces.
e1d87d
+gdb_test_no_output "set var \$[lindex $regname 0] = 81" \
e1d87d
+    "init reg for s2.a"
e1d87d
+gdb_test_no_output "set var \$[lindex $regname 1] = 28" \
e1d87d
+    "init reg for s2.c"
e1d87d
+gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 28, d = 5\\}" \
e1d87d
+    "initialized s2 from mem and regs"
e1d87d
+gdb_test_no_output "set var s2.c += s2.a + s2.b - s2.d"
e1d87d
+gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 108, d = 5\\}" \
e1d87d
+    "verify s2.c"
e1d87d
+gdb_test "print/d \$[lindex $regname 1]" " = 108" \
e1d87d
+    "verify s2.c through reg"
e1d87d
+gdb_test_no_output "set var s2 = {191, 73, 231, 123}" \
e1d87d
+    "re-initialize s2"
e1d87d
+gdb_test "print/d s2"  " = \\{a = 191, b = 73, c = 231, d = 123\\}" \
e1d87d
+    "verify re-initialized s2"
e1d87d
--- a/gdb/testsuite/lib/gdb-utils.exp
e1d87d
+++ b/gdb/testsuite/lib/gdb-utils.exp
e1d87d
@@ -34,6 +34,6 @@ proc gdb_init_commands {} {
e1d87d
 
e1d87d
 proc string_to_regexp {str} {
e1d87d
     set result $str
e1d87d
-    regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
e1d87d
+    regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
e1d87d
     return $result
e1d87d
 }