无法设置断点

发布于 2024-10-17 09:46:42 字数 2203 浏览 4 评论 0原文

我试图获取 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 中的地址。当我在 0x080483e50x080483ee 设置断点时,我得到以下结果。

(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 技术交流群。

扫码二维码加入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 with n and print buf with p buf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文