ppvm1-1:/tmp/pp> ls ./ bopop.c example2* example3-2* pwck_exp* testsc* ../ example1* example2.c example3-2.c pwck_exp.c testsc.c bopop* example1.c example3* example3.c readme ppvm1-1:/tmp/pp> gdb example2 GNU gdb Red Hat Linux (5.1.90CVS-5) Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"... (gdb) list 1,20 1 void function(char *str) { 2 char buffer[16]; 3 4 strcpy(buffer,str); 5 } 6 7 void main() { 8 char large_string[256]; 9 int i; 10 11 for( i = 0; i < 255; i++) 12 large_string[i] = 'A'; 13 14 function(large_string); 15 } (gdb) diasass main Dump of assembler code for function main: 0x80481b8
: push %ebp 0x80481b9 : mov %esp,%ebp 0x80481bb : sub $0x104,%esp 0x80481c1 : nop 0x80481c2 : movl $0x0,0xfffffefc(%ebp) 0x80481cc : lea 0x0(%esi,1),%esi 0x80481d0 : cmpl $0xfe,0xfffffefc(%ebp) 0x80481da : jle 0x80481e0 0x80481dc : jmp 0x80481f8 0x80481de : mov %esi,%esi 0x80481e0 : lea 0xffffff00(%ebp),%eax 0x80481e6 : mov 0xfffffefc(%ebp),%edx 0x80481ec : movb $0x41,(%edx,%eax,1) 0x80481f0 : incl 0xfffffefc(%ebp) 0x80481f6 : jmp 0x80481d0 0x80481f8 : lea 0xffffff00(%ebp),%eax 0x80481fe : push %eax 0x80481ff : call 0x80481a0 0x8048204 : add $0x4,%esp 0x8048207 : leave 0x8048208 : ret End of assembler dump. (gdb) disass function Dump of assembler code for function function: 0x80481a0 : push %ebp 0x80481a1 : mov %esp,%ebp 0x80481a3 : sub $0x10,%esp 0x80481a6 : mov 0x8(%ebp),%eax 0x80481a9 : push %eax 0x80481aa : lea 0xfffffff0(%ebp),%eax 0x80481ad : push %eax 0x80481ae : call 0x804cf10 0x80481b3 : add $0x8,%esp 0x80481b6 : leave 0x80481b7 : ret End of assembler dump. (gdb) break *0x80481ae Breakpoint 1 at 0x80481ae: file example2.c, line 4. (gdb) break *0x80481b3 Breakpoint 2 at 0x80481b3: file example2.c, line 4. (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x080481ae in function at example2.c:4 2 breakpoint keep y 0x080481b3 in function at example2.c:4 (gdb) run Starting program: /tmp/pp/example2 Breakpoint 1, 0x080481ae in function ( str=0xbffff9b8 'A' ...) at example2.c:4 4 strcpy(buffer,str); (gdb) info reg eip esp ebp eip 0x80481ae 0x80481ae esp 0xbffff990 0xbffff990 ebp 0xbffff9a8 0xbffff9a8 (gdb) x/32 0xbffff990 0xbffff990: 0xbffff998 0xbffff9b8 0x00000000 0x00000000 0xbffff9a0: 0x00000ed8 0x0807a068 0xbffffab8 0x08048204 0xbffff9b0: 0xbffff9b8 0x000000ff 0x41414141 0x41414141 0xbffff9c0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9d0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9e0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9f0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffffa00: 0x41414141 0x41414141 0x41414141 0x41414141 (gdb) disass main Dump of assembler code for function main: 0x80481b8
: push %ebp 0x80481b9 : mov %esp,%ebp 0x80481bb : sub $0x104,%esp 0x80481c1 : nop 0x80481c2 : movl $0x0,0xfffffefc(%ebp) 0x80481cc : lea 0x0(%esi,1),%esi 0x80481d0 : cmpl $0xfe,0xfffffefc(%ebp) 0x80481da : jle 0x80481e0 0x80481dc : jmp 0x80481f8 0x80481de : mov %esi,%esi 0x80481e0 : lea 0xffffff00(%ebp),%eax 0x80481e6 : mov 0xfffffefc(%ebp),%edx 0x80481ec : movb $0x41,(%edx,%eax,1) 0x80481f0 : incl 0xfffffefc(%ebp) 0x80481f6 : jmp 0x80481d0 0x80481f8 : lea 0xffffff00(%ebp),%eax 0x80481fe : push %eax 0x80481ff : call 0x80481a0 0x8048204 : add $0x4,%esp 0x8048207 : leave 0x8048208 : ret End of assembler dump. (gdb) x/32 0xbffff990 0xbffff990: 0xbffff998 0xbffff9b8 0x00000000 0x00000000 0xbffff9a0: 0x00000ed8 0x0807a068 0xbffffab8 0x08048204 0xbffff9b0: 0xbffff9b8 0x000000ff 0x41414141 0x41414141 0xbffff9c0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9d0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9e0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9f0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffffa00: 0x41414141 0x41414141 0x41414141 0x41414141 (gdb) cont Continuing. Breakpoint 2, 0x080481b3 in function ( str=0x41414141
) at example2.c:4 4 strcpy(buffer,str); (gdb) info reg eip esp ebp eip 0x80481b3 0x80481b3 esp 0xbffff990 0xbffff990 ebp 0xbffff9a8 0xbffff9a8 (gdb) x/32 0xbffff990 0xbffff990: 0xbffff998 0xbffff9b8 0x41414141 0x41414141 0xbffff9a0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9b0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9c0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9d0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9e0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffff9f0: 0x41414141 0x41414141 0x41414141 0x41414141 0xbffffa00: 0x41414141 0x41414141 0x41414141 0x41414141 (gdb) cont Continuing. Program received signal SIGSEGV, Segmentation fault. 0x41414141 in ?? () (gdb) quit The program is running. Exit anyway? (y or n) y ppvm1-1:/tmp/pp> exit