可以在GDB的“内存访问”中设置断点吗? [英] Can I set a breakpoint on 'memory access' in GDB?
问题描述
em> watch 只能在写入中断, rwatch 允许您打破读取,并且 awatch 允许您打破读/写。
您可以在内存位置设置读取观察点:
gdb $ rwatch * 0xfeedface
硬件读取观察点2:* 0xfeedface
但是一个限制适用于rwatch和awatch命令;您不能在表达式中使用gdb变量
:
gdb $ rwatch $ ebx + 0xec1a04f
表达式无法通过读/访问观察点实现。
所以你必须自己展开:
gdb $ print $ ebx
pre>
$ 13 = 0x135700
gdb $ rwatch * 0x135700 + 0xec1a04f
硬件读取观察点3:* 0x135700 + 0xec1a04f
gdb $ c
硬件读取观察点3:* 0x135700 + 0xec1a04f
值= 0xec34daf
objc_msgSend()中的0x9527d6e7
编辑:哦,顺便说一下您需要硬件或软件支持。软件显然要慢一些。要了解您的操作系统是否支持硬件观察点,您可以看到可以使用的观察点环境设置。
gdb $ show can-use-hw-watchpoints
调试器使用观察点硬件的意愿是1.
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 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
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 ()
Edit: 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的“内存访问”中设置断点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!