Can I set a breakpoint on #39;memory access#39; in GDB?(我可以在 GDB 中的“内存访问上设置断点吗?)
问题描述
我正在通过 gdb 运行一个应用程序,我想在任何时候访问/更改特定变量时设置断点.有没有好的方法可以做到这一点?我也对在 C/C++ 中监视变量的其他方法感兴趣,以查看它是否/何时发生变化.
I am running an application through gdb and I want to set a breakpoint for any time a specific variable is accessed / changed. Is there a good method for doing this? I would also be interested in other ways to monitor a variable in C/C++ to see if/when it changes.
推荐答案
watch 只在写入时中断,rwatch 让你在读取时中断,awatch 让你中断读/写.
watch only breaks on write, rwatch let you break on read, and awatch let you break on read/write.
您可以在内存位置上设置读取观察点:
You can set read watchpoints on memory locations:
gdb$ rwatch *0xfeedface
Hardware read watchpoint 2: *0xfeedface
但有一个限制适用于 rwatch 和 awatch 命令;你不能使用 gdb 变量在表达式中:
but one limitation applies to the rwatch and awatch commands; you can't use gdb variables in expressions:
gdb$ rwatch $ebx+0xec1a04f
Expression cannot be implemented with read/access watchpoint.
所以你必须自己扩展它们:
So you have to expand them yourself:
gdb$ print $ebx
$13 = 0x135700
gdb$ rwatch *0x135700+0xec1a04f
Hardware read watchpoint 3: *0x135700 + 0xec1a04f
gdb$ c
Hardware read watchpoint 3: *0x135700 + 0xec1a04f
Value = 0xec34daf
0x9527d6e7 in objc_msgSend ()
哦,顺便说一下.您需要硬件或软件支持.软件显然要慢得多.要了解您的操作系统是否支持硬件观察点,您可以查看 can-use-hw-watchpoints 环境设置.
Oh, and by the way. You need either hardware or software support. Software is obviously much slower. To find out if your OS supports hardware watchpoints you can see the can-use-hw-watchpoints environment setting.
gdb$ show can-use-hw-watchpoints
Debugger's willingness to use watchpoint hardware is 1.
这篇关于我可以在 GDB 中的“内存访问"上设置断点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以在 GDB 中的“内存访问"上设置断点吗
基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07