1 # Copyright 2017 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test reading/writing variables with non-trivial DWARF locations. In
17 # particular the test uses register- and memory locations as well as
18 # composite locations with register- and memory pieces.
22 # This test can only be run on targets which support DWARF-2 and use gas.
23 if {![dwarf2_support]} {
27 # Choose suitable integer registers for the test.
29 set dwarf_regnum {0 1}
31 if { [istarget "aarch64*-*-*"] } {
33 } elseif { [istarget "arm*-*-*"]
34 || [istarget "s390*-*-*" ]
35 || [istarget "powerpc*-*-*"]
36 || [istarget "rs6000*-*-aix*"] } {
38 } elseif { [istarget "i?86-*-*"] } {
40 } elseif { [istarget "x86_64-*-*"] } {
43 verbose "Skipping tests for accessing DWARF-described variables."
47 standard_testfile .c ${gdb_test_file_name}-dw.S
49 # Make some DWARF for the test.
51 set asm_file [standard_output_file $srcfile2]
52 Dwarf::assemble $asm_file {
53 global srcdir subdir srcfile
54 global dwarf_regnum regname
56 set buf_var [gdb_target_symbol buf]
60 {DW_AT_name var-pieces-dw.c}
63 declare_labels char_type_label
64 declare_labels int_type_label short_type_label
65 declare_labels array_a8_label struct_s_label
68 char_type_label: base_type {
70 {encoding @DW_ATE_unsigned_char}
71 {byte_size 1 DW_FORM_sdata}
75 int_type_label: base_type {
77 {encoding @DW_ATE_signed}
78 {byte_size 4 DW_FORM_sdata}
82 array_a8_label: array_type {
83 {type :$char_type_label}
86 {type :$int_type_label}
87 {upper_bound 7 DW_FORM_udata}
91 # struct s { char a, b, c, d; };
92 struct_s_label: structure_type {
94 {byte_size 4 DW_FORM_sdata}
98 {type :$char_type_label}
99 {data_member_location 0 DW_FORM_udata}
103 {type :$char_type_label}
104 {data_member_location 1 DW_FORM_udata}
108 {type :$char_type_label}
109 {data_member_location 2 DW_FORM_udata}
113 {type :$char_type_label}
114 {data_member_location 3 DW_FORM_udata}
119 {MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }}
120 {DW_AT_external 1 flag}
122 # Simple memory location.
125 {type :$array_a8_label}
130 # Memory pieces: two bytes from &buf[2], and two bytes
134 {type :$struct_s_label}
143 # Register- and memory pieces: one byte each from r0,
144 # &buf[4], r1, and &buf[5].
147 {type :$struct_s_label}
149 regx [lindex $dwarf_regnum 0]
153 regx [lindex $dwarf_regnum 1]
164 if { [prepare_for_testing ${testfile}.exp ${testfile} \
165 [list $srcfile $asm_file] {nodebug}] } {
173 # Byte-aligned memory pieces.
174 gdb_test "print/d s1" " = \\{a = 2, b = 3, c = 0, d = 1\\}" \
175 "s1 == re-ordered buf"
176 gdb_test_no_output "set var s1.a = 63"
177 gdb_test "print/d s1" " = \\{a = 63, b = 3, c = 0, d = 1\\}" \
179 gdb_test "print/d a" " = \\{0, 1, 63, 3, 4, 5, 6, 7\\}" \
180 "verify s1.a through a"
181 gdb_test_no_output "set var s1.b = 42"
182 gdb_test "print/d s1" " = \\{a = 63, b = 42, c = 0, d = 1\\}" \
184 gdb_test "print/d a" " = \\{0, 1, 63, 42, 4, 5, 6, 7\\}" \
185 "verify s1.b through a"
187 # Byte-aligned register- and memory pieces.
188 gdb_test_no_output "set var \$[lindex $regname 0] = 81" \
190 gdb_test_no_output "set var \$[lindex $regname 1] = 28" \
192 gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 28, d = 5\\}" \
193 "initialized s2 from mem and regs"
194 gdb_test_no_output "set var s2.c += s2.a + s2.b - s2.d"
195 gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 108, d = 5\\}" \
197 gdb_test "print/d \$[lindex $regname 1]" " = 108" \
198 "verify s2.c through reg"
199 gdb_test_no_output "set var s2 = {191, 73, 231, 123}" \
201 gdb_test "print/d s2" " = \\{a = 191, b = 73, c = 231, d = 123\\}" \
202 "verify re-initialized s2"