2

For example, can I break on any change to memory in an address range from <startaddress> to <endaddress>? How about reads and/or writes?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Badmanchild
  • 990
  • 9
  • 18
  • 1
    This was almost impossible in 2011. In 2012 however, things have changed. See http://stackoverflow.com/questions/11004374/watch-a-memory-range-in-gdb – iblue Jun 13 '12 at 23:09

1 Answers1

2

On Linux/x86, GDB uses the processor debug registers to implement hardware watchpoints. Such watchpoints are fast -- the program runs at full speed, until the processor stops and signals the application when the access or write watchpoint is triggered.

But such watchpoints can only work on 1-word sized data.

Recent Valgrind versions (SVN, but no released versions) implement GDB remote protocol stub, and allow you to set read or write watchpoints over arbitrary memory via special monitor commands.

So if you are on a platform that has Valgrind, and if your application runs acceptably fast under Valgrind, then yes: you can set watchpoints on arbitrary memory regions.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362