rsp rbp 寄存器用途

Posted Li-Yongjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rsp rbp 寄存器用途相关的知识,希望对你有一定的参考价值。

概念

在最新的 x86_x64 架构中,通常用 rbp、rsp 这两个寄存器来保存进程栈的状态(需要硬件支持)。

  • 其中 rbp 保存的是栈中当前执行函数的基本地址,当前执行函数所有存储在栈上的数据都要靠 rbp 指针加上偏移量来读取。
  • 而 rsp 就是常说的栈指针,它永远指向一个进程的栈顶。

实例

hello.c

#include <stdio.h>

int add(int a, int b)

    int c;

    c = a + b;

    return c;


int main(int argc, char *argv[])

    int sum;

    sum = add(3, 5);
    printf("sum = %d\\n", sum);

    return 0;


编译

gcc -g hello.c -o hello.out

gdb 调试

$ gdb hello.out 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello.out...
(gdb) info reg rsp rbp
The program has no registers now.
(gdb) start
Temporary breakpoint 1 at 0x1167: file hello.c, line 13.
Starting program: /home/liyongjun/project/c/C_study/asm/hello3/hello.out 

Temporary breakpoint 1, main (argc=21845, argv=0x0) at hello.c:13
13	
(gdb) info reg rsp rbp
rsp            0x7fffffffdcd8      0x7fffffffdcd8
rbp            0x0                 0x0
(gdb) list
8	
9	    return c;
10	
11	
12	int main(int argc, char *argv[])
13	
14	    int sum;
15	
16	    sum = add(3, 5);
17	    printf("sum = %d\\n", sum);
(gdb) ni
0x000055555555516b	13	
(gdb) 
0x000055555555516c	13	
(gdb) 
0x000055555555516f	13	
(gdb) 
0x0000555555555173	13	
(gdb) 
0x0000555555555176	13	
(gdb) 
16	    sum = add(3, 5);
(gdb) 
0x000055555555517f	16	    sum = add(3, 5);
(gdb) 
0x0000555555555184	16	    sum = add(3, 5);
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/liyongjun/project/c/C_study/asm/hello3/hello.out 
sum = 8
[Inferior 1 (process 27787) exited normally]
(gdb) info b
No breakpoints or watchpoints.
(gdb) b *main *add
Argument to arithmetic operation not a number or boolean.
(gdb) b *main
Breakpoint 2 at 0x555555555167: file hello.c, line 13.
(gdb) b *add
Breakpoint 3 at 0x555555555149: file hello.c, line 4.
(gdb) info reg rsp rbp
The program has no registers now.
(gdb) run
Starting program: /home/liyongjun/project/c/C_study/asm/hello3/hello.out 

Breakpoint 2, main (argc=21845, argv=0x0) at hello.c:13
13	
(gdb) info reg rsp rbp
rsp            0x7fffffffdcd8      0x7fffffffdcd8
rbp            0x0                 0x0
(gdb) info reg
rax            0x555555555167      93824992235879
rbx            0x5555555551b0      93824992235952
rcx            0x5555555551b0      93824992235952
rdx            0x7fffffffddd8      140737488346584
rsi            0x7fffffffddc8      140737488346568
rdi            0x1                 1
rbp            0x0                 0x0
rsp            0x7fffffffdcd8      0x7fffffffdcd8
r8             0x0                 0
r9             0x7ffff7fe0d60      140737354009952
r10            0x7ffff7ffcf68      140737354125160
r11            0x206               518
r12            0x555555555060      93824992235616
r13            0x7fffffffddc0      140737488346560
r14            0x0                 0
r15            0x0                 0
rip            0x555555555167      0x555555555167 <main>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
(gdb) set disassemble-next-line on
(gdb) ni
0x000055555555516b	13	
   0x0000555555555167 <main+0>:	f3 0f 1e fa	endbr64 
=> 0x000055555555516b <main+4>:	55	push   rbp
   0x000055555555516c <main+5>:	48 89 e5	mov    rbp,rsp
   0x000055555555516f <main+8>:	48 83 ec 20	sub    rsp,0x20
   0x0000555555555173 <main+12>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555176 <main+15>:	48 89 75 e0	mov    QWORD PTR [rbp-0x20],rsi
(gdb) 
0x000055555555516c	13	
   0x0000555555555167 <main+0>:	f3 0f 1e fa	endbr64 
   0x000055555555516b <main+4>:	55	push   rbp
=> 0x000055555555516c <main+5>:	48 89 e5	mov    rbp,rsp
   0x000055555555516f <main+8>:	48 83 ec 20	sub    rsp,0x20
   0x0000555555555173 <main+12>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555176 <main+15>:	48 89 75 e0	mov    QWORD PTR [rbp-0x20],rsi
(gdb) info reg rsp rbp
rsp            0x7fffffffdcd0      0x7fffffffdcd0
rbp            0x0                 0x0
(gdb) x /8xh 0x7fffffffdcd8
0x7fffffffdcd8:	0xf083	0xf7dd	0x7fff	0x0000	0x0060	0x0000	0x0001	0x0000
(gdb) x /8xb 0x7fffffffdcd8
0x7fffffffdcd8:	0x83	0xf0	0xdd	0xf7	0xff	0x7f	0x00	0x00
(gdb) 
0x7fffffffdce0:	0x60	0x00	0x00	0x00	0x01	0x00	0x00	0x00
(gdb) x /8xb 0x7fffffffdcd8
0x7fffffffdcd8:	0x83	0xf0	0xdd	0xf7	0xff	0x7f	0x00	0x00
(gdb) x /8xb *0x7fffffffdcd8
0xfffffffff7ddf083:	Cannot access memory at address 0xfffffffff7ddf083
(gdb) x /8xb 0x7fffffffdcd8
0x7fffffffdcd8:	0x83	0xf0	0xdd	0xf7	0xff	0x7f	0x00	0x00
(gdb) x /8xb 0x7fffffffdcd0
0x7fffffffdcd0:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
(gdb) ni
0x000055555555516f	13	
   0x0000555555555167 <main+0>:	f3 0f 1e fa	endbr64 
   0x000055555555516b <main+4>:	55	push   rbp
   0x000055555555516c <main+5>:	48 89 e5	mov    rbp,rsp
=> 0x000055555555516f <main+8>:	48 83 ec 20	sub    rsp,0x20
   0x0000555555555173 <main+12>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555176 <main+15>:	48 89 75 e0	mov    QWORD PTR [rbp-0x20],rsi
(gdb) info reg rsp rbp
rsp            0x7fffffffdcd0      0x7fffffffdcd0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
(gdb) info reg rsp rbp
rsp            0x7fffffffdcd0      0x7fffffffdcd0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
(gdb) ni
0x0000555555555173	13	
   0x0000555555555167 <main+0>:	f3 0f 1e fa	endbr64 
   0x000055555555516b <main+4>:	55	push   rbp
   0x000055555555516c <main+5>:	48 89 e5	mov    rbp,rsp
   0x000055555555516f <main+8>:	48 83 ec 20	sub    rsp,0x20
=> 0x0000555555555173 <main+12>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555176 <main+15>:	48 89 75 e0	mov    QWORD PTR [rbp-0x20],rsi
(gdb) info reg rsp rbp
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
(gdb) info reg
rax            0x555555555167      93824992235879
rbx            0x5555555551b0      93824992235952
rcx            0x5555555551b0      93824992235952
rdx            0x7fffffffddd8      140737488346584
rsi            0x7fffffffddc8      140737488346568
rdi            0x1                 1
rbp            0x7fffffffdcd0      0x7fffffffdcd0
rsp            0x7fffffffdcb0      0x7fffffffdcb0
r8             0x0                 0
r9             0x7ffff7fe0d60      140737354009952
r10            0x7ffff7ffcf68      140737354125160
r11            0x206               518
r12            0x555555555060      93824992235616
r13            0x7fffffffddc0      140737488346560
r14            0x0                 0
r15            0x0                 0
rip            0x555555555173      0x555555555173 <main+12>
eflags         0x202               [ IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
(gdb) info reg rsp rbp edi rsi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x1                 1
rsi            0x7fffffffddc8      140737488346568
(gdb) ni
0x0000555555555176	13	
   0x0000555555555167 <main+0>:	f3 0f 1e fa	endbr64 
   0x000055555555516b <main+4>:	55	push   rbp
   0x000055555555516c <main+5>:	48 89 e5	mov    rbp,rsp
   0x000055555555516f <main+8>:	48 83 ec 20	sub    rsp,0x20
   0x0000555555555173 <main+12>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
=> 0x0000555555555176 <main+15>:	48 89 75 e0	mov    QWORD PTR [rbp-0x20],rsi
(gdb) info reg rsp rbp edi rsi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x1                 1
rsi            0x7fffffffddc8      140737488346568
(gdb) x /8xb 0x7fffffffdcb4
0x7fffffffdcb4:	0x00	0x00	0x00	0x00	0x60	0x50	0x55	0x55
(gdb) x /8xb 0x7fffffffdcbc
0x7fffffffdcbc:	0x01	0x00	0x00	0x00	0xc0	0xdd	0xff	0xff
(gdb) x /4xb 0x7fffffffdcbc
0x7fffffffdcbc:	0x01	0x00	0x00	0x00
(gdb) x /4xb 0x7fffffffdcb0
0x7fffffffdcb0:	0x00	0x00	0x00	0x00
(gdb) x /8xb 0x7fffffffdcb0
0x7fffffffdcb0:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x00
(gdb) info reg rsp rbp edi rsi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x1                 1
rsi            0x7fffffffddc8      140737488346568
(gdb) ni
16	    sum = add(3, 5);
=> 0x000055555555517a <main+19>:	be 05 00 00 00	mov    esi,0x5
   0x000055555555517f <main+24>:	bf 03 00 00 00	mov    edi,0x3
   0x0000555555555184 <main+29>:	e8 c0 ff ff ff	call   0x555555555149 <add>
   0x0000555555555189 <main+34>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi rsi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x1                 1
rsi            0x7fffffffddc8      140737488346568
(gdb) x /8xb 0x7fffffffdcb0
0x7fffffffdcb0:	0xc8	0xdd	0xff	0xff	0xff	0x7f	0x00	0x00
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x1                 1
esi            0xffffddc8          -8760
(gdb) ni
0x000055555555517f	16	    sum = add(3, 5);
   0x000055555555517a <main+19>:	be 05 00 00 00	mov    esi,0x5
=> 0x000055555555517f <main+24>:	bf 03 00 00 00	mov    edi,0x3
   0x0000555555555184 <main+29>:	e8 c0 ff ff ff	call   0x555555555149 <add>
   0x0000555555555189 <main+34>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) ni
0x0000555555555184	16	    sum = add(3, 5);
   0x000055555555517a <main+19>:	be 05 00 00 00	mov    esi,0x5
   0x000055555555517f <main+24>:	bf 03 00 00 00	mov    edi,0x3
=> 0x0000555555555184 <main+29>:	e8 c0 ff ff ff	call   0x555555555149 <add>
   0x0000555555555189 <main+34>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdcb0      0x7fffffffdcb0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x3                 3
esi            0x5                 5
(gdb) ni

Breakpoint 3, add (a=32767, b=-7863) at hello.c:4
4	
=> 0x0000555555555149 <add+0>:	f3 0f 1e fa	endbr64 
   0x000055555555514d <add+4>:	55	push   rbp
   0x000055555555514e <add+5>:	48 89 e5	mov    rbp,rsp
   0x0000555555555151 <add+8>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <add+11>:	89 75 e8	mov    DWORD PTR [rbp-0x18],esi
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdca8      0x7fffffffdca8
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x3                 3
esi            0x5                 5
(gdb) x /8xb 0x7fffffffdca8
0x7fffffffdca8:	0x89	0x51	0x55	0x55	0x55	0x55	0x00	0x00
(gdb) x /8xh 0x7fffffffdca8
0x7fffffffdca8:	0x5189	0x5555	0x5555	0x0000	0xddc8	0xffff	0x7fff	0x0000
(gdb) x /8xg 0x7fffffffdca8
0x7fffffffdca8:	0x0000555555555189	0x00007fffffffddc8
0x7fffffffdcb8:	0x0000000155555060	0x00007fffffffddc0
0x7fffffffdcc8:	0x0000000000000000	0x0000000000000000
0x7fffffffdcd8:	0x00007ffff7ddf083	0x0000000100000060
(gdb) x /1xg 0x7fffffffdca8
0x7fffffffdca8:	0x0000555555555189
(gdb) x /8xg 0x7fffffffdcd0
0x7fffffffdcd0:	0x0000000000000000	0x00007ffff7ddf083
0x7fffffffdce0:	0x0000000100000060	0x00007fffffffddc8
0x7fffffffdcf0:	0x00000001f7fa37a0	0x0000555555555167
0x7fffffffdd00:	0x00005555555551b0	0x54caaf15e847e821
(gdb) x /1xg 0x7fffffffdcd0
0x7fffffffdcd0:	0x0000000000000000
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdca8      0x7fffffffdca8
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x3                 3
esi            0x5                 5
(gdb) ni
0x000055555555514d	4	
   0x0000555555555149 <add+0>:	f3 0f 1e fa	endbr64 
=> 0x000055555555514d <add+4>:	55	push   rbp
   0x000055555555514e <add+5>:	48 89 e5	mov    rbp,rsp
   0x0000555555555151 <add+8>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <add+11>:	89 75 e8	mov    DWORD PTR [rbp-0x18],esi
(gdb) ni
0x000055555555514e	4	
   0x0000555555555149 <add+0>:	f3 0f 1e fa	endbr64 
   0x000055555555514d <add+4>:	55	push   rbp
=> 0x000055555555514e <add+5>:	48 89 e5	mov    rbp,rsp
   0x0000555555555151 <add+8>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <add+11>:	89 75 e8	mov    DWORD PTR [rbp-0x18],esi
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdcd0      0x7fffffffdcd0
edi            0x3                 3
esi            0x5                 5
(gdb) ni
0x0000555555555151	4	
   0x0000555555555149 <add+0>:	f3 0f 1e fa	endbr64 
   0x000055555555514d <add+4>:	55	push   rbp
   0x000055555555514e <add+5>:	48 89 e5	mov    rbp,rsp
=> 0x0000555555555151 <add+8>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <add+11>:	89 75 e8	mov    DWORD PTR [rbp-0x18],esi
(gdb) info reg rsp rbp edi esi
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
(gdb) disassemble add
Dump of assembler code for function add:
   0x0000555555555149 <+0>:	endbr64 
   0x000055555555514d <+4>:	push   rbp
   0x000055555555514e <+5>:	mov    rbp,rsp
=> 0x0000555555555151 <+8>:	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <+11>:	mov    DWORD PTR [rbp-0x18],esi
   0x0000555555555157 <+14>:	mov    edx,DWORD PTR [rbp-0x14]
   0x000055555555515a <+17>:	mov    eax,DWORD PTR [rbp-0x18]
   0x000055555555515d <+20>:	add    eax,edx
   0x000055555555515f <+22>:	mov    DWORD PTR [rbp-0x4],eax
   0x0000555555555162 <+25>:	mov    eax,DWORD PTR [rbp-0x4]
   0x0000555555555165 <+28>:	pop    rbp
   0x0000555555555166 <+29>:	ret    
End of assembler dump.
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x55555167          1431654759
edx            0xffffddd8          -8744
(gdb) ni
0x0000555555555154	4	
   0x0000555555555149 <add+0>:	f3 0f 1e fa	endbr64 
   0x000055555555514d <add+4>:	55	push   rbp
   0x000055555555514e <add+5>:	48 89 e5	mov    rbp,rsp
   0x0000555555555151 <add+8>:	89 7d ec	mov    DWORD PTR [rbp-0x14],edi
=> 0x0000555555555154 <add+11>:	89 75 e8	mov    DWORD PTR [rbp-0x18],esi
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x55555167          1431654759
edx            0xffffddd8          -8744
(gdb) ni
7	    c = a + b;
=> 0x0000555555555157 <add+14>:	8b 55 ec	mov    edx,DWORD PTR [rbp-0x14]
   0x000055555555515a <add+17>:	8b 45 e8	mov    eax,DWORD PTR [rbp-0x18]
   0x000055555555515d <add+20>:	01 d0	add    eax,edx
   0x000055555555515f <add+22>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x55555167          1431654759
edx            0xffffddd8          -8744
(gdb) ni
0x000055555555515a	7	    c = a + b;
   0x0000555555555157 <add+14>:	8b 55 ec	mov    edx,DWORD PTR [rbp-0x14]
=> 0x000055555555515a <add+17>:	8b 45 e8	mov    eax,DWORD PTR [rbp-0x18]
   0x000055555555515d <add+20>:	01 d0	add    eax,edx
   0x000055555555515f <add+22>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x55555167          1431654759
edx            0x3                 3
(gdb) ni
0x000055555555515d	7	    c = a + b;
   0x0000555555555157 <add+14>:	8b 55 ec	mov    edx,DWORD PTR [rbp-0x14]
   0x000055555555515a <add+17>:	8b 45 e8	mov    eax,DWORD PTR [rbp-0x18]
=> 0x000055555555515d <add+20>:	01 d0	add    eax,edx
   0x000055555555515f <add+22>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x5                 5
edx            0x3                 3
(gdb) ni
0x000055555555515f	7	    c = a + b;
   0x0000555555555157 <add+14>:	8b 55 ec	mov    edx,DWORD PTR [rbp-0x14]
   0x000055555555515a <add+17>:	8b 45 e8	mov    eax,DWORD PTR [rbp-0x18]
   0x000055555555515d <add+20>:	01 d0	add    eax,edx
=> 0x000055555555515f <add+22>:	89 45 fc	mov    DWORD PTR [rbp-0x4],eax
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x8                 8
edx            0x3                 3
(gdb) disassemble add
Dump of assembler code for function add:
   0x0000555555555149 <+0>:	endbr64 
   0x000055555555514d <+4>:	push   rbp
   0x000055555555514e <+5>:	mov    rbp,rsp
   0x0000555555555151 <+8>:	mov    DWORD PTR [rbp-0x14],edi
   0x0000555555555154 <+11>:	mov    DWORD PTR [rbp-0x18],esi
   0x0000555555555157 <+14>:	mov    edx,DWORD PTR [rbp-0x14]
   0x000055555555515a <+17>:	mov    eax,DWORD PTR [rbp-0x18]
   0x000055555555515d <+20>:	add    eax,edx
=> 0x000055555555515f <+22>:	mov    DWORD PTR [rbp-0x4],eax
   0x0000555555555162 <+25>:	mov    eax,DWORD PTR [rbp-0x4]
   0x0000555555555165 <+28>:	pop    rbp
   0x0000555555555166 <+29>:	ret    
End of assembler dump.
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x8                 8
edx            0x3                 3
(gdb) x /1xw 0x7fffffffdc9c
0x7fffffffdc9c:	0x00005555
(gdb) ni
9	    return c;
=> 0x0000555555555162 <add+25>:	8b 45 fc	mov    eax,DWORD PTR [rbp-0x4]
(gdb) x /1xw 0x7fffffffdc9c
0x7fffffffdc9c:	0x00000008
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x8                 8
edx            0x3                 3
(gdb) ni
10	
=> 0x0000555555555165 <add+28>:	5d	pop    rbp
   0x0000555555555166 <add+29>:	c3	ret    
(gdb) info reg rsp rbp edi esi eax edx
rsp            0x7fffffffdca0      0x7fffffffdca0
rbp            0x7fffffffdca0      0x7fffffffdca0
edi            0x3                 3
esi            0x5                 5
eax            0x8                 8
edx            0x3                 3
(gdb) ni
0x0000555555555166	10	
   0x0000555555555165 <add+28>:	5d	pop    rbp
=> 0

以上是关于rsp rbp 寄存器用途的主要内容,如果未能解决你的问题,请参考以下文章

为啥 rbp 和 rsp 被称为通用寄存器?

在C ++内联asm中使用基指针寄存器

在 C++ 内联 asm 中使用基指针寄存器

从 rsp 比 rbp 开始布局堆栈变量的意义

将较小大小的值移动到寄存器中

攻防世界-reverse-666