在gdb中的errno上设置观察点

Her*_*che 4 debugging gdb errno libc watchpoint

我试图找出errno何时发生变化.

起初,我在gdb中尝试了"watch errno",这导致了错误

Cannot find thread-local variables on this target
Run Code Online (Sandbox Code Playgroud)

我能够通过编译"-pthread"来解决这个问题.但是,它仍然不起作用,我现在得到错误

Cannot find shared library `/usr/lib/debug/lib/x86_64-linux-gnu/libc-2.13.so' in dynamic linker's load module list
Run Code Online (Sandbox Code Playgroud)

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

Nik*_*sov 5

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

#   define errno (*__errno_location ())
Run Code Online (Sandbox Code Playgroud)

这是为了获得每个线程的错误状态.

  • 谢谢,我现在添加了"int*errno_p = __errno_location()"作为我程序中main的第一个语句,现在可以使用"watch*errno_p"来检测errno何时发生变化.直接使用"watch*__ errno_location()"由于某种原因无效.关于功能的观察点是不允许的?可能它是被禁止的,因为当它们有副作用时会导致错误的行为. (3认同)
  • 也许这些年来有些东西发生了变化,但是 `watch *(int*)__errno_location()` 工作得很好,只要你在 glibc 初始化之后(例如 `b main`)并且在正确的线程中设置它(因为返回的地址是 thread -当地的) (3认同)