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) 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章