Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2010-2016 Free Software Foundation, Inc. |
2a20745c YQ |
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 | # This file is part of the gdb testsuite. | |
17 | ||
18 | # Test arm displaced stepping. | |
19 | ||
9fcf688e | 20 | if {![is_aarch32_target]} then { |
2a20745c YQ |
21 | verbose "Skipping arm displaced stepping tests." |
22 | return | |
23 | } | |
24 | ||
30ca9da1 | 25 | standard_testfile .S |
2a20745c YQ |
26 | |
27 | set additional_flags "-Wa,-g" | |
28 | ||
30ca9da1 | 29 | if { [prepare_for_testing $testfile.exp $testfile $srcfile [list debug $additional_flags]] } { |
2a20745c YQ |
30 | return -1 |
31 | } | |
32 | ||
33 | ||
34 | ######################################### | |
35 | # Test ldm/stm related to PC. | |
36 | proc test_ldm_stm_pc {} { | |
37 | global srcfile | |
34518530 YQ |
38 | global gdb_prompt |
39 | ||
2a20745c YQ |
40 | # Try to set breakpoint on test_ldm_stm_pc. If symbol 'test_ldm_stm_pc' |
41 | # can't be resolved, test case is compiled in Thumb mode, skip it. | |
42 | gdb_test_multiple "break *test_ldm_stm_pc" "break test_ldm_stm_pc" { | |
34518530 | 43 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { |
2a20745c YQ |
44 | pass "break test_ldm_stm_pc" |
45 | } | |
34518530 YQ |
46 | -re "No symbol.*\r\n$gdb_prompt $" { |
47 | pass "break test_ldm_stm_pc" | |
48 | return 0 | |
2a20745c YQ |
49 | } |
50 | } | |
51 | ||
52 | gdb_test "break *test_ldm_pc" \ | |
53 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
54 | "break test_ldm_pc" | |
55 | gdb_test "break *test_ldm_stm_pc_ret" \ | |
56 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
57 | "break test_ldm_stm_pc_ret" | |
58 | ||
59 | gdb_continue_to_breakpoint "continue to test_ldm_stm_pc" \ | |
60 | ".*stmdb.*sp\!\,.*\{lr\, pc\}.*" | |
61 | gdb_continue_to_breakpoint "continue to test_ldm_pc" \ | |
62 | ".*ldmia.*sp\!\,.*\{pc\}.*" | |
63 | gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \ | |
64 | ".*bx lr.*" | |
65 | } | |
0c51be18 YQ |
66 | |
67 | ######################################### | |
68 | # Test ldrX literal | |
69 | proc test_ldr_literal {} { | |
70 | global srcfile | |
71 | global gdb_prompt | |
72 | ||
73 | gdb_test_multiple "break *test_ldr_literal" "break test_ldr_literal" { | |
74 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { | |
75 | pass "break test_ldr_literal" | |
76 | } | |
77 | -re "No symbol.*\r\n$gdb_prompt $" { | |
78 | return 0 | |
79 | } | |
80 | } | |
81 | ||
82 | gdb_test "break *test_ldrsb_literal" \ | |
83 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
84 | "break test_ldrsb_literal" | |
85 | gdb_test "break *test_ldrsh_literal" \ | |
86 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
87 | "break test_ldrsh_literal" | |
88 | gdb_test "break *test_ldr_literal_end" \ | |
89 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
90 | "break test_test_ldr_literal_end" | |
91 | ||
92 | gdb_continue_to_breakpoint "continue to test_ldr_literal" \ | |
93 | ".*ldrh.*r0\,.*\[pc\].*" | |
94 | gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \ | |
95 | ".*ldrsb.*r0\,.*\[pc\].*" | |
96 | gdb_continue_to_breakpoint "continue to test_ldrsh_literal" \ | |
97 | ".*ldrsh.*r0\,.*\[pc\].*" | |
98 | gdb_continue_to_breakpoint "continue to test_ldr_literal_ret" \ | |
99 | ".*bx lr.*" | |
100 | } | |
101 | ||
34518530 YQ |
102 | proc test_ldr_literal_16 {} { |
103 | global srcfile | |
104 | global gdb_prompt | |
105 | ||
106 | gdb_test_multiple "break *test_ldr_literal_16" "break test_ldr_literal_16" { | |
107 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { | |
108 | pass "break test_ldr_literal" | |
109 | } | |
110 | -re "No symbol.*\r\n$gdb_prompt $" { | |
111 | return 0 | |
112 | } | |
113 | } | |
114 | gdb_test "break *test_ldr_literal_16_end" \ | |
115 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
116 | "break test_ldr_literal_16_end" | |
117 | ||
118 | gdb_continue_to_breakpoint "continue to test_ldr_literal_16" \ | |
119 | ".*ldr.*r0\,.*L2.*" | |
120 | gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \ | |
121 | ".*bx lr.*" | |
122 | } | |
123 | ||
2a20745c YQ |
124 | ########################################## |
125 | # Test call/ret. | |
126 | proc test_call_ret {} { | |
127 | global srcfile | |
34518530 YQ |
128 | global testfile |
129 | ||
130 | gdb_test "break *test_call" \ | |
131 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
132 | "break test_call" | |
133 | ||
2a20745c YQ |
134 | gdb_test "break *test_call_end" \ |
135 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
136 | "break test_call_end" | |
137 | gdb_test "break *test_ret" \ | |
138 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
139 | "break test_ret" | |
140 | gdb_test "break *test_ret_end" \ | |
141 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
142 | "break test_ret_end" | |
143 | ||
34518530 YQ |
144 | gdb_continue_to_breakpoint "test_call" ".*bl test_call_subr.*" |
145 | gdb_continue_to_breakpoint "test_call_end" \ | |
2a20745c | 146 | ".*@ Location test_call_end.*" |
34518530 | 147 | gdb_continue_to_breakpoint "test_ret" \ |
2a20745c YQ |
148 | ".*bx lr.*" |
149 | gdb_continue_to_breakpoint "continue to test_ret_end" \ | |
150 | ".*@ Location test_ret_end.*" | |
151 | } | |
152 | ||
153 | ||
154 | ######################################### | |
155 | # Test branch | |
156 | proc test_branch {} { | |
157 | global srcfile | |
158 | gdb_test "break *test_branch" \ | |
159 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
160 | "break test_branch" | |
161 | gdb_test "break *L_branch" \ | |
162 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
163 | "break Lbranch" | |
164 | ||
165 | gdb_continue_to_breakpoint "continue to test_branch" \ | |
166 | ".*b.*L_branch.*" | |
167 | gdb_continue_to_breakpoint "continue to Lbranch" \ | |
168 | ".*bx lr.*" | |
169 | } | |
170 | ||
171 | ######################################### | |
172 | ||
173 | # Test ldr from pc | |
174 | proc test_ldr_from_pc {} { | |
175 | global srcfile | |
176 | gdb_test "break *test_ldr_pc" \ | |
177 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
178 | "break test_ldr_pc" | |
179 | gdb_test "break test_ldr_pc_ret" \ | |
180 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
181 | "break test_ldr_pc_ret" | |
182 | ||
183 | gdb_continue_to_breakpoint "continue to test_ldr_pc" \ | |
184 | ".*ldr.*r1\,.*\[pc, #0\].*" | |
34518530 YQ |
185 | gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \ |
186 | ".*bx lr.*" | |
187 | } | |
188 | ||
189 | ######################################### | |
190 | ||
191 | # Test cbz and cbnz | |
192 | proc test_cbz_cbnz {} { | |
193 | global srcfile | |
194 | global gdb_prompt | |
195 | ||
196 | gdb_test_multiple "break *test_zero_cbnz" "break test_zero_cbnz" { | |
197 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { | |
198 | pass "break test_ldr_literal" | |
199 | } | |
200 | -re "No symbol.*\r\n$gdb_prompt $" { | |
201 | return 0 | |
202 | } | |
203 | } | |
204 | ||
205 | gdb_test "break *test_zero_cbz" \ | |
206 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
207 | "break test_zero_cbz" | |
208 | gdb_test "break *test_non_zero_cbnz" \ | |
209 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
210 | "break test_non_zero_cbnz" | |
211 | gdb_test "break *test_non_zero_cbz" \ | |
212 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
213 | "break test_non_zero_cbz" | |
214 | ||
215 | gdb_continue_to_breakpoint "continue to test_zero_cbnz" \ | |
216 | ".*cbnz.*r0\,.*\.L3.*" | |
217 | gdb_continue_to_breakpoint "continue to test_zero_cbz" \ | |
218 | ".*cbz.*r0\,.*\.L3.*" | |
219 | gdb_continue_to_breakpoint "continue to test_non_zero_cbz" \ | |
220 | ".*cbz.*r0\,.*\.L4.*" | |
221 | gdb_continue_to_breakpoint "continue to test_non_zero_cbnz" \ | |
222 | ".*cbnz.*r0\,.*\.L4.*" | |
223 | } | |
224 | ||
225 | # Test adr | |
226 | ||
227 | proc test_adr {} { | |
228 | global srcfile | |
229 | global gdb_prompt | |
230 | ||
231 | gdb_test_multiple "break *test_adr" "break test_adr" { | |
232 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { | |
233 | pass "break test_adr" | |
234 | } | |
235 | -re "No symbol.*\r\n$gdb_prompt $" { | |
236 | return 0 | |
237 | } | |
238 | } | |
239 | ||
240 | gdb_test "break *test_adr_end" \ | |
241 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
242 | "break test_adr_end" | |
243 | ||
244 | gdb_continue_to_breakpoint "test_adr" \ | |
245 | ".*adr.*r0\,.*\.L8.*" | |
246 | gdb_continue_to_breakpoint "test_adr_end" \ | |
2a20745c YQ |
247 | ".*bx lr.*" |
248 | } | |
249 | ||
0c51be18 YQ |
250 | proc test_adr_32bit {} { |
251 | global srcfile | |
252 | global gdb_prompt | |
253 | ||
254 | gdb_test_multiple "break *test_adr_32bit" "break test_adr_32bit" { | |
34518530 YQ |
255 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { |
256 | pass "break test_adr" | |
257 | } | |
258 | -re "No symbol.*\r\n$gdb_prompt $" { | |
259 | return 0 | |
260 | } | |
0c51be18 YQ |
261 | } |
262 | ||
263 | gdb_test "break *test_adr_32bit_after" \ | |
34518530 YQ |
264 | "Breakpoint.*at.* file .*$srcfile, line.*" \ |
265 | "break test_adr_32bit_after" | |
0c51be18 YQ |
266 | |
267 | gdb_test "break *test_adr_32bit_end" \ | |
34518530 YQ |
268 | "Breakpoint.*at.* file .*$srcfile, line.*" \ |
269 | "break test_adr_32bit_end" | |
0c51be18 YQ |
270 | |
271 | gdb_continue_to_breakpoint "test_adr_32bit" \ | |
34518530 | 272 | ".*adr.*r0\,.*\.L6.*" |
0c51be18 | 273 | gdb_continue_to_breakpoint "test_adr_32bit_after" \ |
34518530 | 274 | ".*adr.*r0\,.*\.L6.*" |
0c51be18 | 275 | gdb_continue_to_breakpoint "test_adr_32bit_end" \ |
34518530 | 276 | ".*bx lr.*" |
0c51be18 YQ |
277 | } |
278 | ||
279 | ######################################### | |
280 | # Test pop to PC | |
281 | proc test_pop_pc {} { | |
282 | global srcfile | |
283 | gdb_test "break *test_pop_pc_1" \ | |
34518530 YQ |
284 | "Breakpoint.*at.* file .*$srcfile, line.*" \ |
285 | "break test_pop_pc_1" | |
286 | gdb_test "break *test_pop_pc_2" \ | |
287 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
288 | "break test_pop_pc_2" | |
289 | gdb_test "break *test_pop_pc_3" \ | |
290 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
291 | "break test_pop_pc_3" | |
292 | ||
0c51be18 | 293 | gdb_test "break *test_pop_pc_ret" \ |
34518530 YQ |
294 | "Breakpoint.*at.* file .*$srcfile, line.*" \ |
295 | "break test_pop_pc_ret" | |
0c51be18 | 296 | |
34518530 YQ |
297 | gdb_test "break *test_pop_pc_1_right" \ |
298 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
299 | "break test_pop_pc_1_right" | |
300 | gdb_test "break *test_pop_pc_1_wrong" \ | |
301 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
302 | "break test_pop_pc_1_wrong" | |
303 | gdb_test "break *test_pop_pc_2_right" \ | |
304 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
305 | "break test_pop_pc_2_right" | |
306 | gdb_test "break *test_pop_pc_2_wrong" \ | |
307 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
308 | "break test_pop_pc_2_wrong" | |
309 | gdb_test "break *test_pop_pc_3_right" \ | |
310 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
311 | "break test_pop_pc_3_right" | |
312 | gdb_test "break *test_pop_pc_3_wrong" \ | |
313 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
314 | "break test_pop_pc_1_wrong" | |
315 | ||
316 | gdb_continue_to_breakpoint "continue to test_pop_pc_1" \ | |
317 | ".*b.*\{r1\, pc\}.*" | |
318 | gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \ | |
319 | ".*b.*right.*" | |
320 | ||
321 | gdb_continue_to_breakpoint "continue to test_pop_pc_2" \ | |
322 | ".*\{pc\}.*" | |
323 | gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \ | |
324 | ".*b.*right.*" | |
325 | gdb_continue_to_breakpoint "continue to test_pop_pc_3" \ | |
326 | ".*\{r0\,r1\,r2\,r3\,r4\,r5\,r6\,r7\,pc\}.*" | |
327 | gdb_continue_to_breakpoint "continue to test_pop_pc_3_check" \ | |
328 | ".*b.*right.*" | |
0c51be18 | 329 | gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \ |
34518530 | 330 | ".*r7.*" |
0c51be18 YQ |
331 | } |
332 | ||
494e194e YQ |
333 | ########################################### |
334 | ||
335 | proc test_str_pc {} { | |
336 | global srcfile | |
34518530 YQ |
337 | global gdb_prompt |
338 | ||
494e194e | 339 | gdb_test_multiple "break *test_str_pc" "break test_str_pc" { |
34518530 | 340 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { |
494e194e YQ |
341 | pass "break test_str_pc" |
342 | } | |
34518530 | 343 | -re "No symbol.*\r\n$gdb_prompt $" { |
494e194e YQ |
344 | pass "break test_str_pc" |
345 | return | |
346 | } | |
347 | } | |
348 | gdb_test "break *test_str_pc_end" \ | |
349 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
350 | "break test_str_pc_end" | |
351 | ||
352 | # Set breakpoint on both lables pc_offset_right and pc_offset_wrong | |
353 | gdb_test "break *pc_offset_right" \ | |
354 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
355 | "break pc_offset_right" | |
356 | gdb_test "break *pc_offset_wrong" \ | |
357 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
358 | "break pc_offset_wrong" | |
359 | ||
360 | gdb_continue_to_breakpoint "continue to test_str_pc" \ | |
361 | ".*str.*pc\,.*\[sp, #-4\].*" | |
362 | # If breakpoint on lable pc_offset_wrong is hit, that means the offset | |
363 | # computed in displaced stepping is different from offset computed | |
364 | # without displaced stepping. Report a failure. | |
365 | gdb_continue_to_breakpoint "continue to pc_offset_right" \ | |
366 | ".*b.*test_str_pc_end.*" | |
367 | gdb_continue_to_breakpoint "continue to test_str_pc_end" \ | |
368 | ".*bx lr.*" | |
369 | } | |
370 | ||
ef713951 YQ |
371 | # Test 16 bit thumb instruction 'add rd, pc'. |
372 | ||
373 | proc test_add_rn_pc {} { | |
374 | global srcfile gdb_prompt | |
375 | ||
376 | set test "break test_add_rn_pc" | |
377 | gdb_test_multiple "break *test_add_rn_pc" $test { | |
378 | -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { | |
379 | pass $test | |
380 | } | |
381 | -re "No symbol.*\r\n$gdb_prompt $" { | |
382 | return | |
383 | } | |
384 | } | |
385 | ||
386 | gdb_continue_to_breakpoint "continue to test_add_rn_pc" \ | |
387 | ".*mov.*r3, 4.*" | |
388 | ||
389 | gdb_test "break *test_add_rn_pc_start" \ | |
390 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
391 | "break test_add_rn_pc_start" | |
392 | ||
393 | gdb_continue_to_breakpoint "continue to test_add_rn_pc_start" \ | |
394 | ".*add.*r3,.*pc.*" | |
395 | ||
396 | set pc_val [get_integer_valueof "\$pc" 0] | |
397 | ||
398 | gdb_test "break *test_add_rn_pc_end" \ | |
399 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
400 | "break test_add_rn_pc_end" | |
401 | ||
402 | gdb_continue_to_breakpoint "continue to test_add_rn_pc_end" \ | |
403 | ".*bx lr.*" | |
404 | ||
405 | set r3_val [get_integer_valueof "\$r3" 0] | |
406 | # Test the value in r3 is correct. | |
407 | gdb_assert { [expr {$pc_val + 4 + 4} == $r3_val] } | |
408 | } | |
409 | ||
2a20745c YQ |
410 | # Turn displaced stepping off before runto main. When displaced stepping |
411 | # is on, and we type 'run', GDB will first try to single step on _dl_debug_state, | |
412 | # which is in library might be compiled in Thumb. | |
413 | gdb_test_no_output "set displaced-stepping off" | |
414 | ||
415 | if ![runto_main] then { | |
bc6c7af4 | 416 | fail "can't run to main" |
2a20745c YQ |
417 | return 0 |
418 | } | |
419 | ||
420 | gdb_test_no_output "set displaced-stepping on" | |
421 | gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*" | |
422 | ||
2a20745c YQ |
423 | test_call_ret |
424 | ||
425 | test_branch | |
426 | ||
427 | test_ldr_from_pc | |
428 | ||
429 | test_ldm_stm_pc | |
430 | ||
0c51be18 YQ |
431 | test_ldr_literal |
432 | ||
34518530 YQ |
433 | test_ldr_literal_16 |
434 | ||
435 | test_cbz_cbnz | |
436 | ||
437 | test_adr | |
438 | ||
0c51be18 YQ |
439 | test_adr_32bit |
440 | ||
441 | test_pop_pc | |
442 | ||
494e194e | 443 | test_str_pc |
34518530 | 444 | |
ef713951 YQ |
445 | test_add_rn_pc |
446 | ||
2a20745c YQ |
447 | ########################################## |
448 | ||
449 | # Done, run program to exit. | |
450 | ||
451 | gdb_continue_to_end "arm-disp-step" |