unable to set breakpoints
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>开发者_Go百科;: 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?
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
精彩评论