如何使用gdb打破基类的构造函数?

时间:2013-07-30 08:05:02

标签: c++ gdb breakpoints

我的主要cpp文件是:

class UnifiedDirListQuery : public UnifiedQuery{
public:
    UnifiedDirListQuery(){
        //do something-------------line 12
    }
}
//other code

int main( void ){
    UnifiedQuery *query = new UnifiedDirListQuery();//-----line 56
    //do something
    delete query;
}

UnifiedQuery分别在unified.hunified.cpp中声明和定义。当我在gdb中调试这个程序时:

gdb: b 56
gdb: r
gdb: s

程序跳转到第12行。如果ctor在unified.cpp中定义,如何转到Ctor并跳转到基类UnifiedQuery的{​​{1}}。

更新

对于答案unified.cpp : line 25,gdb抱怨:

break UnifiedDirListQuery::UnifiedDirListQuery

对于答案(gdb) b UnifiedDirListQuery::UnifiedDirListQuery [0] cancel [1] all ?HERE ?HERE > 1 Note: breakpoint -1 (disabled) also set at pc 0x0. Breakpoint 1 at 0x0 Note: breakpoints -1 (disabled) and 1 also set at pc 0x0. Breakpoint 2 at 0x0 warning: Multiple breakpoints were set. Use the "delete" command to delete unwanted breakpoints. (gdb) r Starting program: /...(the path)/src/base/unified_album_list.cgi Warning: Cannot insert breakpoint 1. Error accessing memory address 0x0: Input/output error. ,gdb只是忽略它并不停地执行程序。顺便说一句:实际上ctor的定义是在一个名为b file:line的文件中,由于它位于头文件中而被声明为内联函数。

2 个答案:

答案 0 :(得分:5)

你也可以

break UnifiedDirListQuery::UnifiedDirListQuery

另请注意,gdb具有制表符完成功能,因此您无需键入所有内容。

答案 1 :(得分:0)

break unified.cpp:25应该这样做,例如在第25行打破 特别是如果您有多个文件,则必须提供要中断的文件的名称。有关详细信息,请参阅here