]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb, amd64: extend the amd64 prologue analyzer to skip stack alloc
authorPawel Kupczak <pawel.kupczak@intel.com>
Thu, 28 Aug 2025 11:50:15 +0000 (11:50 +0000)
committerChristina Schimpe <christina.schimpe@intel.com>
Thu, 4 Sep 2025 20:44:48 +0000 (20:44 +0000)
commit57ce06ac23a8b01d1bd9de2cbc1f79f75b96f0ca
tree09b72d23582cf08c139f65c73745f44bfdf81b26
parent8862ee58868fc018b6fe179c3b6d61c30867d541
gdb, amd64: extend the amd64 prologue analyzer to skip stack alloc

Following the previous patch (gdb, amd64: extend the amd64 prologue
analyzer to skip register pushes), this patch extends the analyzer
further to be able to skip stack space allocation as the next prologue
part, for functions with a frame pointer.  Implementation was based
on the i386 counterpart, which already had that functionality.

As of now, the stack allocation is not skipped.  Examples below use C
source listed below, compiled with gcc 11.4.0.
```
int foo (int n)
{
    int ns[] = { 1, 4, 9, 16, 25 };
    return ns[n];
}

int
main (int argc, char **argv)
{
    return foo (argc);
}
```

Compiling with "gcc -O0 -fno-omit-frame-pointer" we get:
```
(gdb) b foo
Breakpoint 1 at 0x1151
(gdb) r
...
Breakpoint 1, 0x0000555555555151 in foo ()
(gdb) disassemble
Dump of assembler code for function foo:
   0x0000555555555149 <+0>:     endbr64
   0x000055555555514d <+4>:     push   %rbp
   0x000055555555514e <+5>:     mov    %rsp,%rbp
=> 0x0000555555555151 <+8>:     sub    $0x30,%rsp
   0x0000555555555155 <+12>:    mov    %edi,-0x24(%rbp)
...
```

With this patch, it gets skipped the same way register pushes are:
```
(gdb) b foo
Breakpoint 1 at 0x1155
(gdb) r
...
Breakpoint 1, 0x0000555555555155 in foo ()
(gdb) disassemble
Dump of assembler code for function foo:
   0x0000555555555149 <+0>:     endbr64
   0x000055555555514d <+4>:     push   %rbp
   0x000055555555514e <+5>:     mov    %rsp,%rbp
   0x0000555555555151 <+8>:     sub    $0x30,%rsp
=> 0x0000555555555155 <+12>:    mov    %edi,-0x24(%rbp)
...
```

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/amd64-tdep.c
gdb/testsuite/gdb.arch/amd64-extended-prologue-analysis-no-cfi.S
gdb/testsuite/gdb.arch/amd64-extended-prologue-analysis-offset.S
gdb/testsuite/gdb.arch/amd64-extended-prologue-analysis.S
gdb/testsuite/gdb.arch/amd64-extended-prologue-analysis.c
gdb/testsuite/gdb.arch/amd64-extended-prologue-analysis.exp