GDB调试之观察点的使用(九)

一、什么是观察点?

观察点是一个特殊的断点,当表达式的值发生变化时,它将中断下来。表达式可以是一个变量的值,也可以包含由运算符组合的一个或多个变量的值,例如'a+b'。有时被称为数据断点(VC里面就称之为数据断点)。

二、观察点常用命令

  • watch:写观察点
  • rwatch:读观察点
  • awtach:读写断点
  • info watch:查看观察点
  • delete/disable/enable:删除/禁用/启用观察点

调试代码下载地址

测试代码示例:

#include <iostream>
#include <cstring>
#include <thread>
using namespace std;
int gdata = 0;
int gdata2 = 0;
void test_thread(void *data)
{
	int *temp = (int*)data;
	std::this_thread::sleep_for(std::chrono::seconds(*temp));
	gdata = *temp;
	gdata2 = 2 * (*temp);
	cout << "thread data:" << gdata << endl;
	cout << "test thread exited" << endl;
}
int main(int argc,char** argv)
{
	int data=3;
	thread t1(&test_thread,(void*)&data);
	int data2=5;
	thread t2(&test_thread,(void*)&data2);
	t1.join();
	t2.join();
	cout << "threads exit" << endl;
	return 0;
}

写观察点命令watch的使用:

为指定线程设置写观察点:

为两个变量之和大于10设置写观察点:

读观察点命令rwatch的使用:

读写观察点命令awtach的使用:

posted @ 2024-01-14 19:32  TechNomad  阅读(19)  评论(0编辑  收藏  举报