GDB 调试技巧(不断更新中......)

一、break到不同类的同名函数

方法: 在函数前面加类名以及作用域运算符
eg : break A::func //break 到类A的func函数

程序如下:

//gdb_test.cpp

#include<iostream>

class A {
public:
    void func() {
        std::cout << "A::func() is called" <<  std::endl;
    }
};

class B {
public:
    void func() {
        std::cout << "B::func() is called" <<  std::endl;
    }
};

int main(int argc,char *argv[])
{
    A a;
    B b;
    a.func();
    b.func();
    return 0;
}

这里写图片描述

调试过程如下:

[kiosk@localhost mess]$ gdb gdb_test
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/kiosk/practice/mess/gdb_test...done.
(gdb) b A::func            //备注:break 到 A::func()位置处
Breakpoint 1 at 0x4008fa: file gdb_test.cpp, line 13.
(gdb) b B::func            //备注:break 到 B::func()位置处
Breakpoint 2 at 0x400924: file gdb_test.cpp, line 20.
(gdb) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨博东的博客

请我喝瓶可乐鼓励下~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值