From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D2733858D28; Tue, 17 Jan 2023 13:24:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D2733858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673961899; bh=bkrJ0LF5QCwq1EUPZ1BMd9HD7g4083hGM68ZZuRUryY=; h=From:To:Subject:Date:From; b=VyRjDweQCjKaTfDjdf9h/cRk+F95+Iz6X8559VIiRMmojvIJVehe2vvFN1JWz/NLd UOSd1MF1ttXr/3P5h+kB/xiUhyGtv80Jh4BwupH52lZTTmok5finonqgV8HalgT4zZ htJJPlHvdWlMHGq85lkclnBvaz7W1xMfK5OnmurQ= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug tdep/30011] New: [gdb/tdep, aarch64] Incorrect frame address for last insn (leaf case) Date: Tue, 17 Jan 2023 13:24:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: tdep X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30011 Bug ID: 30011 Summary: [gdb/tdep, aarch64] Incorrect frame address for last insn (leaf case) Product: gdb Version: HEAD Status: NEW Severity: normal Priority: P2 Component: tdep Assignee: unassigned at sourceware dot org Reporter: vries at gcc dot gnu.org Target Milestone: --- [ Spinoff from PR29721. ] Consider the following test-case: ... $ cat test.c void foo (const char *s) { } int main (void) { foo ("foo"); return 0; } ... Compiled without debug info: ... $ gcc test.c ... Disassembly of foo: ... 00000000004005e4 : 4005e4: d10043ff sub sp, sp, #0x10 4005e8: f90007e0 str x0, [sp, #8] 4005ec: d503201f nop 4005f0: 910043ff add sp, sp, #0x10 4005f4: d65f03c0 ret ... Now, let's do "info frame" at each insn in foo, as well as printing $sp and $fp: ... $ gdb 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 $fp 2: /x $fp =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: pc =3D 0x400564 in foo; saved pc =3D 0x40058c called by frame at 0xfffffffff3b0 Arglist at 0xfffffffff3a0, args:=20 Locals at 0xfffffffff3a0, Previous frame's sp is 0xfffffffff3a0 (gdb) si 0x0000000000400568 in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $fp =3D 0xfffffffff390 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: pc =3D 0x400568 in foo; saved pc =3D 0x40058c called by frame at 0xfffffffff3b0 Arglist at 0xfffffffff390, args:=20 Locals at 0xfffffffff390, Previous frame's sp is 0xfffffffff3a0 (gdb) si 0x000000000040056c in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $fp =3D 0xfffffffff390 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: pc =3D 0x40056c in foo; saved pc =3D 0x40058c called by frame at 0xfffffffff3b0 Arglist at 0xfffffffff390, args:=20 Locals at 0xfffffffff390, Previous frame's sp is 0xfffffffff3a0 Saved registers: x0 at 0xfffffffff398 (gdb) si 0x0000000000400570 in foo () 1: /x $sp =3D 0xfffffffff390 2: /x $fp =3D 0xfffffffff390 (gdb) info frame Stack level 0, frame at 0xfffffffff3a0: pc =3D 0x400570 in foo; saved pc =3D 0x40058c called by frame at 0xfffffffff3b0 Arglist at 0xfffffffff390, args:=20 Locals at 0xfffffffff390, Previous frame's sp is 0xfffffffff3a0 Saved registers: x0 at 0xfffffffff398 (gdb) si 0x0000000000400574 in foo () 1: /x $sp =3D 0xfffffffff3a0 2: /x $fp =3D 0xfffffffff3a0 (gdb) info frame Stack level 0, frame at 0xfffffffff3b0: pc =3D 0x400574 in foo; saved pc =3D 0x40058c called by frame at 0xfffffffff3b0 Arglist at 0xfffffffff3a0, args:=20 Locals at 0xfffffffff3a0, Previous frame's sp is 0xfffffffff3b0 Saved registers: x0 at 0xfffffffff3a8 (gdb) si 0x000000000040058c in main () 1: /x $sp =3D 0xfffffffff3a0 2: /x $fp =3D 0xfffffffff3a0 ... The "frame at" bit lists 0xfffffffff3a0 except at the last insn. The frame address is calculated here in aarch64_make_prologue_cache_1: ... unwound_fp =3D get_frame_register_unsigned (this_frame, cache->framereg); if (unwound_fp =3D=3D 0) return; cache->prev_sp =3D unwound_fp + cache->framesize; ... 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 wron= g answer once sp has been restored to entry value by the before-last insn. --=20 You are receiving this mail because: You are on the CC list for the bug.=