简体   繁体   中英

Breakpoint using GDB

I use GDB to debug my code and get stuck when make breakpoint at a function( eg: use strcpy from string.h).

1) At this code, the gdb stop at breakpoint inside strcpy function.

 (gdb) list
1   #include<stdio.h>
2   #include<string.h>
3   main()
4   {
5   char a[20],b[]="ffff";
6   strcpy(a,b);
7   printf("%s\n",a);
8   }
(gdb) break 6
Breakpoint 1 at 0x8048486: file thu.c, line 6.
(gdb) break strcpy
Breakpoint 2 at 0x8048370
(gdb) break 7
Breakpoint 3 at 0x804849a: file thu.c, line 7.
(gdb) run
Starting program: /home/m/a.out 

Breakpoint 1, main () at thu.c:6
6   strcpy(a,b);
(gdb) c
Continuing.

Breakpoint 2, 0xb7ea2490 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) c
Continuing.

Breakpoint 3, main () at thu.c:7
7   printf("%s\n",a);

You can see that gdb stop at breakpoint2 (inside strcpy).

2) At this code, GDB not stop at breakpoint 2 (inside strcpy) but go to breakpoint3.

(gdb) list
1   #include<stdio.h>
2   #include<string.h>
3   main()
4   {
5   char a[20];
6   strcpy(a,"hello world!");
7   printf("%s\n",a);
8   }
(gdb) break 6
Breakpoint 1 at 0x8048449: file thu.c, line 6.
(gdb) break strcpy
Function "strcpy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y

Breakpoint 2 (strcpy) pending.
(gdb) break 7
Breakpoint 3 at 0x8048469: file thu.c, line 7.
(gdb) run
Starting program: /home/m/a.out 

Breakpoint 1, main () at thu.c:6
6   strcpy(a,"hello world!");
(gdb) c
Continuing.

Breakpoint 3, main () at thu.c:7
7   printf("%s\n",a);

So what make two cases different?. I am follow the book "Hacking: The Art of Exploitation" Jon Erickson, this is a example from the book, the case 2 is similar with code char_array2.c at page 39, but the output is not similar from the book in case of breakpoint 2.

thanks for reading!

在第一种情况下,编译器具有所有详细信息(所有参数都是堆栈上已知偏移量的变量。因此,编译器可能用宏替换了对strcpy的调用。在第二种情况下,并非所有关于参数的详细信息都是已知的,因此编译器插入了对strcpy的实际调用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM