From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iKQnBVpJD2MTZjAAWB0awg (envelope-from ) for ; Wed, 31 Aug 2022 07:43:22 -0400 Received: by simark.ca (Postfix, from userid 112) id 014321E4A7; Wed, 31 Aug 2022 07:43:21 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=cKcHpGM6; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A3EB01E21F for ; Wed, 31 Aug 2022 07:43:19 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79688383E075 for ; Wed, 31 Aug 2022 11:43:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79688383E075 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661946198; bh=ogv5weAmwG1Dmh2JkMcklw/Ja4I3F+eJ5GFHab897s4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=cKcHpGM6FETyyPKpnnLY0vJl4qoNU8n2VE+f1XnVkaQgBHP1tcEHn1LrPDHTLw3kd YdqdUwdnNcl77jgK6p2rIqg8MhO9DFq5qFIAz+sH39pgE3QnHLgmwJ90bft1lxdbtf +k5ItHk3Rc4m+T1S5RsjqAltFTyuRga5z5tASMEs= Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by sourceware.org (Postfix) with ESMTPS id 679453858C2D for ; Wed, 31 Aug 2022 11:42:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 679453858C2D X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R241e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046051; MF=jiangshuai_li@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0VNr8h4A_1661946172; Received: from lijsh-VirtualBox.hz.ali.com(mailfrom:jiangshuai_li@linux.alibaba.com fp:SMTPD_---0VNr8h4A_1661946172) by smtp.aliyun-inc.com; Wed, 31 Aug 2022 19:42:53 +0800 To: gdb-patches@sourceware.org Subject: [PATCH] gdb/csky add unwinder for long branch cases Date: Wed, 31 Aug 2022 19:42:50 +0800 Message-Id: <20220831114250.7276-1-jiangshuai_li@linux.alibaba.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Jiangshuai Li via Gdb-patches Reply-To: Jiangshuai Li Cc: Jiangshuai Li Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" There are two sequences of instructions for long branch: 1. jmpi [pc+4] //insn code: 0xeac00001 .long addr 2. lrw t1, [pc+8] //insn code: 0xea8d0002 jmp t1 //insn code: 0x7834 nop //insn code: 0x6c03 .long addr --- gdb/csky-tdep.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----- gdb/csky-tdep.h | 5 +++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c index ba53c1b10ca..3cd7a775f8d 100644 --- a/gdb/csky-tdep.c +++ b/gdb/csky-tdep.c @@ -2358,21 +2358,71 @@ static const struct frame_unwind csky_unwind_cache = { NULL }; +static CORE_ADDR +csky_check_long_branch (struct frame_info *frame, CORE_ADDR pc) +{ + gdb_byte buf[8]; + struct gdbarch *gdbarch = get_frame_arch (frame); + enum bfd_endian byte_order_for_code + = gdbarch_byte_order_for_code (gdbarch); + + if (target_read_memory (pc, buf, 8) == 0) + { + unsigned int data0 + = extract_unsigned_integer (buf, 4, byte_order_for_code); + unsigned int data1 + = extract_unsigned_integer (buf + 4, 4, byte_order_for_code); + + /* Case: jmpi [pc+4] : 0xeac00001 + .long addr */ + if (data0 == CSKY_JMPI_PC_4) + return data1; + + /* Case: lrw t1, [pc+8] : 0xea8d0002 + jmp t1 : 0x7834 + nop : 0x6c03 + .long addr */ + if ((data0 == CSKY_LRW_T1_PC_8) && (data1 == CSKY_JMP_T1_VS_NOP)) + { + if (target_read_memory (pc + 8, buf, 4) == 0) + return extract_unsigned_integer (buf, 4, byte_order_for_code); + } + return 0; + } + + return 0; +} static int csky_stub_unwind_sniffer (const struct frame_unwind *self, - struct frame_info *this_frame, - void **this_prologue_cache) + struct frame_info *this_frame, + void **this_prologue_cache) { - CORE_ADDR addr_in_block; + CORE_ADDR addr_in_block, pc; + gdb_byte dummy[4]; + const char *name; + CORE_ADDR start_addr; + /* Get pc */ addr_in_block = get_frame_address_in_block (this_frame); + pc = get_frame_pc (this_frame); - if (find_pc_partial_function (addr_in_block, NULL, NULL, NULL) == 0 - || in_plt_section (addr_in_block)) + if (in_plt_section (addr_in_block) + || target_read_memory (pc, dummy, 4) != 0) return 1; + /* Find the starting address and name of the function containing the PC. */ + if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) + { + start_addr = csky_check_long_branch (this_frame, pc); + /* if not long branch, return 0. */ + if (start_addr != 0) + return 1; + + return 0; + } + return 0; } diff --git a/gdb/csky-tdep.h b/gdb/csky-tdep.h index f845b9ab744..dbdcd15b3a7 100644 --- a/gdb/csky-tdep.h +++ b/gdb/csky-tdep.h @@ -385,4 +385,9 @@ enum csky_regnum /* Macro for kernel 4.x */ #define CSKY_MOVI_R7_139 0x008bea07 +/* Macro for check long branch. */ +#define CSKY_JMPI_PC_4 0x1eac0 +#define CSKY_LRW_T1_PC_8 0x2ea8d +#define CSKY_JMP_T1_VS_NOP 0x6c037834 + #endif -- 2.25.1