This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Fix PR tdep/12352: Handle str pc, [Rd, #imm] in displaced stepping
- From: Yao Qi <yao at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 29 Dec 2010 00:41:39 +0800
- Subject: [patch] Fix PR tdep/12352: Handle str pc, [Rd, #imm] in displaced stepping
When I read arm-tdep.c:copy_ldr_str_ldrb_strb, I feel pretty hard to
understand two lines of code,
dsc->modinsn[0] = 0xe58ff014; /* str pc, [pc, #20]. */
dsc->modinsn[1] = 0xe59f4010; /* ldr r4, [pc, #16]. */
Shall program get SIGSEGV when executing `str pc, [pc, #20]' during
displaced stepping? A simple test case confirmed my guess, which is
included in arm-disp-step.S in this patch.
If it is a bug here, this patch is to address it. These two lines of
code is to compute the offset of `str pc'. In this patch, we can do
this in a different way,
str pc, [sp, #-4]
ldr r4, [sp, #-4]
OK for mainline and 7.2 branch?
--
Yao (éå)
gdb/
PR tdep/12352
* arm-tdep.c (copy_ldr_str_ldrb_strb): Replace PC with SP in order to
store PC value on stack instead of text section.
gdb/testsuite/
PR tdep/12352
* gdb.arch/arm-disp-step.S : New test for str instruction.
* gdb.arch/arm-disp-step.exp : Likewise.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 1f05b7a..ad9b1f4 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -5152,7 +5152,7 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn,
scratch+12: add r4, r4, #8 (r4 = offset)
scratch+16: add r0, r0, r4
scratch+20: str r0, [r2, #imm] (or str r0, [r2, r3])
- scratch+24: <temp>
+ temp can be [sp, -4]
Otherwise we don't know what value to write for PC, since the offset is
architecture-dependent (sometimes PC+8, sometimes PC+12). */
@@ -5177,8 +5177,8 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn,
/* We need to use r4 as scratch. Make sure it's restored afterwards. */
dsc->u.ldst.restore_r4 = 1;
- dsc->modinsn[0] = 0xe58ff014; /* str pc, [pc, #20]. */
- dsc->modinsn[1] = 0xe59f4010; /* ldr r4, [pc, #16]. */
+ dsc->modinsn[0] = 0xe50df004; /* str pc, [sp, #-4]*/
+ dsc->modinsn[1] = 0xe51d4004; /* ldr r4, [sp, #-4]*/
dsc->modinsn[2] = 0xe044400f; /* sub r4, r4, pc. */
dsc->modinsn[3] = 0xe2844008; /* add r4, r4, #8. */
dsc->modinsn[4] = 0xe0800004; /* add r0, r0, r4. */
diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.S b/gdb/testsuite/gdb.arch/arm-disp-step.S
index d748718..1aa7df1 100644
--- a/gdb/testsuite/gdb.arch/arm-disp-step.S
+++ b/gdb/testsuite/gdb.arch/arm-disp-step.S
@@ -48,6 +48,10 @@ test_ret_end:
bl test_ldm_stm_pc
#endif
+ /* Test str in ARM mode and Thumb-2 */
+#if !defined(__thumb__)
+ bl test_str_pc
+#endif
/* Return */
mov sp, r7
sub sp, sp, #4
@@ -118,3 +122,17 @@ 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 (__thumb2__)
+ .code 16
+ .thumb_func
+#endif
+ .global test_str_pc
+ .type test_str_pc, %function
+test_str_pc:
+ str pc, [sp, #-4]
+ .global test_str_pc_end
+test_str_pc_end:
+ bx lr
+#endif
diff --git a/gdb/testsuite/gdb.arch/arm-disp-step.exp b/gdb/testsuite/gdb.arch/arm-disp-step.exp
index 826f728..f2df388 100644
--- a/gdb/testsuite/gdb.arch/arm-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/arm-disp-step.exp
@@ -126,6 +126,29 @@ proc test_ldr_from_pc {} {
".*bx lr.*"
}
+###########################################
+
+proc test_str_pc {} {
+ global srcfile
+ gdb_test_multiple "break *test_str_pc" "break test_str_pc" {
+ -re "Breakpoint.*at.* file .*$srcfile, line.*" {
+ pass "break test_str_pc"
+ }
+ -re "No symbol.*" {
+ pass "break test_str_pc"
+ return
+ }
+ }
+ gdb_test "break *test_str_pc_end" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "break test_str_pc_end"
+
+ gdb_continue_to_breakpoint "continue to test_str_pc" \
+ ".*str.*pc\,.*\[sp, #-4\].*"
+ gdb_continue_to_breakpoint "continue to test_str_pc_end" \
+ ".*bx lr.*"
+}
+
# Get things started.
clean_restart ${testfile}
@@ -165,6 +188,7 @@ test_ldr_from_pc
test_ldm_stm_pc
+test_str_pc
##########################################
# Done, run program to exit.