From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out29-194.mail.aliyun.com (out29-194.mail.aliyun.com [115.124.29.194]) by sourceware.org (Postfix) with ESMTPS id 0BCAF3858C78 for ; Tue, 1 Mar 2022 07:32:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0BCAF3858C78 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=c-sky.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=c-sky.com X-Alimail-AntiSpam: AC=CONTINUE; BC=0.8293142|0.4321795; BR=01201311R551S27rulernew998_84748_2000303; CH=blue; DM=|SPAM|false|; DS=CONTINUE|ham_system_inform|0.0107508-0.00031517-0.988934; FP=0|0|0|0|0|-1|-1|-1; HT=ay29a033018047198; MF=lifang_xia@c-sky.com; NM=1; PH=DS; RN=4; RT=4; SR=0; TI=SMTPD_---.Mxi0gRt_1646119962; Received: from PF1K7H4W.hz.ali.com(mailfrom:lifang_xia@c-sky.com fp:SMTPD_---.Mxi0gRt_1646119962) by smtp.aliyun-inc.com(33.37.72.11); Tue, 01 Mar 2022 15:32:43 +0800 From: Lifang Xia To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, palmer@dabbelt.com, Lifang Xia Subject: [PATCH] [RISC-V]: Handling optimized prologue Date: Tue, 1 Mar 2022 15:32:31 +0800 Message-Id: <20220301073231.1927-1-lifang_xia@c-sky.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 07:32:49 -0000 From: Lifang Xia The optimizer might shove anything into the prologue, if we build up cache (cache != NULL) from scanning prologue, we just skip what we don't recognize and scan further to make cache as complete as possible. However, if we skip prologue, we'll stop immediately on unrecognized instruction. The case is: ---------------------------- Disassembly of section .text: 0000000000010078 : 10078: 00100513 li a0,1 1007c: 008000ef jal ra,10084 10080: 00008067 ret 0000000000010084 : 10084: 00051263 bnez a0,10088 10088: ff010113 addi sp,sp,-16 1008c: 00813023 sd s0,0(sp) 10090: 00050413 mv s0,a0 10094: 00113423 sd ra,8(sp) 10098: 014000ef jal ra,100ac 1009c: 00813083 ld ra,8(sp) 100a0: 00013403 ld s0,0(sp) 100a4: 01010113 addi sp,sp,16 100a8: 00008067 ret 00000000000100ac : 100ac: 00000013 nop >> 100b0: 00008067 ret ---------------------- (gdb) bt #0 0x00000000000100b0 in aaa () #1 0x000000000001009c in bar () Backtrace stopped: frame did not save the PC gdb/ * riscv-tdep.c (riscv_scan_prologue): Keep scaning if cache is not NULL. --- gdb/riscv-tdep.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 886996c..e46d441 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -1987,7 +1987,15 @@ riscv_scan_prologue (struct gdbarch *gdbarch, else { end_prologue_addr = cur_pc; - break; + + /* The optimizer might shove anything into the prologue, if + we build up cache (cache != NULL) from scanning prologue, + we just skip what we don't recognize and scan further to + make cache as complete as possible. However, if we skip + prologue, we'll stop immediately on unrecognized + instruction. */ + if (cache == NULL) + break; } } -- 2.7.4