gdb调试--基础

GDB是一款强大的调试工具,用于在程序运行时检查和修改变量、设置断点、跟踪执行流程。本文详细介绍了GDB的基础知识,包括文档、作用、如何调试C++源代码以及多种启动和设置断点的方法。同时,讲解了如next、step和until等单步调试命令,以及print和display命令用于查看变量值。此外,还讨论了在多线程和多进程环境下的调试技巧,如条件断点和跟踪点的使用。
摘要由CSDN通过智能技术生成

gdb

1. 文档

官方参考文档:http://www.gnu.org/software/gdb/documentation/

2. 作用

GDB 做以下 4 件主要的事情来帮助您捕获程序中的 bug:
◼ 在程序启动之前指定一些可以影响程序行为的变量或条件
◼ 在某个指定的地方或条件下暂停程序
◼ 在程序停止时检查已经发生了什么
◼ 在程序执行过程中修改程序中的变量或条件,这样就可以体验修复一个bug 的成果,并继续了解其他 bug

3. 调试GDB的cpp源代码

文件名:typederivation.cpp

#include <iostream>
#include <typeinfo>
#include <vector>
#include<chrono>
#include<thread>
using namespace std;

template <typename T>
class Base {
   
public:
    void func(T& container) {
   
        m_it = container.begin();
    }
private:
    decltype(T().begin()) m_it;  //注意这里
};

void testauto(){
   
    int x = 0;
    double y = 0.8;
    cout << "y type:" << typeid(y).name() << "|" << y << endl;
    auto *p1 = &x;
    auto p2 = &x;
    auto &r1 = x;
    auto r2 = r1;

    const auto n = x;
    cout << "n type:" << typeid(n).name() << "|" << n << endl;
    auto f = n;
    cout << "f type:" << typeid(f).name() << "|" << f << endl;
    const auto &s1 = x;
    cout << "s1 type:" << typeid(s1).name() << "|" << s1 << endl;
    auto &s2 = s1;
    cout << "s2 type:" << typeid(s2).name() << "|" << s2 << endl;
    auto s3 = s1;
    cout << "s3 type:" <<
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值