使用 GDB 设置读写观察点?

Set Read-Write watchpoint with GDB?

我正在尝试追踪 incorrect runtime cpu feature reporting. I'm fairly certain its due to C++ "As-If-Broken" rule 的源代码,其中的语言允许编译器采用正确的程序并将其变成错误的程序。

根据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

注意观察点用于写访问,而不是读写访问。

我想设置一个变量的读写访问观察点,该变量在 __attribute__(constructor) 的函数启动时设置一次,然后在确定功能后多次读取。我想这样做是为了确认优化器正在删除调用,并可能确定正在删除多少调用。

如何使用 GDB 设置读写观察点?

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

(gdb) help awatch

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