From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 02D233858D3C; Mon, 23 Jan 2023 15:49:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02D233858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674488979; bh=mKlSlYrBt8RAbg8ZlP1VqPLXnitrnbxuOI2ZFpd+/vk=; h=From:To:Subject:Date:From; b=ggY3jRxb/3OiSOcSpWJyIE3sEHJOShMMjYWAvUhSdUPhMljH9RqrQZdk6lnoXjpoF jCHb0SDVzaT8eaknapOBHJj/+9icVpHBF4H3ZkQarvYe2xqx/DKbn2TL/50fQfpbDN uiGpNh7YQQT0ONJPj5oUwp5BKVygZOfkY7Tthv8A= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/tdep, aarch64] Fix frame address of last insn X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: eb015bf86b6c6764f8acfea01a25a63e9b492dc5 X-Git-Newrev: 29e09a42f1d1af3d97652e54b6b3cac68cf61d15 Message-Id: <20230123154939.02D233858D3C@sourceware.org> Date: Mon, 23 Jan 2023 15:49:39 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D29e09a42f1d1= af3d97652e54b6b3cac68cf61d15 commit 29e09a42f1d1af3d97652e54b6b3cac68cf61d15 Author: Tom de Vries Date: Mon Jan 23 16:49:36 2023 +0100 [gdb/tdep, aarch64] Fix frame address of last insn =20 Consider the test-case test.c, compiled without debug info: ... void foo (const char *s) { } =20 int main (void) { foo ("foo"); return 0; } ... =20 Disassembly of foo: ... 0000000000400564 : 400564: d10043ff sub sp, sp, #0x10 400568: f90007e0 str x0, [sp, #8] 40056c: d503201f nop 400570: 910043ff add sp, sp, #0x10 400574: d65f03c0 ret ... =20 Now, let's do "info frame" at each insn in foo, as well as printing $sp and $x29 (and strip the output of info frame to the first line, for bre= vity): ... $ gdb -q a.out Reading symbols from a.out... (gdb) b *foo Breakpoint 1 at 0x400564 (gdb) r Starting program: a.out =20 Breakpoint 1, 0x0000000000400564 in foo () (gdb) display /x $sp 1: /x $sp =3D 0xfffffffff3a0 (gdb) display /x $x29 2: /x $x29 =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: (gdb) si 0x0000000000400568 in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $x29 =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: (gdb) si 0x000000000040056c in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $x29 =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: (gdb) si 0x0000000000400570 in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $x29 =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: (gdb) si 0x0000000000400574 in foo () 1: /x $sp =3D 0xfffffffff3a0 2: /x $x29 =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3b0: pc =3D 0x400574 in foo; saved pc =3D 0x40058c (gdb) si 0x000000000040058c in main () 1: /x $sp =3D 0xfffffffff3a0 2: /x $x29 =3D 0xfffffffff3a0 ... =20 The "frame at" bit lists 0xfffffffff3a0 except at the last insn, where = it lists 0xfffffffff3b0. =20 The frame address is calculated here in aarch64_make_prologue_cache_1: ... unwound_fp =3D get_frame_register_unsigned (this_frame, cache->framer= eg); if (unwound_fp =3D=3D 0) return; =20 cache->prev_sp =3D unwound_fp + cache->framesize; ... =20 For insns after the prologue, we have cache->framereg =3D=3D sp and cache->framesize =3D=3D 16, so unwound_fp + cache->framesize gives the = wrong answer once sp has been restored to entry value by the before-last insn. =20 Fix this by detecting the situation that the sp has been restored. =20 This fixes PRs tdep/30010 and tdep/30011. =20 This also fixes the aarch64 FAILs in gdb.reverse/solib-precsave.exp and gdb.reverse/solib-reverse.exp I reported in PR gdb/PR29721. =20 Tested on aarch64-linux. PR tdep/30010 PR tdep/30011 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30010 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30011 Diff: --- gdb/aarch64-tdep.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index aeca30587a5..ea93e9ad0d2 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -149,6 +149,8 @@ static const char *const aarch64_mte_register_names[] = =3D "tag_ctl" }; =20 +static int aarch64_stack_frame_destroyed_p (struct gdbarch *, CORE_ADDR); + /* AArch64 prologue cache structure. */ struct aarch64_prologue_cache { @@ -1000,7 +1002,10 @@ aarch64_make_prologue_cache_1 (frame_info_ptr this_f= rame, if (unwound_fp =3D=3D 0) return; =20 - cache->prev_sp =3D unwound_fp + cache->framesize; + cache->prev_sp =3D unwound_fp; + if (!aarch64_stack_frame_destroyed_p (get_frame_arch (this_frame), + cache->prev_pc)) + cache->prev_sp +=3D cache->framesize; =20 /* Calculate actual addresses of saved registers using offsets determined by aarch64_analyze_prologue. */