在文件中的类的成员函数上设置断点

Aqu*_*irl 5 gdb breakpoints

(gdb) b breakpoints.cpp:X::X()

Can't find member of namespace, class, struct, or union named "breakpoints.cpp:X::X"
Hint: try 'breakpoints.cpp:X::X()<TAB> or 'breakpoints.cpp:X::X()<ESC-?>
(Note leading single quote.)
Make breakpoint pending on future shared library load? (y or [n]) n
Run Code Online (Sandbox Code Playgroud)

在以下代码中:

#include <stdio.h>
#include <iostream>

class X
{
    public:
        X   () 
        {
            std :: cout << "\nIn the default constructor";
        }

        X   (int) 
        {
            std :: cout << "\nIn the parameterized constructor";
        }

        ~X () {}
};

int main (int argc, char *argv[])
{
    X xObjA;
    X xObjB (11);

    while (--argc > 0)
    {
        printf("\n%s ", argv [argc]);
    }
    std :: cout << std :: endl << std :: endl;
}
Run Code Online (Sandbox Code Playgroud)

文件名是:breakpoints.cpp

我错过了什么意思?

Mil*_*lan 3

这才是设置断点的正确方法。

您要么在错误的可执行文件上尝试(将breakpoints.cpp放入目录中并使用g++ -g Breakpoints.cpp进行编译,然后在a.out可执行文件上使用gdb),代码与发布的代码不同并且可能具有名称空间,或者您由于使用过时的 gdb 版本而偶然发现了一个旧错误。

  • fwiw,我用 gdb 7.2 和 gdb 7.3 尝试过这个,只有 7.3 有效。 (2认同)