Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 01/19] Add test for modifiable DWARF locations
Date: Tue, 09 May 2017 17:47:00 -0000	[thread overview]
Message-ID: <1494352015-10465-2-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com>

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 | 197 ++++++++++++++++++++++++++++++++
 gdb/testsuite/lib/gdb-utils.exp         |   2 +-
 3 files changed, 223 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 <http://www.gnu.org/licenses/>.  */
+
+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..a52327d
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/var-access.exp
@@ -0,0 +1,197 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+# Test reading/writing variables with non-trivial DWARF locations.  In
+# particular the test uses register- and memory locations as well as
+# composite locations with register- and memory pieces.
+
+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 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
+	    char_type_label: base_type {
+		{name "char"}
+		{encoding @DW_ATE_unsigned_char}
+		{byte_size 1 DW_FORM_sdata}
+	    }
+
+	    # int
+	    int_type_label: base_type {
+		{name "int"}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+
+	    # char [8]
+	    array_a8_label: array_type {
+		{type :$char_type_label}
+	    } {
+		subrange_type {
+		    {type :$int_type_label}
+		    {upper_bound 7 DW_FORM_udata}
+		}
+	    }
+
+	    # struct s { char a, b, c, d; };
+	    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 {
+		{MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }}
+		{DW_AT_external 1 flag}
+	    } {
+		# Simple memory location.
+		DW_TAG_variable {
+		    {name "a"}
+		    {type :$array_a8_label}
+		    {location {
+			addr $buf_var
+		    } SPECIAL_expr}
+		}
+		# Memory pieces: two bytes from &buf[2], and two bytes
+		# from &buf[0].
+		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: one byte each from r0,
+		# &buf[4], r1, and &buf[5].
+		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
 }
-- 
2.5.0


  reply	other threads:[~2017-05-09 17:47 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09 17:47 [PATCH v2 00/19] Various DWARF piece fixes Andreas Arnez
2017-05-09 17:47 ` Andreas Arnez [this message]
2017-05-11 21:22   ` [PATCH v2 01/19] Add test for modifiable DWARF locations Yao Qi
2017-05-09 17:48 ` [PATCH v2 02/19] write_pieced_value: Fix size capping logic Andreas Arnez
2017-05-11 21:26   ` Yao Qi
2017-05-09 17:49 ` [PATCH v2 04/19] Remove addr_size field from struct piece_closure Andreas Arnez
2017-05-11 21:29   ` Yao Qi
2017-05-09 17:49 ` [PATCH v2 03/19] PR gdb/21226: Take DWARF stack value pieces from LSB end Andreas Arnez
2017-05-15  9:32   ` Yao Qi
2017-05-15 16:35     ` Andreas Arnez
2017-05-16  7:53       ` Yao Qi
     [not found]         ` <m34lwlf2cq.fsf@oc1027705133.ibm.com>
2017-05-16 13:50           ` Yao Qi
2017-05-09 17:50 ` [PATCH v2 05/19] gdb/testsuite: Add "get_endianness" convenience proc Andreas Arnez
2017-05-11 21:32   ` Yao Qi
2017-05-09 17:51 ` [PATCH v2 07/19] write_pieced_value: Fix copy/paste error in size calculation Andreas Arnez
2017-05-16  8:29   ` Yao Qi
2017-05-09 17:51 ` [PATCH v2 06/19] read/write_pieced_value: Respect value parent's offset Andreas Arnez
2017-05-16  8:18   ` Yao Qi
2017-05-09 17:52 ` [PATCH v2 08/19] write_pieced_value: Include transfer size in byte-wise check Andreas Arnez
2017-05-16  8:32   ` Yao Qi
2017-05-16 13:45     ` Andreas Arnez
2017-05-09 17:53 ` [PATCH v2 10/19] write_pieced_value: Transfer least significant bits into bit-field Andreas Arnez
2017-05-16  9:14   ` Yao Qi
2017-05-09 17:53 ` [PATCH v2 09/19] write_pieced_value: Fix buffer offset for memory pieces Andreas Arnez
2017-05-16  8:46   ` Yao Qi
2017-05-09 17:54 ` [PATCH v2 11/19] Add DWARF piece test cases for bit-field access Andreas Arnez
2017-05-16 13:52   ` Yao Qi
2017-05-09 17:55 ` [PATCH v2 12/19] read/write_pieced_value: Drop 'buffer_size' variable Andreas Arnez
2017-05-16 14:08   ` Yao Qi
2017-05-16 17:51     ` Andreas Arnez
2017-05-09 17:55 ` [PATCH v2 13/19] Fix handling of DWARF register pieces on big-endian targets Andreas Arnez
2017-06-12 13:12   ` Yao Qi
2017-05-09 17:56 ` [PATCH v2 14/19] read/write_pieced_value: Improve logic for buffer allocation Andreas Arnez
2017-06-12 13:28   ` Yao Qi
2017-06-12 19:40   ` Simon Marchi
2017-06-13 12:10     ` Andreas Arnez
2017-06-13 12:18       ` Pedro Alves
2017-06-13 14:41         ` Andreas Arnez
2017-05-09 17:57 ` [PATCH v2 15/19] Respect piece offset for DW_OP_bit_piece Andreas Arnez
2017-05-16 21:08   ` Yao Qi
2017-05-09 17:58 ` [PATCH v2 17/19] Fix bit-/byte-offset mismatch in parameter to read_value_memory Andreas Arnez
2017-05-30 19:59   ` Simon Marchi
2017-05-31 14:02     ` Andreas Arnez
2017-05-31 14:30       ` Simon Marchi
2017-05-09 17:58 ` [PATCH v2 16/19] read/write_pieced_value: Remove unnecessary variable copies Andreas Arnez
2017-06-12 13:50   ` Yao Qi
2017-05-09 17:59 ` [PATCH v2 18/19] write_pieced_value: Notify memory_changed observers Andreas Arnez
2017-05-16 21:12   ` Yao Qi
2017-05-09 18:00 ` [PATCH v2 19/19] read/write_pieced_value: Merge into one function Andreas Arnez
2017-06-12 13:57   ` Yao Qi
2017-06-12 14:34     ` Andreas Arnez
2017-06-13  9:17       ` Yao Qi
2017-05-30 16:42 ` [ping] [PATCH v2 00/19] Various DWARF piece fixes Andreas Arnez
2017-05-30 20:44 ` Simon Marchi
2017-05-31 14:24   ` Andreas Arnez
2017-06-12 11:38     ` Andreas Arnez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1494352015-10465-2-git-send-email-arnez@linux.vnet.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox