From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30930 invoked by alias); 15 Feb 2011 08:11:35 -0000 Received: (qmail 30912 invoked by uid 22791); 15 Feb 2011 08:11:30 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Feb 2011 08:11:25 +0000 Received: (qmail 26102 invoked from network); 15 Feb 2011 08:11:23 -0000 Received: from unknown (HELO ?192.168.0.101?) (yao@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Feb 2011 08:11:23 -0000 Message-ID: <4D5A3528.5000607@codesourcery.com> Date: Tue, 15 Feb 2011 10:55:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Ulrich Weigand CC: Richard Earnshaw , gdb-patches@sourceware.org, julian@codesourcery.com Subject: Re: [patch] Fix PR tdep/12352: Handle str pc, [Rd, #imm] in displaced stepping References: <201102141416.p1EEGPxC014774@d06av02.portsmouth.uk.ibm.com> In-Reply-To: <201102141416.p1EEGPxC014774@d06av02.portsmouth.uk.ibm.com> Content-Type: multipart/mixed; boundary="------------030909020202060405060708" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00316.txt.bz2 This is a multi-part message in MIME format. --------------030909020202060405060708 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-length: 1083 On 02/14/2011 10:16 PM, Ulrich Weigand wrote: > I think this is wrong: the "pipeline offset" of 8 bytes is already > added to the PC value when it is retrieved by displaced_read_reg > (this applies to any use of PC as source operand in any instruction). > > The special case relating to STR PC is about an optional *additional* > offset of 4 bytes (such that PC + 12 instead of PC + 8 is stored); > the "offset" value computed by this routine should therefore be > 0 or 4 (not 8 or 12). Thanks for the explanation. > Maybe it would be good to add a test that verifies the value > stored under displaced stepping is identical to the value > stored when running the instruction natively? In my new patch, the test case is revised to execute instructions below twice, str pc, [sp, #-4] ldr rN, [sp, #-4] sub rN, rN, pc the first `str' instruction is executed with displaced stepping, while the second `str' is executed without displaced stepping. Then, values of two registers are compared to make sure they should be the same. -- Yao (齐尧) --------------030909020202060405060708 Content-Type: text/x-patch; name="pr12352-0215.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr12352-0215.patch" Content-length: 5465 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..440fda5 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -5146,16 +5146,24 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, /* To write PC we can do: - scratch+0: str pc, temp (*temp = scratch + 8 + offset) - scratch+4: ldr r4, temp - scratch+8: sub r4, r4, pc (r4 = scratch + 8 + offset - scratch - 8 - 8) - 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: + Before this sequence of instructions: + r0 is the PC value got from displaced_read_reg, so r0 = from + 8; + r2 is the Rn value got from dispalced_read_reg. + + Insn1: push {pc} Write address of STR instruction + offset on stack + Insn2: pop {r4} Read it back from stack, r4 = addr(Insn1) + offset + Insn3: sub r4, r4, pc r4 = addr(Insn1) + offset - pc + = addr(Insn1) + offset - addr(Insn3) - 8 + = offset - 16 + Insn4: add r4, r4, #8 r4 = offset - 8 + Insn5: add r0, r0, r4 r0 = from + 8 + offset - 8 + = from + offset + Insn6: str r0, [r2, #imm] (or str r0, [r2, r3]) Otherwise we don't know what value to write for PC, since the offset is - architecture-dependent (sometimes PC+8, sometimes PC+12). */ + architecture-dependent (sometimes PC+8, sometimes PC+12). More details + of this can be found in Section "Saving from r15" in + http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204g/Cihbjifh.html */ if (load || rt != 15) { @@ -5176,9 +5184,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] = 0xe92d8000; /* push {pc} */ + dsc->modinsn[1] = 0xe8bd0010; /* pop {r4} */ 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..4b637d7 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,36 @@ 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] + ldr r0, [sp, #-4] + sub r0, r0, pc + /* compute offset again without displaced stepping. */ + str pc, [sp, #-4] + ldr r1, [sp, #-4] + sub r1, r1, pc + + /* r0 should be equal to r1. */ + cmp r0, r1 + bne pc_offset_wrong + + .global pc_offset_right +pc_offset_right: + b test_str_pc_end + + .global pc_offset_wrong +pc_offset_wrong: + nop + + .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..80e4050 100644 --- a/gdb/testsuite/gdb.arch/arm-disp-step.exp +++ b/gdb/testsuite/gdb.arch/arm-disp-step.exp @@ -126,6 +126,42 @@ 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" + + # 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} @@ -165,6 +201,7 @@ test_ldr_from_pc test_ldm_stm_pc +test_str_pc ########################################## # Done, run program to exit. --------------030909020202060405060708--