可以在GDB的“内存访问”中设置断点吗? [英] Can I set a breakpoint on 'memory access' in GDB?

查看:815
本文介绍了可以在GDB的“内存访问”中设置断点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过gdb运行应用程序,并且我想要随时访问/更改特定变量,设置一个断点。有没有一个很好的方法来做到这一点?我也有兴趣在其他方式监视C / C ++中的一个变量来查看是否/何时改变。

解决方案

em> watch 只能在写入中断, rwatch 允许您打破读取,并且 awatch 允许您打破读/写。



您可以在内存位置设置读取观察点:

  gdb $ rwatch * 0xfeedface 
硬件读取观察点2:* 0xfeedface

但是一个限制适用于rwatch和awatch命令;您不能在表达式中使用gdb变量

  gdb $ rwatch $ ebx + 0xec1a04f 
表达式无法通过读/访问观察点实现。

所以你必须自己展开:

  gdb $ print $ ebx 
$ 13 = 0x135700
gdb $ rwatch * 0x135700 + 0xec1a04f
硬件读取观察点3:* 0x135700 + 0xec1a04f
gdb $ c
硬件读取观察点3:* 0x135700 + 0xec1a04f

值= 0xec34daf
objc_msgSend()中的0x9527d6e7
pre>

编辑:哦,顺便说一下您需要硬件或软件支持。软件显然要慢一些。要了解您的操作系统是否支持硬件观察点,您可以看到可以使用的观察点环境设置。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆