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

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

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

程序如下:

//gdb_test.cpp

#include

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;
}

GDB 调试技巧(不断更新中......)_第1张图片

调试过程如下:

[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 .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:
.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) 

你可能感兴趣的:(工具)