Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

debugging

gdb

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?

like image 969
alexgolec Avatar asked Jun 28 '11 18:06

alexgolec


1 Answers

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. 
like image 147
Alok Save Avatar answered Sep 24 '22 01:09

Alok Save