【问题标题】:Setting a watchpoint on errno in gdb在 gdb 中的 errno 上设置观察点
【发布时间】:2023-03-12 01:11:01
【问题描述】:

我正在尝试找出 errno 何时更改。

一开始我在gdb中尝试了“watch errno”,导致报错

Cannot find thread-local variables on this target

我可以通过使用“-pthread”进行编译来解决这个问题。但是,它仍然不起作用,我现在收到错误

Cannot find shared library `/usr/lib/debug/lib/x86_64-linux-gnu/libc-2.13.so' in dynamic linker's load module list

当我输入“watch errno”时。我需要做什么才能在 errno 上设置观察点?

【问题讨论】:

    标签: debugging gdb libc errno watchpoint


    【解决方案1】:

    errno 不再只是一个静态变量。这是 Linux 上用户级应用程序的显示方式(来自我本地的 /usr/include/x86_64-linux-gnu/bits/errno.h):

    #   define errno (*__errno_location ())
    

    这是为了获取每个线程的错误状态。

    【讨论】:

    • 谢谢,我现在将“int *errno_p = __errno_location()”作为 main 中的第一条语句添加到我的程序中,现在可以使用“watch *errno_p”来检测 errno 何时更改。由于某种原因,直接使用“watch *__errno_location()”不起作用。是否不允许函数上的观察点?可能是被禁止的,因为当它们有副作用时会导致错误的行为。
    • 也许这些年来发生了一些变化,但watch *(int*)__errno_location() 工作正常,只要您在 glibc 初始化之后(例如 b main)和正确的线程中设置它(因为返回的地址是 thread-本地)
    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2018-07-03
    相关资源
    最近更新 更多