Re: [patch 3/3] Displaced stepping for 16-bit Thumb instructions

Yao Qi
2010-12-27T13:52:35Z

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

On 12/25/2010 10:21 PM, Yao Qi wrote:
> gdb/testsuite/
> 2010-12-25 Yao Qi <yao@codesourcery.com>
>
> * gdb.arch/arm-disp-step.S: Test cbnz/cbz, adr and ldr.
> * gdb.arch/arm-disp-step.exp: Likewise.

In my previous patch, displaced stepping is turned off in test_call_ret,
but 'forget' to turn it on again. This patch is to address this problem
by replacing original gdb_continue_to_breakpoint by
try_continue_with_displaced_step, in which displaced stepping is turned
on, and make sure GDB can do displaced stepping on that instruction, so
displaced stepping can't be turned off again.

--
Yao (é½å°§)

[-- Attachment #2: arm_disp_step_thumb_16bit_test_1227.patch --]
[-- Type: text/x-patch, Size: 9180 bytes --]

diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.S b/gdb/testsuite/gdb.arch/arm-disp-step.S
index d748718..2e5b7ba 100644
--- a/gdb/testsuite/gdb.arch/arm-disp-step.S
+++ b/gdb/testsuite/gdb.arch/arm-disp-step.S
@@ -48,6 +48,26 @@ test_ret_end:
bl test_ldm_stm_pc
#endif

+ /* Test ldrX literal in ARM and Thumb-2 */
+#if !defined (__thumb__)
+ bl test_ldr_literal
+#endif
+
+ /* Test ldr literal in Thumb */
+#if defined(__thumb__)
+ bl test_ldr_literal_16
+#endif
+
+ /* Test cbnz/cbz in Thumb-2 */
+#if defined(__thumb2__)
+ bl test_cbz_cbnz
+#endif
+
+ /* Test adr in Thumb and Thumb-2 */
+#if defined(__thumb) || defined(__thumb2__)
+ bl test_adr
+#endif
+
/* Return */
mov sp, r7
sub sp, sp, #4
@@ -118,3 +138,75 @@ test_ldm_stm_pc_ret:
.word test_ldm_stm_pc_ret
.size test_ldm_stm_pc, .-test_ldm_stm_pc
#endif
+
+#if !defined (__thumb__)
+ .global test_ldr_literal
+ .type test_ldr_literal, %function
+test_ldr_literal:
+ ldrh r0, [pc]
+ .global test_ldrsb_literal
+test_ldrsb_literal:
+ ldrsb r0, [pc]
+ .global test_ldrsh_literal
+test_ldrsh_literal:
+ ldrsh r0, [pc]
+ .global test_ldr_literal_end
+test_ldr_literal_end:
+ bx lr
+ .size test_ldr_literal, .-test_ldr_literal
+#endif
+
+#if defined(__thumb__)
+ .global test_ldr_literal_16
+ .code 16
+ .thumb_func
+test_ldr_literal_16:
+ ldr r0, .L2
+ .global test_ldr_literal_16_end
+test_ldr_literal_16_end:
+ bx lr
+ .align 2
+.L2:
+ .word test_ldr_literal_16
+ .size test_ldr_literal_16, .-test_ldr_literal_16
+#endif
+
+#if defined(__thumb2__)
+ .global test_cbz_cbnz
+ .code 16
+ .thumb_func
+test_cbz_cbnz:
+ movs r0, #0
+ .global test_zero_cbnz
+test_zero_cbnz:
+ cbnz r0, .L3
+ .global test_zero_cbz
+test_zero_cbz:
+ cbz r0, .L3
+.L3:
+ movs r0, #1
+ .global test_non_zero_cbz
+test_non_zero_cbz:
+ cbz r0, .L4
+ .global test_non_zero_cbnz
+test_non_zero_cbnz:
+ cbnz r0, .L4
+ nop
+.L4:
+ .global test_cbz_cbnz_end
+test_cbz_cbnz_end:
+ bx lr
+ .size test_cbz_cbnz, .-test_cbz_cbnz
+#endif
+
+#if defined(__thumb) || defined(__thumb2__)
+ .global test_adr
+ .code 16
+ .thumb_func
+test_adr:
+ adr r0, #1
+ .global test_adr_end
+test_adr_end:
+ bx lr
+ .size test_adr, .-test_adr
+#endif
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.exp b/gdb/testsuite/gdb.arch/arm-disp-step.exp
index 826f728..a8d2adc 100644
--- a/gdb/testsuite/gdb.arch/arm-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/arm-disp-step.exp
@@ -37,6 +37,22 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list
return -1
}

+# Try to resume program with displaced stepping. If displaced stepping is
+# not supported, turn it off, and continue.
+
+proc try_continue_with_displaced_step { msg loc } {
+ gdb_test_no_output "set displaced-stepping on"
+ gdb_test_multiple "continue" "continue to $msg" {
+ -re ".*$loc.*" {
+ pass "continue to $msg"
+ }
+ -re "Displaced stepping is only supported in.*" {
+ gdb_test_no_output "set displaced-stepping off"
+ gdb_test "continue" ".*"
+ kfail "gdb/NNNN" $msg
+ }
+ }
+}

#########################################
# Test ldm/stm related to PC.
@@ -50,7 +66,11 @@ proc test_ldm_stm_pc {} {
}
-re "Function \"test_ldm_stm_pc\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" {
gdb_test "n" "" "Test case is compiled in Thumb mode"
- return
+ return 0
+ }
+ -re "No symbol.*" {
+ pass "break test_ldm_stm_pc"
+ return 0
}
}

@@ -68,10 +88,75 @@ proc test_ldm_stm_pc {} {
gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \
".*bx lr.*"
}
+
+#########################################
+# Test ldrX literal
+proc test_ldr_literal {} {
+ global srcfile
+ # 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_ldr_literal" "break test_ldr_literal" {
+ -re "Breakpoint.*at.* file .*$srcfile, line.*" {
+ pass "break test_ldr_literal"
+ }
+ -re "Function \"test_ldr_literal\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" {
+ gdb_test "n" "" "Test case is compiled in Thumb mode"
+ return 0
+ }
+ -re "No symbol.*" {
+ 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.*"
+
+ gdb_test_multiple "break test_ldr_literal_16" "break test_ldr_literal_16" {
+ -re "Breakpoint.*at.* file .*$srcfile, line.*" {
+ pass "break test_ldr_literal"
+ }
+ -re "Function \"test_ldr_literal_16\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" {
+ gdb_test "n" "" "skip"
+ return 0
+ }
+ }
+
+ gdb_test "break *test_ldr_literal_16_end" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "break test_test_ldr_literal_16_end"
+
+ gdb_continue_to_breakpoint "continue to test_ldr_literal" \
+ ".*ldr.*r0\,.*L2.*"
+ gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \
+ ".*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"
@@ -82,10 +167,12 @@ proc test_call_ret {} {
"Breakpoint.*at.* file .*$srcfile, line.*" \
"break test_ret_end"

- gdb_continue_to_breakpoint "continue to test_call_end" \
- ".*@ Location test_call_end.*"
- gdb_continue_to_breakpoint "continue to test_ret" \
+ try_continue_with_displaced_step "test_call" "bl test_call_subr"
+ try_continue_with_displaced_step "test_call_end" \
+ "@ Location test_call_end"
+ try_continue_with_displaced_step "test_ret" \
".*bx lr.*"
+
gdb_continue_to_breakpoint "continue to test_ret_end" \
".*@ Location test_ret_end.*"
}
@@ -122,7 +209,66 @@ proc test_ldr_from_pc {} {

gdb_continue_to_breakpoint "continue to test_ldr_pc" \
".*ldr.*r1\,.*\[pc, #0\].*"
- gdb_continue_to_breakpoint "continue to Lbranch" \
+ gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \
+ ".*bx lr.*"
+}
+
+#########################################
+
+# Test cbz and cbnz
+proc test_cbz_cbnz {} {
+ global srcfile
+
+ gdb_test_multiple "break *test_zero_cbnz" "break test_zero_cbnz" {
+ -re "Breakpoint.*at.* file .*$srcfile, line.*" {
+ pass "break test_ldr_literal"
+ }
+ -re "No symbol.*" {
+ 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
+
+ gdb_test_multiple "break *test_adr" "break test_adr" {
+ -re "Breakpoint.*at.* file .*$srcfile, line.*" {
+ pass "break test_adr"
+ }
+ -re "No symbol.*" {
+ return 0
+ }
+ }
+
+ gdb_test "break *test_adr_end" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "break test_adr_end"
+
+ try_continue_with_displaced_step "test_adr" \
+ "adr.*r0\,.*#1"
+ try_continue_with_displaced_step "test_adr_end" \
".*bx lr.*"
}

@@ -143,20 +289,6 @@ if ![runto_main] then {
gdb_test_no_output "set displaced-stepping on"
gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"

-gdb_test "break *test_call" \
- "Breakpoint.*at.* file .*$srcfile, line.*" \
- "break test_call"
-
-gdb_test_multiple "continue" "continue to test_call" {
- -re ".*bl test_call_subr.*" {
- pass "continue to test_call"
- }
- -re "Displaced stepping is only supported in" {
- kfail "gdb/NNNN" $testfile
- return
- }
- }
-
test_call_ret

test_branch
@@ -165,6 +297,11 @@ test_ldr_from_pc

test_ldm_stm_pc

+test_ldr_literal
+
+test_cbz_cbnz
+
+test_adr
##########################################

# Done, run program to exit.