2009年9月11日 星期五

How to set the breakpoints and remove breakpoints in GDB

qustion@jeff-debian:~/Samsung/hello/printf$ gcc -g -Wall -o hello hello.c
qustion@jeff-debian:~/Samsung/hello/printf$ gdb ./hello
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) list
1 #include
2
3 int main(int argc, char *argv[]) {
4 printf("Hello the world!\n");
5 return 0;
6 }
7
(gdb) b 5
Breakpoint 1 at 0x80483c1: file hello.c, line 5.
(gdb) r
Starting program: /home/qustion/Samsung/hello/printf/hello
Hello the world!

Breakpoint 1, main () at hello.c:5
5 return 0;
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x080483c1 in main at hello.c:5
breakpoint already hit 1 time
(gdb) info registers
eax 0x11 17
ecx 0x11 17
edx 0xb7ee40f0 -1209122576
ebx 0xb7ee2ff4 -1209126924
esp 0xbfc228f0 0xbfc228f0
ebp 0xbfc228f8 0xbfc228f8
esi 0x80483e0 134513632
edi 0x80482f0 134513392
eip 0x80483c1 0x80483c1
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) print/x $eip
$1 = 0x80483c1
(gdb) c
Continuing.

Program exited normally.
(gdb) clear 5
Deleted breakpoint 1
(gdb) disassemble main
Dump of assembler code for function main:
0x080483a4 : lea 0x4(%esp),%ecx
0x080483a8 : and $0xfffffff0,%esp
0x080483ab : pushl -0x4(%ecx)
0x080483ae : push %ebp
0x080483af : mov %esp,%ebp
0x080483b1 : push %ecx
0x080483b2 : sub $0x4,%esp
0x080483b5 : movl $0x8048490,(%esp)
0x080483bc : call 0x80482d4
0x080483c1 : mov $0x0,%eax
0x080483c6 : add $0x4,%esp
0x080483c9 : pop %ecx
0x080483ca : pop %ebp
0x080483cb : lea -0x4(%ecx),%esp
0x080483ce : ret
End of assembler dump.
(gdb)

沒有留言: