public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored
Date: Tue, 17 Jan 2023 15:12:33 +0000	[thread overview]
Message-ID: <bug-30012-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=30012

            Bug ID: 30012
           Summary: [gdb/tdep, aarch64] fp and sp register aliases ignored
           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: ---

Consider 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:
...
0000000000400564 <foo>:
  400564:       d10043ff        sub     sp, sp, #0x10
  400568:       f90007e0        str     x0, [sp, #8]
  40056c:       d503201f        nop
  400570:       910043ff        add     sp, sp, #0x10
  400574:       d65f03c0        ret
...

This looks interesting:
...
$ gdb -q -batch a.out \
    -ex "display /x \$sp" \
    -ex "display /x \$x29" \
    -ex "display /x \$fp" \
    -ex "b *foo" \
    -ex run \
    -ex stepi
Breakpoint 1 at 0x400564

Breakpoint 1, 0x0000000000400564 in foo ()
1: /x $sp = 0xfffffffff3a0
2: /x $x29 = 0xfffffffff3a0
3: /x $fp = 0xfffffffff3a0
0x0000000000400568 in foo ()
1: /x $sp = 0xfffffffff390
2: /x $x29 = 0xfffffffff3a0
3: /x $fp = 0xfffffffff390
...

The effect of "sub sp, sp, #0x10" on sp (the canonical name in gdb for x31) is
as expected, it drops 0x10.

The effect on x29, the frame pointer register, is none, again as expected.

However, fp is supposed to be an alias for x29, according to:
...
static const struct
{
  const char *const name;
  int regnum;
} aarch64_register_aliases[] =
{
  /* 64-bit register names.  */
  {"fp", AARCH64_FP_REGNUM},
  {"lr", AARCH64_LR_REGNUM},
  {"sp", AARCH64_SP_REGNUM},
  /*  specials */
  {"ip0", AARCH64_X0_REGNUM + 16},
  {"ip1", AARCH64_X0_REGNUM + 17}
};
...

So we'd expect fp to be unaffected, but that's not the case.

The reason for this is this:
...
void
_initialize_frame_reg ()
{
  /* Frame based $fp, $pc, $sp and $ps.  These only come into play              
     when the target does not define its own version of these                   
     registers.  */
  user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
  user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
  user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
  user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
}
...

So, the fp register alias is simply ignored.

Note that the sp alias is likewise ignored, given that the canonical name for
"x31" is "sp".

We probably should:
- error out when creating aliases with a name that's already taken.
- remove the sp and fp aliases

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-01-17 15:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 15:12 vries at gcc dot gnu.org [this message]
2023-01-19 12:38 ` [Bug tdep/30012] " vries at gcc dot gnu.org
2023-01-19 13:05 ` cvs-commit at gcc dot gnu.org
2023-01-19 13:06 ` vries at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30012-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).