在 gdb 中查看内存范围? [英] Watch a memory range in gdb?

查看:54
本文介绍了在 gdb 中查看内存范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 gdb 中调试一个程序,我希望程序在访问内存区域 0x08049000 到 0x0804a000 时停止.当我尝试手动设置内存断点时,gdb 似乎一次不支持两个以上的位置.

I am debugging a program in gdb and I want the program to stop when the memory region 0x08049000 to 0x0804a000 is accessed. When I try to set memory breakpoints manually, gdb does not seem to support more than two locations at a time.

(gdb) awatch *0x08049000
Hardware access (read/write) watchpoint 1: *0x08049000
(gdb) awatch *0x08049001
Hardware access (read/write) watchpoint 2: *0x08049001
(gdb) awatch *0x08049002
Hardware access (read/write) watchpoint 3: *0x08049002
(gdb) run
Starting program: /home/iblue/git/some-code/some-executable
Warning:
Could not insert hardware watchpoint 3.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

已经有一个问题被问到了,答案是,有可能用 valgrind 做到这一点.不幸的是,答案不包含任何示例或对 valgrind 手册的参考,因此它不是很启发性:如何使用 gdb 来监视整个内存区域的任何变化?

There is already a question where this has been asked and the answer was, that it may be possible to do this with valgrind. Unfortunately the answer does not contain any examples or reference to the valgrind manual, so it was not very enlightning: How can gdb be used to watch for any changes in an entire region of memory?

那么:如何查看整个内存区域?

So: How can I watch the whole memory region?

推荐答案

如果你将 GDB 7.4 与 Valgrind 3.7.0 一起使用,那么你有无限的模拟"硬件观察点.

If you use GDB 7.4 together with Valgrind 3.7.0, then you have unlimited "emulated" hardware watchpoints.

在 Valgrind 下启动你的程序,给出参数--vgdb=full --vgdb-error=0然后使用 GDB 连接到它(target remote | vgdb).然后你可以例如watchawatchrwatch 内存范围通过执行rwatch (char[100]) *0x5180040

Start your program under Valgrind, giving the arguments --vgdb=full --vgdb-error=0 then use GDB to connect to it (target remote | vgdb). Then you can e.g. watch or awatch or rwatch a memory range by doing rwatch (char[100]) *0x5180040

参见 Valgrindgdb 集成用户手册了解更多详情

这篇关于在 gdb 中查看内存范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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