【发布时间】:2023-04-02 16:45:01
【问题描述】:
(gdb) break main
Breakpoint 1 at 0x80483e4: file hello.c, line 6.
(gdb) run
Starting program: /PROG/1/a.out
Breakpoint 1, main () at hello.c:6
6 for(i=0;i<10;i++)
(gdb) disassemble main
Dump of assembler code for function main:
0x080483d4 <+0>: push ebp
0x080483d5 <+1>: mov ebp,esp
0x080483d7 <+3>: sub esp,0x8
0x080483da <+6>: and esp,0xfffffff0
0x080483dd <+9>: mov eax,0x0
0x080483e2 <+14>: sub esp,eax
0x080483e4 <+16>: mov DWORD PTR [ebp-0x4],0x0
0x080483eb <+23>: cmp DWORD PTR [ebp-0x4],0x9
0x080483ef <+27>: jle 0x80483f3 <main+31>
0x080483f1 <+29>: jmp 0x8048406 <main+50>
0x080483f3 <+31>: mov DWORD PTR [esp],0x80484e4 <=this instruction 'doesn't have influence'
0x080483fa <+38>: call 0x80482f0 <printf@plt>
0x080483ff <+43>: lea eax,[ebp-0x4]
0x08048402 <+46>: inc DWORD PTR [eax]
0x08048404 <+48>: jmp 0x80483eb <main+23>
0x08048406 <+50>: mov eax,0x0
0x0804840b <+55>: leave
0x0804840c <+56>: ret
End of assembler dump.
(gdb) nexti
0x080483eb 6 for(i=0;i<10;i++)
(gdb) nexti
0x080483ef 6 for(i=0;i<10;i++)
(gdb) nexti
7 printf("Hello, World!\n");
(gdb) i r esp
esp 0xbffff520 0xbffff520
(gdb) nexti
0x080483fa 7 printf("Hello, World!\n");
(gdb) i r esp
esp 0xbffff520 0xbffff520
(gdb) nexti
0x08048402 6 for(i=0;i<10;i++)
(gdb) i r esp
esp 0xbffff520 0xbffff520 <=esp stays the same all the time
(gdb) quit
您看到的说明是在 Gentoo 系统 (i686) 上使用 gcc-3.3.6 (gcc -g hello.c) 构建的。它们会影响系统打印“Hello, World!” 10次。
如您所见,mov 指令“应该”将地址 0x80484e4 写入寄存器 esp,但命令 i r esp(info register esp) 始终返回相同的结果。
我用不同版本的 gdb 尝试了一切,我什至在不同的发行版上尝试过。然而它一直都是一样的。
谢谢。
【问题讨论】: