简体   繁体   English

使用gdb设置多线程应用程序的观察点

[英]Setting watchpoint for multithreaded applications with gdb

gdb manual says the following. gdb手册说如下。

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. 如果gdb创建了一个软件观察点,它只能在单个线程中观察表达式的值。 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. 但是,当非当前线程的活动更改表达式时,gdb可能不会注意到。 (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? 那么,如何使用gdb将watchpoint与多个线程一起使用,以便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...) 这仅适用于简单的标量数据(单指针,单整数,单字节......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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