Here is my codes:
#include <stdio.h>
int main()
{
fopen("./1.txt","r");
printf("hello");
return 0;
}
$g++ -g -o m main.cpp
$gdb ./m
(gdb) b fopen
Breakpoint 1 at 0x804842c
(gdb) b printf
Breakpoint 2 at 0x804843c
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804842c <fopen@plt>
2 breakpoint keep y 0x0804843c <printf@plt>
(gdb) r
it seems that the breakpoint at function fopen never work ,but at printf works fine.
why?
Thanks
It’s a bug in GDB, which appears to be fixed in current CVS sources (as of 20120124).
The problem is that there are two versions of
fopenin 32-bitlibc.so.6on Linux, and GDB used to select the wrong one:If you also break on
main, and repeatinfo break, you’ll see that GDB set the breakpoint onfopen@GLIBC_2.0, but the function that is called is thefopen@@GLIBC_2.1.