Search code examples
gdbwatchpoint

Set Read-Write watchpoint with GDB?


I'm trying to trackdown the source of incorrect runtime cpu feature reporting. I'm fairly certain its due to C++ "As-If-Broken" rule, where the language allows the compiler to take a correct program and turn it into an incorrect program.

According to 5.1.2 Setting Watchpoints:

Set a watchpoint for an expression. gdb will break when the expression expr is written into by the program and its value changes. The simplest (and the most popular) use of this command is to watch the value of a single variable:

(gdb) watch foo

Notice the watchpoints are for write access, but not read-write access.

I'd like to set a watchpoint for read-write access on a variable which is set once at startup in a function with __attribute__(constructor), and then read multiple times after the features have been determined. I want to do it to confirm the optimizer is removing the calls, and maybe determine how many of the calls are being removed.

How do I set a read-write watchpoint with GDB?


Solution

  • How do I set a read-write watchpoint with GDB?

    (gdb) help awatch
    

    From the manual:

    awatch [-l|-location] expr [thread thread-id] [mask maskvalue]
    
    Set a watchpoint that will break when expr is either read from
    or written into by the program.