一、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)