From patchwork Wed Apr 9 08:42:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Zhu X-Patchwork-Id: 438 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 79C35360060 for ; Wed, 9 Apr 2014 01:42:29 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id 2BE7A4709701; Wed, 9 Apr 2014 01:42:29 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 090C446F8DBF for ; Wed, 9 Apr 2014 01:42:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=KXPd1arzhvTEu6gL l/mN6uaLWfSR2IUITc52wrZGiVZMeP/E8TxEcKCLa8IhAU9xzG0S8mThkU9a00z9 orEOtYAKmSTkjLN8fhf+8zGcGzxjiIy5MlLsqg0IeBVbKYsHxW/q403N1Mb/I1iQ M6UotO95NQl2cPn1QlkFz4oTzE8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=default; bh=D5ppkMIOIT7x6LNWbEnfjI dDe1c=; b=Ryc2yyeScYJw6OpqIBtW++p9vg0hhYcT9fgNbLHrVW+8YKYPai8Bsv m2gWwtp33KXAHH0zv8L+CD30q5CEuVxRr7iVIAzAvhp6ioyM+SJIMneWGE5gUvMm SwOZds8ph5TfJAz25pHVYPH5T/Dq2opW8k6dru7Q47opol8VQt2xw= Received: (qmail 3079 invoked by alias); 9 Apr 2014 08:42:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 2922 invoked by uid 89); 9 Apr 2014 08:42:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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; Wed, 09 Apr 2014 08:42:20 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1WXo5I-0003JM-Py from Hui_Zhu@mentor.com ; Wed, 09 Apr 2014 01:42:16 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 9 Apr 2014 01:42:16 -0700 Received: from localhost.localdomain (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.2.247.3; Wed, 9 Apr 2014 01:42:15 -0700 Message-ID: <534507E2.1000906@mentor.com> Date: Wed, 9 Apr 2014 16:42:10 +0800 From: Hui Zhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Marcus Shawcroft CC: Yao Qi , gdb-patches ml Subject: Re: [PATCH/v2] Fix PR backtrace/16558: GDB Aarch64 signal frame unwinder issue References: <533295A3.90907@mentor.com> In-Reply-To: <533295A3.90907@mentor.com> X-Forwarded-Message-Id: <533295A3.90907@mentor.com> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Ping. Thanks, Hui -------- Original Message -------- Subject: Re: [PATCH/v2] Fix PR backtrace/16558: GDB Aarch64 signal frame unwinder issue Date: Wed, 26 Mar 2014 16:53:55 +0800 From: Hui Zhu To: Marcus Shawcroft CC: gdb-patches ml , Yao Qi On 03/20/14 00:01, Marcus Shawcroft wrote: > On 5 March 2014 06:33, Hui Zhu wrote: > >> /* Signal frame handling. >> - +----------+ ^ >> - | saved lr | | >> - +->| saved fp |--+ >> - | | | >> - | | | >> - | +----------+ >> - | | saved lr | >> - +--| saved fp | >> - ^ | | >> - | | | >> - | +----------+ >> - ^ | | >> - | | signal | >> - | | | >> - | | saved lr |-->interrupted_function_pc >> - +--| saved fp | >> - | +----------+ >> - | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc >> 0) >> - +--| saved fp |<- FP >> - | | >> - | |<- SP >> - +----------+ >> - > > Better no diagram than a broken diagram, but wouldn't it be better to > fix the diagram rather than just remove the whole comment? > Add the pic back according to Yao's pic: +------------+ ^ | saved lr | | +->| saved fp |--+ | | | | | | | +------------+ | | saved lr | +--| saved fp | ^ | | | | | | +------------+ ^ | | | | signal | | | | SIGTRAMP_FRAME (struct rt_sigframe) | | saved regs | +--| saved sp |--> interrupted_sp | | saved pc |--> interrupted_pc | | | | +------------+ | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0) +--| saved fp |<- FP | | NORMAL_FRAME | |<- SP +------------+ I removed "saved lr |-->interrupted_function_pc". Because the lr didn't save the address of of interrupted_function. It saved the caller address of interrupted_function. This is not a special behavior of ABI. So I think It does not need to be added here. >> On signal delivery, the kernel will create a signal handler stack >> - frame and setup the return address in LR to point at restorer stub. >> + frame in arch/arm64/kernel/signal.c:setup_rt_frame. > > I don;t think documenting the name of a function in a different source > tree here in a comment is a good idea, should the kernel guys decide > to refactor that code in the future the comment will be left bit > rotten. It would be better to say what we are expecting to find on > the stack and in the registers rather than who we are expecting to > setup the stack and registers. > >> The signal stack frame is defined by: >> struct rt_sigframe >> @@ -123,8 +100,8 @@ >> d28015a8 movz x8, #0xad >> d4000001 svc #0x0 >> - We detect signal frames by snooping the return code for the restorer >> - instruction sequence. >> + This is a system call sys_rt_sigreturn. The kernel will detect signal >> + frame from sp and call arch/arm64/kernel/signal.c:restore_sigframe. > > Likewise. I added them back. > >> The handler then needs to recover the saved register set from >> ucontext.uc_mcontext. */ >> @@ -146,7 +123,6 @@ aarch64_linux_sigframe_init (const struc >> >> { >> struct gdbarch *gdbarch = get_frame_arch (this_frame); >> CORE_ADDR sp = get_frame_register_unsigned (this_frame, >> AARCH64_SP_REGNUM); >> - CORE_ADDR fp = get_frame_register_unsigned (this_frame, >> AARCH64_FP_REGNUM); >> CORE_ADDR sigcontext_addr = >> sp >> + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET >> @@ -160,12 +136,14 @@ aarch64_linux_sigframe_init (const struc >> >> cd sigcontext_addr + >> AARCH64_SIGCONTEXT_XO_OFFSET >> + i * AARCH64_SIGCONTEXT_REG_SIZE); >> } >> + trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, >> + sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET >> + + 31 * AARCH64_SIGCONTEXT_REG_SIZE); >> + trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, >> + sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET >> + + 32 * AARCH64_SIGCONTEXT_REG_SIZE); >> - trad_frame_set_reg_addr (this_cache, AARCH64_FP_REGNUM, fp); >> - trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM, fp + 8); >> - trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, fp + 8); >> - >> - trad_frame_set_id (this_cache, frame_id_build (fp, func)); >> + trad_frame_set_id (this_cache, frame_id_build (sp, func)); > > The comments above aside, I think the actual functional change in this > patch looks reasonable. However I cannot approve patches in GDB. > Thanks for your help. Best, Hui 2014-03-26 Hui Zhu Yao Qi PR backtrace/16558 * aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Update comments and change address of sp and pc. --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -53,28 +53,30 @@ /* Signal frame handling. - +----------+ ^ - | saved lr | | - +->| saved fp |--+ - | | | - | | | - | +----------+ - | | saved lr | - +--| saved fp | - ^ | | - | | | - | +----------+ - ^ | | - | | signal | - | | | - | | saved lr |-->interrupted_function_pc - +--| saved fp | - | +----------+ - | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0) - +--| saved fp |<- FP - | | - | |<- SP - +----------+ + +------------+ ^ + | saved lr | | + +->| saved fp |--+ + | | | + | | | + | +------------+ + | | saved lr | + +--| saved fp | + ^ | | + | | | + | +------------+ + ^ | | + | | signal | + | | | SIGTRAMP_FRAME (struct rt_sigframe) + | | saved regs | + +--| saved sp |--> interrupted_sp + | | saved pc |--> interrupted_pc + | | | + | +------------+ + | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0) + +--| saved fp |<- FP + | | NORMAL_FRAME + | |<- SP + +------------+ On signal delivery, the kernel will create a signal handler stack frame and setup the return address in LR to point at restorer stub. @@ -123,6 +125,8 @@ d28015a8 movz x8, #0xad d4000001 svc #0x0 + This is a system call sys_rt_sigreturn. + We detect signal frames by snooping the return code for the restorer instruction sequence. @@ -146,7 +150,6 @@ aarch64_linux_sigframe_init (const struc { struct gdbarch *gdbarch = get_frame_arch (this_frame); CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); - CORE_ADDR fp = get_frame_register_unsigned (this_frame, AARCH64_FP_REGNUM); CORE_ADDR sigcontext_addr = sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET @@ -160,12 +163,14 @@ aarch64_linux_sigframe_init (const struc sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET + i * AARCH64_SIGCONTEXT_REG_SIZE); } + trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, + sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET + + 31 * AARCH64_SIGCONTEXT_REG_SIZE); + trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, + sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET + + 32 * AARCH64_SIGCONTEXT_REG_SIZE); - trad_frame_set_reg_addr (this_cache, AARCH64_FP_REGNUM, fp); - trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM, fp + 8); - trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, fp + 8); - - trad_frame_set_id (this_cache, frame_id_build (fp, func)); + trad_frame_set_id (this_cache, frame_id_build (sp, func)); } static const struct tramp_frame aarch64_linux_rt_sigframe =