From 3451853062d59da1ad23ecd872775ed22c8a0b85 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Sun, 18 Sep 2011 14:34:55 +0000 Subject: Support displaced stepping for Thumb 16-bit insns. gdb/ * arm-tdep.c (THUMB_NOP) Define. (thumb_copy_unmodified_16bit): New. (thumb_copy_b, thumb_copy_bx_blx_reg): New. (thumb_copy_alu_reg): New. (arm_copy_svc): Move some common code to ... (install_svc): ... here. New. (thumb_copy_svc): New. (install_pc_relative): New. (thumb_copy_pc_relative_16bit): New. (thumb_decode_pc_relative_16bit): New. (thumb_copy_16bit_ldr_literal): New. (thumb_copy_cbnz_cbz): New. (cleanup_pop_pc_16bit_all): New. (thumb_copy_pop_pc_16bit): New. (thumb_process_displaced_16bit_insn): New. (thumb_process_displaced_32bit_insn): New. (thumb_process_displaced_insn): process thumb instruction. Support displaced stepping for Thumb 32-bit insns. gdb/ * arm-tdep.c (thumb_copy_unmodified_32bit): New. (thumb2_copy_preload): New. (thumb2_copy_copro_load_store): New. (thumb2_copy_b_bl_blx): New. (thumb2_copy_alu_imm): New. (thumb2_copy_load_reg_imm): New. (thumb2_copy_load_literal): New (thumb2_copy_block_xfer): New. (thumb_32bit_copy_undef): New. (thumb_32bit_copy_unpred): New. (thumb2_decode_ext_reg_ld_st): New. (thumb2_decode_svc_copro): New. (decode_thumb_32bit_store_single_data_item): New. (thumb_copy_pc_relative_32bit): New. (thumb_decode_pc_relative_32bit): New. (decode_thumb_32bit_ld_mem_hints): New. (thumb2_copy_table_branch): New (thumb_process_displaced_32bit_insn): Process Thumb 32-bit instructions. gdb/testsuite/ * gdb.arch/arm-disp-step.S (test_ldr_literal): Test for Thumb instructions. (test_adr_32bit, test_pop_pc): Likewise. (test_ldr_literal_16, test_cbz_cbnz, test_adr): New test for Thumb instructions. * gdb.arch/arm-disp-step.exp (test_ldm_stm_pc): Match $gdb_prompt in gdb_test_multiple. (test_ldr_literal_16, test_cbz_cbnz, test_adr): New. --- gdb/testsuite/ChangeLog | 11 ++ gdb/testsuite/gdb.arch/arm-disp-step.S | 166 +++++++++++++++++++++--- gdb/testsuite/gdb.arch/arm-disp-step.exp | 210 ++++++++++++++++++++++++------- 3 files changed, 330 insertions(+), 57 deletions(-) (limited to 'gdb/testsuite') diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 132351a..477907d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2011-09-18 Yao Qi + + * gdb.arch/arm-disp-step.S (test_ldr_literal): Test for Thumb + instructions. + (test_adr_32bit, test_pop_pc): Likewise. + (test_ldr_literal_16, test_cbz_cbnz, test_adr): New test for + Thumb instructions. + * gdb.arch/arm-disp-step.exp (test_ldm_stm_pc): Match $gdb_prompt + in gdb_test_multiple. + (test_ldr_literal_16, test_cbz_cbnz, test_adr): New. + 2011-09-17 Yao Qi * lib/gdb.exp (can_single_step_to_signal_handler): New. diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.S b/gdb/testsuite/gdb.arch/arm-disp-step.S index fa69e31..1da7191 100644 --- a/gdb/testsuite/gdb.arch/arm-disp-step.S +++ b/gdb/testsuite/gdb.arch/arm-disp-step.S @@ -48,20 +48,32 @@ test_ret_end: bl test_ldm_stm_pc #endif - /* Test ldrX literal in ARM */ -#if !defined (__thumb__) + /* Test ldrX literal in ARM and Thumb-2 */ +#if !defined (__thumb__) || defined(__thumb2__) bl test_ldr_literal #endif - /* Test 32-bit adr in ARM */ -#if !defined(__thumb__) - bl test_adr_32bit + /* Test ldr literal in Thumb */ +#if defined(__thumb__) + bl test_ldr_literal_16 #endif -#if !defined(__thumb__) - bl test_pop_pc + /* Test cbnz/cbz in Thumb-2 */ +#if defined(__thumb2__) + bl test_cbz_cbnz #endif + /* Test adr in Thumb and Thumb-2 */ +#if defined(__thumb__) + bl test_adr +#endif + /* Test 32-bit adr in ARM and Thumb-2 */ +#if defined(__thumb2__) || !defined(__thumb__) + bl test_adr_32bit +#endif + + bl test_pop_pc + /* Test str in ARM mode and Thumb-2 */ #if !defined(__thumb__) bl test_str_pc @@ -136,8 +148,8 @@ test_ldm_stm_pc_ret: .word test_ldm_stm_pc_ret .size test_ldm_stm_pc, .-test_ldm_stm_pc #endif - -#if !defined (__thumb__) + +#if !defined (__thumb__) || defined(__thumb2__) .global test_ldr_literal .type test_ldr_literal, %function test_ldr_literal: @@ -154,8 +166,66 @@ test_ldr_literal_end: .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(__thumb__) +#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__) + .global test_adr + .code 16 + .thumb_func +test_adr: + adr r0, .L8 + nop + nop + nop +.L8: + .global test_adr_end +test_adr_end: + bx lr + .size test_adr, .-test_adr +#endif + +#if defined(__thumb2__) || !defined(__thumb__) .global test_adr_32bit #if defined(__thumb2__) .code 16 @@ -184,22 +254,90 @@ test_adr_32bit_end: #endif test_pop_pc: - ldr r1, .L5 + ldr r1, .L1_right + ldr r2, .L1_wrong #if defined(__thumb__) movs r0, #1 orrs r1, r0 + orrs r2, r0 #endif push {r1} - push {r1} + push {r2} .global test_pop_pc_1 test_pop_pc_1: pop {r1, pc} + +test_pop_pc_2_start: + ldr r1, .L2_right +#if defined(__thumb__) + movs r0, #1 + orrs r1, r0 +#endif + push {r1} + .global test_pop_pc_2 +test_pop_pc_2: + pop {pc} + + /* Test pop instruction with full register list. */ +test_pop_pc_3_start: + ldr r1, .L3_right + ldr r2, .L3_wrong +#if defined(__thumb__) + movs r0, #1 + orrs r1, r0 + orrs r2, r0 +#endif + push {r7} + push {r1} /* Push the right address so that PC will get it. */ + /* Push the wrong address so r0-r7 will get the wrong a ddress. If PC + is set from any of them, we can get a FAIL. */ + push {r2} + push {r2} + push {r2} + push {r2} + push {r2} + push {r2} + push {r2} + push {r2} +test_pop_pc_3: + pop {r0,r1,r2,r3,r4,r5,r6,r7,pc} .global test_pop_pc_ret test_pop_pc_ret: + pop {r7} bx lr + + .global test_pop_pc_1_right +test_pop_pc_1_right: + b test_pop_pc_2_start /* right */ + .global test_pop_pc_1_wrong +test_pop_pc_1_wrong: + b test_pop_pc_2_start /* wrong */ + .global test_pop_pc_2_right +test_pop_pc_2_right: + b test_pop_pc_3_start /* right */ + .global test_pop_pc_2_wrong +test_pop_pc_2_wrong: + b test_pop_pc_3_start /* wrong */ + .global test_pop_pc_3_right +test_pop_pc_3_right: + b test_pop_pc_ret /* right */ + .global test_pop_pc_3_wrong +test_pop_pc_3_wrong: + b test_pop_pc_ret /* wrong */ + .align 2 -.L5: - .word test_pop_pc_ret +.L1_right: + .word test_pop_pc_1_right +.L1_wrong: + .word test_pop_pc_1_wrong +.L2_right: + .word test_pop_pc_2_right +.L2_wrong: + .word test_pop_pc_2_wrong +.L3_right: + .word test_pop_pc_3_right +.L3_wrong: + .word test_pop_pc_3_wrong .size test_pop_pc, .-test_pop_pc #if !defined(__thumb__) diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.exp b/gdb/testsuite/gdb.arch/arm-disp-step.exp index 0427a04..994f08e 100644 --- a/gdb/testsuite/gdb.arch/arm-disp-step.exp +++ b/gdb/testsuite/gdb.arch/arm-disp-step.exp @@ -42,15 +42,17 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list # 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.*" { + -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { pass "break 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 + -re "No symbol.*\r\n$gdb_prompt $" { + pass "break test_ldm_stm_pc" + return 0 } } @@ -104,10 +106,38 @@ proc test_ldr_literal {} { ".*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" @@ -118,9 +148,10 @@ proc test_call_ret {} { "Breakpoint.*at.* file .*$srcfile, line.*" \ "break test_ret_end" - gdb_continue_to_breakpoint "continue to test_call_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 "continue to test_ret" \ + gdb_continue_to_breakpoint "test_ret" \ ".*bx lr.*" gdb_continue_to_breakpoint "continue to test_ret_end" \ ".*@ Location test_ret_end.*" @@ -158,7 +189,68 @@ 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 + 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.*" } @@ -167,28 +259,28 @@ proc test_adr_32bit {} { 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 - } + -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" + "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" + "Breakpoint.*at.* file .*$srcfile, line.*" \ + "break test_adr_32bit_end" gdb_continue_to_breakpoint "test_adr_32bit" \ - ".*adr.*r0\,.*\.L6.*" + ".*adr.*r0\,.*\.L6.*" gdb_continue_to_breakpoint "test_adr_32bit_after" \ - ".*adr.*r0\,.*\.L6.*" + ".*adr.*r0\,.*\.L6.*" gdb_continue_to_breakpoint "test_adr_32bit_end" \ - ".*bx lr.*" + ".*bx lr.*" } ######################################### @@ -196,27 +288,66 @@ proc test_adr_32bit {} { proc test_pop_pc {} { global srcfile gdb_test "break *test_pop_pc_1" \ - "Breakpoint.*at.* file .*$srcfile, line.*" \ - "break test_pop_pc" + "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" + "Breakpoint.*at.* file .*$srcfile, line.*" \ + "break test_pop_pc_ret" - gdb_continue_to_breakpoint "continue to test_pop_pc" \ - ".*b.*\{r1\, pc\}.*" + 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" \ - ".*bx lr.*" + ".*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.*" { + -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" { pass "break test_str_pc" } - -re "No symbol.*" { + -re "No symbol.*\r\n$gdb_prompt $" { pass "break test_str_pc" return } @@ -261,20 +392,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 @@ -285,11 +402,18 @@ 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. -- cgit v1.1