开发者

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

开发者 https://www.devze.com 2023-03-15 20:22 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Can I set a breakpoint on 'memory access' in 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?


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

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 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 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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号