From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28327 invoked by alias); 28 Aug 2014 07:37:35 -0000 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 Received: (qmail 28311 invoked by uid 89); 28 Aug 2014 07:37:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Aug 2014 07:37:32 +0000 Received: from svr-orw-fem-05.mgc.mentorg.com ([147.34.97.43]) by relay1.mentorg.com with esmtp id 1XMuGv-0005uF-6l from Yao_Qi@mentor.com ; Thu, 28 Aug 2014 00:37:29 -0700 Received: from GreenOnly (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 28 Aug 2014 00:37:28 -0700 From: Yao Qi To: Pedro Alves CC: Subject: Re: [PATCH] arm software watchpoint: return to epilogue References: <1407295090-17296-1-git-send-email-yao@codesourcery.com> <53FDB9FD.60900@redhat.com> Date: Thu, 28 Aug 2014 07:37:00 -0000 In-Reply-To: <53FDB9FD.60900@redhat.com> (Pedro Alves's message of "Wed, 27 Aug 2014 11:59:09 +0100") Message-ID: <87zjepf4qd.fsf@codesourcery.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2014-08/txt/msg00592.txt.bz2 Pedro Alves writes: > This gdbarch hook's name is a bit misleading -- your comment above kind > of makes it sound like the patch is doing some kind of target specific I write down a lot to describe the problem on thumb mode and it gives a feeling that it is a target specific hack. > hack, while this is exactly how the gdbarch hook is specified: > > # A target might have problems with watchpoints as soon as the stack > # frame of the current function has been destroyed. This mostly happens > # as the first action in a funtion's epilogue. in_function_epilogue_p() > # is defined to return a non-zero value if either the given addr is one > ^^^^^^ > # instruction after the stack destroying instruction up to the trailing > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > # return instruction or if we can figure out that the stack frame has > # already been invalidated regardless of the value of addr. Targets > # which don't suffer from that problem could just let this functionality > # untouched. > m:int:in_function_epilogue_p:CORE_ADDR addr:addr:0:generic_in_function_ep= ilogue_p::0 > Yes, this gdbarch hook's name is misleading. How about renaming it to stack_frame_destroyed_p? >> The patch is tested in arm-none-eabi and arm-none-linux-gnueabi with >> various multilibs. OK to apply? > > This is OK with Will's comment addressed. The changelog entry is updated, and the assignment to found_stack_adjust is removed from the patch. Patch below is pushed in. --=20 Yao (=E9=BD=90=E5=B0=A7) Author: Yao Qi Date: Fri Aug 1 11:26:16 2014 +0800 arm software watchpoint: return to epilogue =20=20=20=20 Hi, This patch is to handle a software watchpoint case that program returns to caller's epilogue, and it causes the fail in thumb mode, =20=20=20=20 finish^M Run till exit from #0 func () at gdb/testsuite/gdb.base/watchpoint-con= d-gone.c:26^M 0x000001f6 in jumper ()^M (gdb) FAIL: gdb.base/watchpoint-cond-gone.exp: Catch the no longer vali= d watchpoint =20=20=20=20 In the test, jumper calls func, and programs returns from func to jumper's epilogue, IOW, the branch instruction is the last instruction of jumper's function body. =20=20=20=20 jumper: ..... 0x000001f2 <+10>: bl 0x200 [1] <---- indirect call to func 0x000001f6 <+14>: mov sp, r7 [2] <---- start of the epilogue 0x000001f8 <+16>: add sp, #8 0x000001fa <+18>: pop {r7} 0x000001fc <+20>: pop {r0} 0x000001fe <+22>: bx r0 =20=20=20=20 When the inferior returns from func back to jumper, it is expected that an expression of a software watchpoint becomes out-of-scope. GDB validates the expression by checking the corresponding frame, but this check is guarded by gdbarch_in_function_epilogue_p. See breakpoint.c:watchpoint_check. =20=20=20=20 It doesn't work in this case, because program returns from func's epilogue back to jumper's epilogue [2], GDB thinks the program is still within the epilogue, but in fact it goes to a different one. When PC points at [2], the sp-restore instruction is to be executed, so the stack frame isn't destroyed yet and we can still use the frame mechanism reliably. =20=20=20=20 Note that when PC points to the first instruction of restoring SP, it is part of epilogue, but we still return zero. When goes to the next instruction, the backward scan will still match the epilogue sequence correctly. The reason for doing this is to handle the "return-to-epilogue" case. =20=20=20=20 What this patch does is to restrict the epilogue matching that let GDB think the first SP restore instruction isn't part of the epilogue, and fall back to use frame mechanism. We set 'found_stack_adjust' zero before backward scan, and we've done this for arm mode counterpart (arm_in_function_epilogue_p) too. =20=20=20=20 The patch is tested in arm-none-eabi and arm-none-linux-gnueabi with various multilibs. OK to apply? =20=20=20=20 gdb: =20=20=20=20 2014-08-28 Yao Qi =20=20=20=20 * arm-tdep.c (thumb_in_function_epilogue_p): Don't set found_stack_adjust in forward scan. Remove condition check on found_stack_adjust which is always true. Indent the code. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c7ccb41..b6d8469 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2014-08-28 Yao Qi =20 + * arm-tdep.c (thumb_in_function_epilogue_p): Don't set + found_stack_adjust in forward scan. Remove condition check + on found_stack_adjust which is always true. Indent the code. + +2014-08-28 Yao Qi + * dwarf2read.c (dwarf_decode_lines): Update declaration. (handle_DW_AT_stmt_list): Remove comment about WANT_LINE_INFO. (dwarf_decode_lines): Remove argument diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 9bc6507..f9feb52 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3273,7 +3273,6 @@ thumb_in_function_epilogue_p (struct gdbarch *gdbarch= , CORE_ADDR pc) found_return =3D 1; else if (thumb_instruction_restores_sp (insn)) { - found_stack_adjust =3D 1; if ((insn & 0xfe00) =3D=3D 0xbd00) /* pop */ found_return =3D 1; } @@ -3287,20 +3286,18 @@ thumb_in_function_epilogue_p (struct gdbarch *gdbar= ch, CORE_ADDR pc) =20 if (insn =3D=3D 0xe8bd) /* ldm.w sp!, */ { - found_stack_adjust =3D 1; if (insn2 & 0x8000) /* include PC. */ found_return =3D 1; } else if (insn =3D=3D 0xf85d /* ldr.w , [sp], #4 */ && (insn2 & 0x0fff) =3D=3D 0x0b04) { - found_stack_adjust =3D 1; if ((insn2 & 0xf000) =3D=3D 0xf000) /* is PC. */ found_return =3D 1; } else if ((insn & 0xffbf) =3D=3D 0xecbd /* vldm sp!, */ && (insn2 & 0x0e00) =3D=3D 0x0a00) - found_stack_adjust =3D 1; + ; else break; } @@ -3317,27 +3314,24 @@ thumb_in_function_epilogue_p (struct gdbarch *gdbar= ch, CORE_ADDR pc) a 32-bit instruction. This is just a heuristic, so we do not worry too much about false positives. */ =20 - if (!found_stack_adjust) - { - if (pc - 4 < func_start) - return 0; - if (target_read_memory (pc - 4, buf, 4)) - return 0; - - insn =3D extract_unsigned_integer (buf, 2, byte_order_for_code); - insn2 =3D extract_unsigned_integer (buf + 2, 2, byte_order_for_code); + if (pc - 4 < func_start) + return 0; + if (target_read_memory (pc - 4, buf, 4)) + return 0; =20 - if (thumb_instruction_restores_sp (insn2)) - found_stack_adjust =3D 1; - else if (insn =3D=3D 0xe8bd) /* ldm.w sp!, */ - found_stack_adjust =3D 1; - else if (insn =3D=3D 0xf85d /* ldr.w , [sp], #4 */ - && (insn2 & 0x0fff) =3D=3D 0x0b04) - found_stack_adjust =3D 1; - else if ((insn & 0xffbf) =3D=3D 0xecbd /* vldm sp!, */ - && (insn2 & 0x0e00) =3D=3D 0x0a00) - found_stack_adjust =3D 1; - } + insn =3D extract_unsigned_integer (buf, 2, byte_order_for_code); + insn2 =3D extract_unsigned_integer (buf + 2, 2, byte_order_for_code); + + if (thumb_instruction_restores_sp (insn2)) + found_stack_adjust =3D 1; + else if (insn =3D=3D 0xe8bd) /* ldm.w sp!, */ + found_stack_adjust =3D 1; + else if (insn =3D=3D 0xf85d /* ldr.w , [sp], #4 */ + && (insn2 & 0x0fff) =3D=3D 0x0b04) + found_stack_adjust =3D 1; + else if ((insn & 0xffbf) =3D=3D 0xecbd /* vldm sp!, */ + && (insn2 & 0x0e00) =3D=3D 0x0a00) + found_stack_adjust =3D 1; =20 return found_stack_adjust; }