public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored
@ 2023-01-17 15:12 vries at gcc dot gnu.org
  2023-01-19 12:38 ` [Bug tdep/30012] " vries at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-17 15:12 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tdep/30012] [gdb/tdep, aarch64] fp and sp register aliases ignored
  2023-01-17 15:12 [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored vries at gcc dot gnu.org
@ 2023-01-19 12:38 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-19 12:38 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2023-January/195930.html

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tdep/30012] [gdb/tdep, aarch64] fp and sp register aliases ignored
  2023-01-17 15:12 [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored vries at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-19 13:05 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ea2f6fad7e104fb65da6a438bb0ec753210f1e90

commit ea2f6fad7e104fb65da6a438bb0ec753210f1e90
Author: Tom de Vries <tdevries@space.suse.cz>
Date:   Thu Jan 19 14:05:08 2023 +0100

    [gdb/tdep, aarch64] Remove fp and sp reg aliases, add x31 reg alias

    In aarch64-tdep.c we find these register aliases:
    ...
    {
      /* 64-bit register names.  */
      {"fp", AARCH64_FP_REGNUM},
      {"lr", AARCH64_LR_REGNUM},
      {"sp", AARCH64_SP_REGNUM},
    ...

    The sp alias is superfluous, because the canonical name of x31 is already
sp.

    The fp alias is superfluous, because it's already taken by the default
meaning
    of fp, assigned here in _initialize_frame_reg:
    ...
      user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
    ...

    Fix this by removing the fp and sp aliases.

    While we're at it, add an x31 alias for sp.

    Approved-By: Luis Machado <luis.machado@arm.com>

    Tested on aarch64-linux.
    PR tdep/30012
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30012

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tdep/30012] [gdb/tdep, aarch64] fp and sp register aliases ignored
  2023-01-17 15:12 [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored vries at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-19 13:06 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |14.1

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-19 13:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 15:12 [Bug tdep/30012] New: [gdb/tdep, aarch64] fp and sp register aliases ignored vries at gcc dot gnu.org
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

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).