简体   繁体   中英

Setting watchpoint for multithreaded applications with gdb

gdb manual says the following.

Warning: In multi-threaded programs, software watchpoints have only limited usefulness. If gdb creates a software watchpoint, it can only watch the value of an expression in a single thread. If you are confident that the expression can only change due to the current thread's activity (and if you are also confident that no other thread can become current), then you can use software watchpoints as usual. However, gdb may not notice when a non-current thread's activity changes the expression. (Hardware watchpoints, in contrast, watch an expression in all threads.)

So, how can I use watchpoint with multiple threads using gdb, such that change to the watched variable from any thread is seen by gdb?

In general, software watchpoints are really costly. You could use a hardware watchpoint, if you are watching a scalar data whose address is well defined, something like

  p &myvar
  $1 = (int*) 0x1234556
  watch *(int*) 0x1234556

This is relevant only for simple scalar data (single pointer, single integer, single byte...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM