无法设置断点
我试图获取 buf
的起始地址。所以我编译了以下程序并将其加载到 gdb 中。
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char buf[128];
if(argc < 2) return 1;
strcpy(buf, argv[1]);
printf("%s\n", buf);
return 0;
}
在反汇编 main
时,我们得到: -
(gdb) disassemble main
Dump of assembler code for function main:
0x080483b4 <main+0>: push ebp
0x080483b5 <main+1>: mov ebp,esp
0x080483b7 <main+3>: sub esp,0xa8
0x080483bd <main+9>: and esp,0xfffffff0
0x080483c0 <main+12>: mov eax,0x0
0x080483c5 <main+17>: sub esp,eax
0x080483c7 <main+19>: cmp DWORD PTR [ebp+0x8],0x1
0x080483cb <main+23>: jg 0x80483d9 <main+37>
0x080483cd <main+25>: mov DWORD PTR [ebp-0x8c],0x1
0x080483d7 <main+35>: jmp 0x8048413 <main+95>
0x080483d9 <main+37>: mov eax,DWORD PTR [ebp+0xc]
0x080483dc <main+40>: add eax,0x4
0x080483df <main+43>: mov eax,DWORD PTR [eax]
0x080483e1 <main+45>: mov DWORD PTR [esp+0x4],eax
0x080483e5 <main+49>: lea eax,[ebp-0x88]
0x080483eb <main+55>: mov DWORD PTR [esp],eax
0x080483ee <main+58>: call 0x80482d4 <strcpy@plt>
0x080483f3 <main+63>: lea eax,[ebp-0x88]
0x080483f9 <main+69>: mov DWORD PTR [esp+0x4],eax
0x080483fd <main+73>: mov DWORD PTR [esp],0x8048524
0x08048404 <main+80>: call 0x80482b4 <printf@plt>
0x08048409 <main+85>: mov DWORD PTR [ebp-0x8c],0x0
0x08048413 <main+95>: mov eax,DWORD PTR [ebp-0x8c]
0x08048419 <main+101>: leave
0x0804841a <main+102>: ret
End of assembler dump.
为了找到 buf 的起始地址,我需要查看正在加载到 eax
中的地址。当我在 0x080483e5
或 0x080483ee
设置断点时,我得到以下结果。
(gdb) b 0x080483eb
Function "0x080483eb" not defined.
Make breakpoint pending on future shared library load? (y or [n])
(gdb) run test
Starting program: /levels/level05 test
test
Program exited normally.
我做错了什么?为什么程序执行不在该地址处暂停?
Im trying to get the starting address of buf
. So I compile the following program and load it up in gdb.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char buf[128];
if(argc < 2) return 1;
strcpy(buf, argv[1]);
printf("%s\n", buf);
return 0;
}
On disassembling main
we get:-
(gdb) disassemble main
Dump of assembler code for function main:
0x080483b4 <main+0>: push ebp
0x080483b5 <main+1>: mov ebp,esp
0x080483b7 <main+3>: sub esp,0xa8
0x080483bd <main+9>: and esp,0xfffffff0
0x080483c0 <main+12>: mov eax,0x0
0x080483c5 <main+17>: sub esp,eax
0x080483c7 <main+19>: cmp DWORD PTR [ebp+0x8],0x1
0x080483cb <main+23>: jg 0x80483d9 <main+37>
0x080483cd <main+25>: mov DWORD PTR [ebp-0x8c],0x1
0x080483d7 <main+35>: jmp 0x8048413 <main+95>
0x080483d9 <main+37>: mov eax,DWORD PTR [ebp+0xc]
0x080483dc <main+40>: add eax,0x4
0x080483df <main+43>: mov eax,DWORD PTR [eax]
0x080483e1 <main+45>: mov DWORD PTR [esp+0x4],eax
0x080483e5 <main+49>: lea eax,[ebp-0x88]
0x080483eb <main+55>: mov DWORD PTR [esp],eax
0x080483ee <main+58>: call 0x80482d4 <strcpy@plt>
0x080483f3 <main+63>: lea eax,[ebp-0x88]
0x080483f9 <main+69>: mov DWORD PTR [esp+0x4],eax
0x080483fd <main+73>: mov DWORD PTR [esp],0x8048524
0x08048404 <main+80>: call 0x80482b4 <printf@plt>
0x08048409 <main+85>: mov DWORD PTR [ebp-0x8c],0x0
0x08048413 <main+95>: mov eax,DWORD PTR [ebp-0x8c]
0x08048419 <main+101>: leave
0x0804841a <main+102>: ret
End of assembler dump.
In order to find the starting address of buf, I need to see the address which is being loaded into eax
. When I set a breakpoint at 0x080483e5
or 0x080483ee
I get the following.
(gdb) b 0x080483eb
Function "0x080483eb" not defined.
Make breakpoint pending on future shared library load? (y or [n])
(gdb) run test
Starting program: /levels/level05 test
test
Program exited normally.
What am I doing wrong? Why doesn't the program execution pause at that address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想在某个地址设置断点,你必须说
b *0x080483eb
请参阅此处了解更多信息。
您还应该使用 -g 编译您的程序,并且不进行优化。您可以在到达 main 时
break main
停止,使用n
步进几行,然后使用p buf< 打印
buf
/代码>If you want to set a break point at an address, you have to say
b *0x080483eb
See here for more info.
You should also compile your program with -g , and without optimization. You can just
break main
to stop when you get to main, step a few lines withn
and printbuf
withp buf