From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44B3BC00144 for ; Fri, 29 Jul 2022 05:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234360AbiG2Fi6 (ORCPT ); Fri, 29 Jul 2022 01:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiG2Fi4 (ORCPT ); Fri, 29 Jul 2022 01:38:56 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 661CB1F62E for ; Thu, 28 Jul 2022 22:38:54 -0700 (PDT) Received: from [10.130.0.63] (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxz9JmcuNiJipBAA--.27572S3; Fri, 29 Jul 2022 13:38:47 +0800 (CST) Subject: Re: [PATCH 2/3] LoongArch: Add prologue unwinder support To: Youling Tang , Huacai Chen Cc: WANG Xuerui , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Jiaxun Yang , hejinyang@loongson.cn References: <20220728140519.5420-1-zhangqing@loongson.cn> <20220728140519.5420-2-zhangqing@loongson.cn> From: zhangqing Message-ID: Date: Fri, 29 Jul 2022 13:38:46 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf9Dxz9JmcuNiJipBAA--.27572S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tF4rXFy3Xr47CF4DWF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List: linux-kernel@vger.kernel.org On 2022/7/29 上午10:03, Youling Tang wrote: > > > On 07/28/2022 10:05 PM, Qing Zhang wrote: >> It unwind the stack frame based on prologue code analyze. >> CONFIG_KALLSYMS is needed, at least the address and length >> of each function. >> >> Three stages when we do unwind, >>   (1)unwind_start(), the prapare of unwinding, fill unwind_state. >>   (2)unwind_done(), judge whether the unwind process is finished or not. >>   (3)unwind_next_frame(), unwind the next frame. >> >> Dividing unwinder helps to add new unwinders in the future, eg: >> unwind_frame, unwind_orc .etc >> >> Signed-off-by: Qing Zhang >> >> + >> +    while (ip < ip_end) { >> +        if (is_ra_save_ins(ip)) { >> +            frame_ra = ip->reg2i12_format.immediate; > Because the immediate member in struct reg2i12_format is defined as an > unsigned type, the value obtained by frame_ra here can only be a > positive number. > >> +            break; >> +        } >> +        if (is_branch_insn(*ip)) >> +            break; >> +        ip++; >> +    } >> + >> +    if (frame_ra < 0) { > In addition to judging whether the initial value of frame_ra is > negative, we also want to judge whether the previously assigned > frame_ra is negative. > > Save the ra value to the stack in the prologue, offset must be a > positive number, so we can add another judgment to is_ra_save_ins, the > code is as follows: > +static inline bool is_ra_save_ins(union loongarch_instruction *ip) > +{ > +    /* st.d $ra, $sp, offset */ > +    return ip->reg2i12_format.opcode == std_op && > +        ip->reg2i12_format.rj == LOONGARCH_GPR_SP && > +        ip->reg2i12_format.rd == LOONGARCH_GPR_RA && > +        !(ip->reg2i12_format.immediate & (1 << 11)); > +} Hi, youling you are right and I will send v2. Thanks, Qing