tbaeder / rpms / gdb

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