From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7882) id 9622638582B3; Tue, 13 Sep 2022 06:20:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9622638582B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663050014; bh=lDrct7cO22p5imTxZUVpuT2vnL4HPUCe9c0GjidmrXQ=; h=From:To:Subject:Date:From; b=BkKPkYO5/YbNa0Lnv0Cb5h4TjFukvYpG8HF2UsVOdmQ/HVHuBoOxpxROtuHAxZlUm WLBjveFSBKDNhkVt3ySyS4YuePO6Q8u44q66JEzElZguYObOv+Mm5f6ZlaklWg+y6S jM1UHfhSxeKP/YYLP8MyDsBlKuv4iXawQjLlqUXE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jiangshuai Li To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/csky add unwinder for long branch cases X-Act-Checkin: binutils-gdb X-Git-Author: Jiangshuai Li X-Git-Refname: refs/heads/master X-Git-Oldrev: 02cd1b4e97120f71710c4246953bcb2d63cb4aea X-Git-Newrev: d354e0c8e7d333d2ec1796f8ce4216e892a4c714 Message-Id: <20220913062014.9622638582B3@sourceware.org> Date: Tue, 13 Sep 2022 06:20:14 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd354e0c8e7d3= 33d2ec1796f8ce4216e892a4c714 commit d354e0c8e7d333d2ec1796f8ce4216e892a4c714 Author: Jiangshuai Li Date: Tue Sep 13 14:19:26 2022 +0800 gdb/csky add unwinder for long branch cases =20 There are two sequences of instructions for long branch: 1. jmpi [pc+4] //insn code: 0xeac00001 .long addr =20 2. lrw t1, [pc+8] //insn code: 0xea8d0002 jmp t1 //insn code: 0x7834 nop //insn code: 0x6c03 .long addr Diff: --- 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 = =3D { NULL }; =20 +static CORE_ADDR +csky_check_long_branch (struct frame_info *frame, CORE_ADDR pc) +{ + gdb_byte buf[8]; + struct gdbarch *gdbarch =3D get_frame_arch (frame); + enum bfd_endian byte_order_for_code + =3D gdbarch_byte_order_for_code (gdbarch); + + if (target_read_memory (pc, buf, 8) =3D=3D 0) + { + unsigned int data0 + =3D extract_unsigned_integer (buf, 4, byte_order_for_code); + unsigned int data1 + =3D extract_unsigned_integer (buf + 4, 4, byte_order_for_code); + + /* Case: jmpi [pc+4] : 0xeac00001 + .long addr */ + if (data0 =3D=3D CSKY_JMPI_PC_4) + return data1; + + /* Case: lrw t1, [pc+8] : 0xea8d0002 + jmp t1 : 0x7834 + nop : 0x6c03 + .long addr */ + if ((data0 =3D=3D CSKY_LRW_T1_PC_8) && (data1 =3D=3D CSKY_JMP_T1_VS_= NOP)) + { + if (target_read_memory (pc + 8, buf, 4) =3D=3D 0) + return extract_unsigned_integer (buf, 4, byte_order_for_code); + } =20 + return 0; + } + + return 0; +} =20 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; =20 + /* Get pc */ addr_in_block =3D get_frame_address_in_block (this_frame); + pc =3D get_frame_pc (this_frame); =20 - if (find_pc_partial_function (addr_in_block, NULL, NULL, NULL) =3D=3D 0 - || in_plt_section (addr_in_block)) + if (in_plt_section (addr_in_block) + || target_read_memory (pc, dummy, 4) !=3D 0) return 1; =20 + /* Find the starting address and name of the function containing the PC.= */ + if (find_pc_partial_function (pc, &name, &start_addr, NULL) =3D=3D 0) + { + start_addr =3D csky_check_long_branch (this_frame, pc); + /* if not long branch, return 0. */ + if (start_addr !=3D 0) + return 1; + + return 0; + } + return 0; } =20 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 =20 +/* 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