【问题标题】:why I can't set breakpoint at fopen in linux为什么我不能在 linux 的 fopen 设置断点
【发布时间】:2012-02-06 05:20:19
【问题描述】:

这是我的代码:

#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 处的断点工作正常。 为什么?

谢谢

【问题讨论】:

    标签: linux gdb


    【解决方案1】:

    这是 GDB 中的一个错误,似乎在当前 CVS 源中已修复(截至 20120124)。

    问题是在Linux上32位libc.so.6中有两个版本的fopen,而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 上设置了断点,但调用的函数是fopen@@GLIBC_2.1

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2020-08-31
    • 2010-10-28
    • 2011-02-10
    • 1970-01-01
    相关资源
    最近更新 更多