如何监控在 gdb 中设置观察点所需的资源?

发布于 2024-12-11 13:38:03 字数 542 浏览 0 评论 0原文

在 x86 上,GDB 使用一些特殊的硬件资源(调试寄存器?)来设置观察点。在某些情况下,当没有足够的资源时,GDB 会设置观察点,但它不会起作用。 有什么方法可以在 Linux 上以编程方式监视这些资源的可用性吗?也许是 procfs 中的一些信息,或者其他什么。我需要此信息来选择池中的机器进行调试。

来自 GDB 内部人士: “由于它们依赖于硬件资源,因此硬件断点的数量可能有限;当用户要求更多时,gdb将开始尝试设置软件断点。(在某些体系结构上,特别是32位x86平台上,gdb并不总是知道是否有足够的硬件资源来插入所有硬件断点和观察点。在这些平台上,只有当正在调试的程序继续时,gdb 才会打印错误消息。)”“

请求了太多不同的观察点。 (在某些体系结构上,这种情况在调试程序恢复之前无法检测到。)请注意,x86 调试寄存器既用于硬件断点又用于观察点,因此设置太多硬件断点可能会导致观察点插入失败。

“32 位 Intel x86 处理器具有特殊的调试寄存器,旨在促进调试。gdb 提供了一个通用函数库,基于 x86 的端口可使用该库来实现对观察点和硬件辅助断点的支持。”

On x86 GDB uses some special hardware resources (debug registers?) to set watchpoints. In some situations, when there is not enough of that resources, GDB will set the watchpoint, but it won't work.
Is there any way to programmatically monitor the availability of this resources on Linux? Maybe some info in procfs, or something. I need this info to choose machine in pool for debugging.

From GDB Internals:
"Since they depend on hardware resources, hardware breakpoints may be limited in number; when the user asks for more, gdb will start trying to set software breakpoints. (On some architectures, notably the 32-bit x86 platforms, gdb cannot always know whether there's enough hardware resources to insert all the hardware breakpoints and watchpoints. On those platforms, gdb prints an error message only when the program being debugged is continued.)"

"Too many different watchpoints requested. (On some architectures, this situation is impossible to detect until the debugged program is resumed.) Note that x86 debug registers are used both for hardware breakpoints and for watchpoints, so setting too many hardware breakpoints might cause watchpoint insertion to fail."

"The 32-bit Intel x86 processors feature special debug registers designed to facilitate debugging. gdb provides a generic library of functions that x86-based ports can use to implement support for watchpoints and hardware-assisted breakpoints."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2024-12-18 13:38:04

我需要此信息来选择池中的机器进行调试。

不,你不知道。 x86 调试寄存器(有 4 个)是每个进程的资源,而不是每个机器的资源 [1]。对于正在调试的每个进程,最多可以有 4 个硬件观察点。如果其他人在同一台机器上调试,你们不会互相干扰。

[1] 更准确地说,寄存器由内核进行多路复用:与 EAX 寄存器的方式相同。系统上的每个进程和内核本身都使用 EAX,(单核)CPU 上只有一个 EAX 寄存器,但通过以下魔力一切都可以正常工作时间切片。

I need this info to choose machine in pool for debugging.

No, you don't. The x86 debug registers (there are 4) are per-process resource, not per-machine resource [1]. You can have up to 4 hardware watchpoints for every process you are debugging. If someone else is debugging on the same machine, you are not going to interfere with each other.

[1] More precisely, the registers are multiplexed by the kernel: in the same way as e.g. the EAX register. Every process on the system and the kernel itself uses EAX, there is only a single EAX register on (single-core) CPU, yet it all works fine through the magic of time-slicing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文