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 的起始地址,我需要查看正在加载的地址eax0x080483e5当我在或设置断点时,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.

我究竟做错了什么?为什么程序执行不在该地址处暂停?

4

1 回答 1

1

如果你想在某个地址设置断点,你必须说b *0x080483eb See here for more info。

您还应该使用 -g 编译您的程序,并且不进行优化。您可以break main在到达 main 时停下来,走几行并n打印bufp buf

于 2011-02-14T07:51:32.330 回答