Setting a breakpoint for a class member function in a file

(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

by the following code:

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

File Name: breakpoints.cpp

What is the point of what I am missing?

+5
source share
3 answers

This is the correct way to set a breakpoint.

You are trying to execute the wrong executable (put breakspoints.cpp in the directory and compile with g ++ -g breakpoints.cpp and then use gdb for the a.out executable), the code is different from the hosted one, and possibly with a namespace, or you stumbled upon an old error due to using an outdated version of gdb.

+3
source

You might need to define your breakpoints without a file name. The following works for me:

break FooNamespace::FooClass::doSomething()

, , , .

, , , gdb , - :

Breakpoint 1 at 0x7fe62f8e744d: file src/FooClass.cpp, line 42. (2 locations)
(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>
1.1                         y   0x00007fe62f8e744d in FooNamespace::FooClass::doSomething() at src/FooClass.cpp:42
1.2                         y   0x00007fe62f8e7c5d in FooNamespace::FooClass::doSomething() at src/FooClass.cpp:42
+1

, . std. , . , . "nm -C", -C ++.

So, to summarize with an example: If the namespace is "mySpace" and the class "X" of which "Y" is a member, then the breakpoint should look like the point below, "(gdb) b mySpace :: X :: Y"

0
source

All Articles