GDB硬件观察点如何工作?

发布于 2025-02-05 06:55:11 字数 134 浏览 1 评论 0原文

我对如何实现硬件观察点感兴趣。如果我通过观看uint8_t变量,请手表varname(观看 - > write Watch),以防将在将检测到的内存位置范围内更改任何数据?

GDB如何处理内存位置/范围?

I am interested in how a hardware watchpoint is realized. If I watch for a uint8_t variable by watch varName (watch -> write watch) so in case any data is changed on any bit within the range of the memory location it will be detected?

And how is the memory location/range handled by GDB?

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

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

发布评论

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

评论(1

太傻旳人生 2025-02-12 06:55:11

我对如何实现硬件观察点感兴趣。

在支持硬件观察点的平台上,GDB使用启用它们的处理器功能(du!)。

例如,在x86上,有特殊“ nofollow noreferrer”> debug寄存器停止执行时,当地址总线与给定的地址匹配时,访问是写入(用于观察点),读取(用于实现 access 观察点),等等。

如果我注意一个UINT8_T变量...在将被检测到的内存位置范围内的任何位上,任何数据都会更改?

X86处理器不会将单个写入内存。您至少可以写的是一个字节。编写字节后,处理器将停止(如果调试寄存器已配置如此)。然后,GDB可以将新值与旧值进行比较,如果它们有所不同,请停止执行(否则GDB会吞下观察点并继续没有发生任何事情)。

是的,这可以在单位更改上使用 - 它所需的只是GDB记住旧值(在设置断点时它会这样)。

注意:其中存在一些差距 - 如果内核更改了该值(例如,由于读取系统调用),GDB观察点将 not 停止。发生。

I am interested in how a hardware watchpoint is realized.

On platforms which support hardware watchpoints, GDB uses the processor features which enable them (duh!).

For example, on x86, there are special debug registers, which can be programmed to have the processor halt execution when the address bus matches the given address and the access is a write (used for watchpoints), a read (used to implement access watchpoints), etc.

If I watch for a uint8_t variable ... any data is changed on any bit within the range of the memory location it will be detected?

The x86 processors do not write single bits into memory. The least you can write is a byte. The processor will stop after writing the byte (if the debug registers are so configured). GDB can then compare the new value with the old one, and if they differ, stop execution (otherwise GDB will swallow the watchpoint and continue as of nothing happened).

Yes, this can work on single-bit changes -- all it requires is for GDB to remember the old value (which it does when you set up the breakpoint).

Note: there are some gaps in this -- if the value is changed by the kernel (e.g. as a result of read system call), GDB watchpoint will not stop when that happens.

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