如何使用 gdb 来监视整个内存区域的任何变化?
例如,我可以中断从
到
地址范围内对内存的任何更改吗? 读和/或写怎么样?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 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.