用gdb分析C的时候,碰到ebp寄存器,不太明白它到底指向哪里
用的是intel语法,我想用gdb分析C 程序,关键就是我不明白ebp寄存器是怎么一回事我明白ebp是为了参照函数中局部变量的,
eip是下一条要执行語句的地址
有一程序stack_example.c
#include<stdio.h>
void test_function(int a, int b, int c, int d) {
int flag;
char buffer[10];
flag = 6;
buffer[0] = 'A';
}
int main(void) {
test_function(1,2,3,4);
}
$ gcc -g stack_example.c 编译
$ gdb -q ./a.out 安静模式
(gdb) disass main
Dump of assembler code for function main:
0x08048433 <+0>: push %ebp
0x08048434 <+1>: mov %esp,%ebp
0x08048436 <+3>: and $0xfffffff0,%esp
0x08048439 <+6>: sub $0x10,%esp
0x0804843c <+9>: movl $0x4,0xc(%esp)
0x08048444 <+17>: movl $0x3,0x8(%esp)
0x0804844c <+25>: movl $0x2,0x4(%esp)
0x08048454 <+33>: movl $0x1,(%esp)
0x0804845b <+40>: call 0x8048404 <test_function>
0x08048460 <+45>: leave
0x08048461 <+46>: ret
End of assembler dump.
(gdb) disass test_function
Dump of assembler code for function test_function:
0x08048404 <+0>: push %ebp
0x08048405 <+1>: mov %esp,%ebp
0x08048407 <+3>: sub $0x28,%esp
0x0804840a <+6>: mov %gs:0x14,%eax
0x08048410 <+12>: mov %eax,-0xc(%ebp)
0x08048413 <+15>: xor %eax,%eax
0x08048415 <+17>: movl $0x6,-0x1c(%ebp)
0x0804841c <+24>: movb $0x41,-0x16(%ebp)
0x08048420 <+28>: mov -0xc(%ebp),%eax
0x08048423 <+31>: xor %gs:0x14,%eax
0x0804842a <+38>: je 0x8048431 <test_function+45>
0x0804842c <+40>: call 0x8048340 <__stack_chk_fail@plt>
0x08048431 <+45>: leave
0x08048432 <+46>: ret
End of assembler dump.
(gdb)
我明白stack 是从高位向低位伸展
heap是从低位向高位伸展
不明白的就是出现 ebp的那几行
0x08048415 <+17>: movl $0x6,-0x1c(%ebp)
0x0804841c <+24>: movb $0x41,-0x16(%ebp)