如何使用 gdb 来监视整个内存区域的任何变化?

发布于 2024-11-25 01:10:03 字数 126 浏览 3 评论 0原文

例如,我可以中断从 地址范围内对内存的任何更改吗? 读和/或写怎么样?

For example, can I break on any change to memory in an address range from <startaddress> to <endaddress>?
How about reads and/or writes?

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

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

发布评论

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

评论(1

蓝眸 2024-12-02 01:10:03

在 Linux/x86 上,GDB 使用处理器调试寄存器来实现硬件观察点。这样的观察点速度很快——程序全速运行,直到处理器停止并向应用程序发出访问或写入观察点被触发的信号。

但这样的观察点只能对 1 个字大小的数据起作用。

最近的 Valgrind 版本(SVN,但没有发布版本)实现了 GDB 远程协议存根,并允许您通过特殊的监视命令在任意内存上设置读取或写入观察点。

因此,如果您使用的是具有 Valgrind 的平台,并且您的应用程序在 Valgrind 下运行速度可以接受,那么是的:您可以在任意内存区域上设置观察点。

On Linux/x86, GDB uses the processor debug registers to implement hardware watchpoints. Such watchpoints are fast -- the program runs at full speed, until the processor stops and signals the application when the access or write watchpoint is triggered.

But such watchpoints can only work on 1-word sized data.

Recent Valgrind versions (SVN, but no released versions) implement GDB remote protocol stub, and allow you to set read or write watchpoints over arbitrary memory via special monitor commands.

So if you are on a platform that has Valgrind, and if your application runs acceptably fast under Valgrind, then yes: you can set watchpoints on arbitrary memory regions.

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