Commit | Line | Data |
---|---|---|
0567c986 AA |
1 | # Copyright 2017 Free Software Foundation, Inc. |
2 | ||
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
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. | |
19 | ||
20 | load_lib dwarf.exp | |
21 | ||
22 | # This test can only be run on targets which support DWARF-2 and use gas. | |
23 | if {![dwarf2_support]} { | |
24 | return 0 | |
25 | } | |
26 | ||
27 | # Choose suitable integer registers for the test. | |
28 | ||
29 | set dwarf_regnum {0 1} | |
30 | ||
31 | if { [istarget "aarch64*-*-*"] } { | |
32 | set regname {x0 x1} | |
33 | } elseif { [istarget "arm*-*-*"] | |
34 | || [istarget "s390*-*-*" ] | |
35 | || [istarget "powerpc*-*-*"] | |
36 | || [istarget "rs6000*-*-aix*"] } { | |
37 | set regname {r0 r1} | |
38 | } elseif { [istarget "i?86-*-*"] } { | |
39 | set regname {eax edx} | |
40 | } elseif { [istarget "x86_64-*-*"] } { | |
41 | set regname {rax rdx} | |
42 | } else { | |
43 | verbose "Skipping tests for accessing DWARF-described variables." | |
44 | return | |
45 | } | |
46 | ||
47 | standard_testfile .c ${gdb_test_file_name}-dw.S | |
48 | ||
49 | # Make some DWARF for the test. | |
50 | ||
51 | set asm_file [standard_output_file $srcfile2] | |
52 | Dwarf::assemble $asm_file { | |
53 | global srcdir subdir srcfile | |
54 | global dwarf_regnum regname | |
55 | ||
56 | set buf_var [gdb_target_symbol buf] | |
57 | ||
58 | cu {} { | |
59 | DW_TAG_compile_unit { | |
60 | {DW_AT_name var-pieces-dw.c} | |
61 | {DW_AT_comp_dir /tmp} | |
62 | } { | |
63 | declare_labels char_type_label | |
64 | declare_labels int_type_label short_type_label | |
65 | declare_labels array_a8_label struct_s_label | |
66 | ||
67 | # char | |
68 | char_type_label: base_type { | |
69 | {name "char"} | |
70 | {encoding @DW_ATE_unsigned_char} | |
71 | {byte_size 1 DW_FORM_sdata} | |
72 | } | |
73 | ||
74 | # int | |
75 | int_type_label: base_type { | |
76 | {name "int"} | |
77 | {encoding @DW_ATE_signed} | |
78 | {byte_size 4 DW_FORM_sdata} | |
79 | } | |
80 | ||
81 | # char [8] | |
82 | array_a8_label: array_type { | |
83 | {type :$char_type_label} | |
84 | } { | |
85 | subrange_type { | |
86 | {type :$int_type_label} | |
87 | {upper_bound 7 DW_FORM_udata} | |
88 | } | |
89 | } | |
90 | ||
91 | # struct s { char a, b, c, d; }; | |
92 | struct_s_label: structure_type { | |
93 | {name "s"} | |
94 | {byte_size 4 DW_FORM_sdata} | |
95 | } { | |
96 | member { | |
97 | {name "a"} | |
98 | {type :$char_type_label} | |
99 | {data_member_location 0 DW_FORM_udata} | |
100 | } | |
101 | member { | |
102 | {name "b"} | |
103 | {type :$char_type_label} | |
104 | {data_member_location 1 DW_FORM_udata} | |
105 | } | |
106 | member { | |
107 | {name "c"} | |
108 | {type :$char_type_label} | |
109 | {data_member_location 2 DW_FORM_udata} | |
110 | } | |
111 | member { | |
112 | {name "d"} | |
113 | {type :$char_type_label} | |
114 | {data_member_location 3 DW_FORM_udata} | |
115 | } | |
116 | } | |
117 | ||
118 | DW_TAG_subprogram { | |
119 | {MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }} | |
120 | {DW_AT_external 1 flag} | |
121 | } { | |
122 | # Simple memory location. | |
123 | DW_TAG_variable { | |
124 | {name "a"} | |
125 | {type :$array_a8_label} | |
126 | {location { | |
127 | addr $buf_var | |
128 | } SPECIAL_expr} | |
129 | } | |
130 | # Memory pieces: two bytes from &buf[2], and two bytes | |
131 | # from &buf[0]. | |
132 | DW_TAG_variable { | |
133 | {name "s1"} | |
134 | {type :$struct_s_label} | |
135 | {location { | |
136 | addr $buf_var | |
137 | plus_uconst 2 | |
138 | piece 2 | |
139 | addr $buf_var | |
140 | piece 2 | |
141 | } SPECIAL_expr} | |
142 | } | |
143 | # Register- and memory pieces: one byte each from r0, | |
144 | # &buf[4], r1, and &buf[5]. | |
145 | DW_TAG_variable { | |
146 | {name "s2"} | |
147 | {type :$struct_s_label} | |
148 | {location { | |
149 | regx [lindex $dwarf_regnum 0] | |
150 | piece 1 | |
151 | addr "$buf_var + 4" | |
152 | piece 1 | |
153 | regx [lindex $dwarf_regnum 1] | |
154 | piece 1 | |
155 | addr "$buf_var + 5" | |
156 | piece 1 | |
157 | } SPECIAL_expr} | |
158 | } | |
159 | } | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | if { [prepare_for_testing ${testfile}.exp ${testfile} \ | |
165 | [list $srcfile $asm_file] {nodebug}] } { | |
166 | return -1 | |
167 | } | |
168 | ||
169 | if ![runto_main] { | |
170 | return -1 | |
171 | } | |
172 | ||
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\\}" \ | |
178 | "verify s1.a" | |
179 | gdb_test "print/d a" " = \\{0, 1, 63, 3, 4, 5, 6, 7\\}" \ | |
180 | "verify s1.a through a" | |
181 | ||
182 | # Byte-aligned register- and memory pieces. | |
183 | gdb_test_no_output "set var \$[lindex $regname 0] = 81" \ | |
184 | "init reg for s2.a" | |
185 | gdb_test_no_output "set var \$[lindex $regname 1] = 28" \ | |
186 | "init reg for s2.c" | |
187 | gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 28, d = 5\\}" \ | |
188 | "initialized s2 from mem and regs" | |
189 | gdb_test_no_output "set var s2.c += s2.a + s2.b - s2.d" | |
190 | gdb_test "print/d s2" " = \\{a = 81, b = 4, c = 108, d = 5\\}" \ | |
191 | "verify s2.c" | |
192 | gdb_test "print/d \$[lindex $regname 1]" " = 108" \ | |
193 | "verify s2.c through reg" | |
194 | gdb_test_no_output "set var s2 = {191, 73, 231, 123}" \ | |
195 | "re-initialize s2" | |
196 | gdb_test "print/d s2" " = \\{a = 191, b = 73, c = 231, d = 123\\}" \ | |
197 | "verify re-initialized s2" |