为什么我不能在linux中的fopen设置断点

时间:2012-02-06 05:20:20

标签: linux gdb

这是我的代码:

#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

似乎函数fopen的断点永远不会工作,但是在printf工作正常。 为什么?

由于

1 个答案:

答案 0 :(得分:4)

这是GDB中的一个错误,它似乎在当前的CVS来源中得到修复(截至2012012年)。

问题是Linux上的32位fopen中存在两个版本的libc.so.6,并且GDB用于选择错误的版本:

nm -D /lib32/libc.so.6 | grep '\<fopen\>'
0005d0c0 T fopen
00109750 T fopen

readelf -s  /lib32/libc.so.6 | egrep '0005d0c0|00109750'
181: 0005d0c0    50 FUNC    GLOBAL DEFAULT   12 fopen@@GLIBC_2.1
182: 00109750   136 FUNC    GLOBAL DEFAULT   12 fopen@GLIBC_2.0
679: 0005d0c0    50 FUNC    GLOBAL DEFAULT   12 _IO_fopen@@GLIBC_2.1
680: 00109750   136 FUNC    GLOBAL DEFAULT   12 _IO_fopen@GLIBC_2.0

如果您还在main上中断并重复info break,您会看到GDB在fopen@GLIBC_2.0上设置断点,但调用的函数是{{1} }。

相关问题