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

一、什么是观察点?

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

二、观察点常用命令

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

调试代码下载地址

测试代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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 @   TechNomad  阅读(132)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-01-14 转:HTTP协议简介
点击右上角即可分享
微信分享提示