C++ 我可以从地址读/写时中断 gdb 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6511560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:17:56  来源:igfitidea点击:

Can I have gdb break on read/write from an address?

c++cdebugginggdb

提问by Alex

Possible Duplicate:
Can I set a breakpoint on 'memory access' in GDB?

可能的重复:
我可以在 GDB 中的“内存访问”上设置断点吗?

I have a specific location in memory that is getting corrupted, and I'd like to be able to see exactly when things write to that location. Is there any way that I can make gdb break on memory access to that particular address?

我在内存中有一个特定位置已损坏,我希望能够准确地看到写入该位置的内容。有什么方法可以让 gdb 中断对该特定地址的内存访问?

回答by Alok Save

Yes.
Using Watchpoints:
watch- only breaks on write (and only if the value changes)
rwatch- breaks on read, and
awatch- breaks on read/write.

是的。
使用观察点
watch- 仅在写入时中断(并且仅当值更改时)
rwatch- 在读取时中断,而
awatch- 在读/写时中断。

A more detailed brief from some internet sources:

来自一些互联网资源的更详细的简介:

watch
watch is gdb's way of setting data breakpoints which will halt the execution of a program if memory changes at the specified location.

watch
watch 是 gdb 设置数据断点的方法,如果指定位置的内存发生变化,它将停止程序的执行。

watch breakpoints can either be set on the variable name or any address location.

可以在变量名或任何地址位置上设置观察断点。

watch my_variable
watch *0x12345678
where 0x12345678 is a valid address.

rwatch
rwatch (read-watch) breakpoints break the execution of code when the program tries to read from a variable or memory location.

rwatch
rwatch (read-watch) 断点在程序尝试从变量或内存位置读取时中断代码的执行。

rwatch iWasAccessed
rwatch *0x12345678
where 0x12345678 is a valid address.

awatch
awatch or access watches break execution of the program if a variable or memory location is written to or read from. In summary, awatches are watches and rwatches all in one. It is a handy way of creating one breakpoint than two separate ones.


如果写入或读取变量或内存位置,awatchawatch 或访问手表会中断程序的执行。总之,awatches 是 watch 和 rwatches 合二为一。这是一种创建一个断点而不是两个独立断点的方便方法。

awatch *0x12345678
where 0x12345678 is a valid address.