aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/arm-disp-step.exp
blob: 994f08e99355577f2add826b1232eaf940fbcd7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# Copyright 2010, 2011 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/>.

# This file is part of the gdb testsuite.

# Test arm displaced stepping.

if $tracelevel {
    strace $tracelevel
}

if {![istarget "arm*-*-*"]} then {
    verbose "Skipping arm displaced stepping tests."
    return
}

set testfile "arm-disp-step"
set srcfile ${testfile}.S
set binfile ${objdir}/${subdir}/${testfile}

set additional_flags "-Wa,-g"

if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
    untested arm-disp-step.exp
    return -1
}


#########################################
# Test ldm/stm related to PC.
proc test_ldm_stm_pc {} {
    global srcfile
    global gdb_prompt

    # Try to set breakpoint on test_ldm_stm_pc.  If symbol 'test_ldm_stm_pc'
    # can't be resolved, test case is compiled in Thumb mode, skip it.
    gdb_test_multiple "break *test_ldm_stm_pc" "break test_ldm_stm_pc" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_ldm_stm_pc"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    pass "break test_ldm_stm_pc"
	    return 0
	}
    }

    gdb_test "break *test_ldm_pc" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ldm_pc"
    gdb_test "break *test_ldm_stm_pc_ret" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ldm_stm_pc_ret"

    gdb_continue_to_breakpoint "continue to test_ldm_stm_pc" \
	".*stmdb.*sp\!\,.*\{lr\, pc\}.*"
    gdb_continue_to_breakpoint "continue to test_ldm_pc" \
	".*ldmia.*sp\!\,.*\{pc\}.*"
    gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \
	".*bx lr.*"
}

#########################################
# Test ldrX literal
proc test_ldr_literal {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_ldr_literal" "break test_ldr_literal" {
       -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
           pass "break test_ldr_literal"
       }
       -re "No symbol.*\r\n$gdb_prompt $" {
           return 0
       }
    }

    gdb_test "break *test_ldrsb_literal" \
       "Breakpoint.*at.* file .*$srcfile, line.*" \
       "break test_ldrsb_literal"
    gdb_test "break *test_ldrsh_literal" \
       "Breakpoint.*at.* file .*$srcfile, line.*" \
       "break test_ldrsh_literal"
    gdb_test "break *test_ldr_literal_end" \
       "Breakpoint.*at.* file .*$srcfile, line.*" \
       "break test_test_ldr_literal_end"

    gdb_continue_to_breakpoint "continue to test_ldr_literal" \
       ".*ldrh.*r0\,.*\[pc\].*"
    gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \
       ".*ldrsb.*r0\,.*\[pc\].*"
    gdb_continue_to_breakpoint "continue to test_ldrsh_literal" \
       ".*ldrsh.*r0\,.*\[pc\].*"
    gdb_continue_to_breakpoint "continue to test_ldr_literal_ret" \
       ".*bx lr.*"
}

proc test_ldr_literal_16 {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_ldr_literal_16" "break test_ldr_literal_16" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_ldr_literal"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    return 0
	}
    }
    gdb_test "break *test_ldr_literal_16_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ldr_literal_16_end"

    gdb_continue_to_breakpoint "continue to test_ldr_literal_16" \
	".*ldr.*r0\,.*L2.*"
    gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \
	".*bx lr.*"
}

##########################################
# Test call/ret.
proc test_call_ret {} {
    global srcfile
    global testfile

    gdb_test "break *test_call" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_call"

    gdb_test "break *test_call_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_call_end"
    gdb_test "break *test_ret" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ret"
    gdb_test "break *test_ret_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ret_end"

    gdb_continue_to_breakpoint "test_call" ".*bl test_call_subr.*"
    gdb_continue_to_breakpoint "test_call_end" \
	".*@ Location test_call_end.*"
    gdb_continue_to_breakpoint "test_ret" \
	".*bx lr.*"
    gdb_continue_to_breakpoint "continue to test_ret_end" \
	".*@ Location test_ret_end.*"
}


#########################################
# Test branch
proc test_branch {} {
    global srcfile
    gdb_test "break *test_branch" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_branch"
    gdb_test "break *L_branch" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break Lbranch"

    gdb_continue_to_breakpoint "continue to test_branch" \
	".*b.*L_branch.*"
    gdb_continue_to_breakpoint "continue to Lbranch" \
	".*bx lr.*"
}

#########################################

# Test ldr from pc
proc test_ldr_from_pc {} {
    global srcfile
    gdb_test "break *test_ldr_pc" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ldr_pc"
    gdb_test "break test_ldr_pc_ret" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_ldr_pc_ret"

    gdb_continue_to_breakpoint "continue to test_ldr_pc" \
	".*ldr.*r1\,.*\[pc, #0\].*"
    gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \
	".*bx lr.*"
}

#########################################

# Test cbz and cbnz
proc test_cbz_cbnz {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_zero_cbnz" "break test_zero_cbnz" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_ldr_literal"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    return 0
	}
    }

    gdb_test "break *test_zero_cbz" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_zero_cbz"
    gdb_test "break *test_non_zero_cbnz" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_non_zero_cbnz"
    gdb_test "break *test_non_zero_cbz" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_non_zero_cbz"

    gdb_continue_to_breakpoint "continue to test_zero_cbnz" \
	".*cbnz.*r0\,.*\.L3.*"
    gdb_continue_to_breakpoint "continue to test_zero_cbz" \
	".*cbz.*r0\,.*\.L3.*"
    gdb_continue_to_breakpoint "continue to test_non_zero_cbz" \
	".*cbz.*r0\,.*\.L4.*"
    gdb_continue_to_breakpoint "continue to test_non_zero_cbnz" \
	".*cbnz.*r0\,.*\.L4.*"
}

# Test adr

proc test_adr {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_adr" "break test_adr" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_adr"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    return 0
	}
    }

    gdb_test "break *test_adr_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_adr_end"

    gdb_continue_to_breakpoint "test_adr" \
	".*adr.*r0\,.*\.L8.*"
    gdb_continue_to_breakpoint "test_adr_end" \
	".*bx lr.*"
}

proc test_adr_32bit {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_adr_32bit" "break test_adr_32bit" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_adr"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    return 0
	}
    }

    gdb_test "break *test_adr_32bit_after" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_adr_32bit_after"

    gdb_test "break *test_adr_32bit_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_adr_32bit_end"

    gdb_continue_to_breakpoint "test_adr_32bit" \
	".*adr.*r0\,.*\.L6.*"
    gdb_continue_to_breakpoint "test_adr_32bit_after" \
	".*adr.*r0\,.*\.L6.*"
    gdb_continue_to_breakpoint "test_adr_32bit_end" \
	".*bx lr.*"
}

#########################################
# Test pop to PC
proc test_pop_pc {} {
    global srcfile
    gdb_test "break *test_pop_pc_1" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_1"
    gdb_test "break *test_pop_pc_2" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_2"
    gdb_test "break *test_pop_pc_3" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_3"

    gdb_test "break *test_pop_pc_ret" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_ret"

    gdb_test "break *test_pop_pc_1_right" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_1_right"
    gdb_test "break *test_pop_pc_1_wrong" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_1_wrong"
    gdb_test "break *test_pop_pc_2_right" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_2_right"
    gdb_test "break *test_pop_pc_2_wrong" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_2_wrong"
    gdb_test "break *test_pop_pc_3_right" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_3_right"
    gdb_test "break *test_pop_pc_3_wrong" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_pop_pc_1_wrong"

    gdb_continue_to_breakpoint "continue to test_pop_pc_1" \
	".*b.*\{r1\, pc\}.*"
    gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \
	".*b.*right.*"

    gdb_continue_to_breakpoint "continue to test_pop_pc_2" \
	".*\{pc\}.*"
    gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \
	".*b.*right.*"
    gdb_continue_to_breakpoint "continue to test_pop_pc_3" \
	".*\{r0\,r1\,r2\,r3\,r4\,r5\,r6\,r7\,pc\}.*"
    gdb_continue_to_breakpoint "continue to test_pop_pc_3_check" \
	".*b.*right.*"
    gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \
	".*r7.*"
}

###########################################

proc test_str_pc {} {
    global srcfile
    global gdb_prompt

    gdb_test_multiple "break *test_str_pc" "break test_str_pc" {
	-re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
	    pass "break test_str_pc"
	}
	-re "No symbol.*\r\n$gdb_prompt $" {
	    pass "break test_str_pc"
	    return
	}
    }
    gdb_test "break *test_str_pc_end" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break test_str_pc_end"

    # Set breakpoint on both lables pc_offset_right and pc_offset_wrong
    gdb_test "break *pc_offset_right" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break pc_offset_right"
    gdb_test "break *pc_offset_wrong" \
	"Breakpoint.*at.* file .*$srcfile, line.*" \
	"break pc_offset_wrong"

    gdb_continue_to_breakpoint "continue to test_str_pc" \
	".*str.*pc\,.*\[sp, #-4\].*"
    # If breakpoint on lable pc_offset_wrong is hit, that means the offset
    # computed in displaced stepping is different from offset computed
    # without displaced stepping.  Report a failure.
    gdb_continue_to_breakpoint "continue to pc_offset_right" \
	".*b.*test_str_pc_end.*"
    gdb_continue_to_breakpoint "continue to test_str_pc_end" \
	".*bx lr.*"
}

# Get things started.

clean_restart ${testfile}

# Turn displaced stepping off before runto main. When displaced stepping
# is on, and we type 'run', GDB will first try to single step on _dl_debug_state,
# which is in library might be compiled in Thumb.
gdb_test_no_output "set displaced-stepping off"

if ![runto_main] then {
    fail "Can't run to main"
    return 0
}

gdb_test_no_output "set displaced-stepping on"
gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"

test_call_ret

test_branch

test_ldr_from_pc

test_ldm_stm_pc

test_ldr_literal

test_ldr_literal_16

test_cbz_cbnz

test_adr

test_adr_32bit

test_pop_pc

test_str_pc

##########################################

# Done, run program to exit.

gdb_continue_to_end "arm-disp-step"