LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GDB: Setting breakpoint on a class's member function in a file (https://www.linuxquestions.org/questions/programming-9/gdb-setting-breakpoint-on-a-classs-member-function-in-a-file-901703/)

Aquarius_Girl 09-07-2011 10:16 PM

GDB: Setting breakpoint on a class's member function in a file
 
Code:

anisha@linux-dopx:~> gdb -v
GNU gdb (GDB) SUSE (7.1-3.12)
Copyright (C) 2010 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-suse-linux". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>.

anisha@linux-dopx:~>

Code:

(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

on the following code:
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's name is: breakpoints.cpp

What's the point that I am missing?

Is this a GDB version problem?

SigTerm 09-07-2011 10:21 PM

Quote:

Originally Posted by Anisha Kaul (Post 4464519)
What's the point that I am missing?

b X::X()

OR

b main.cpp:9

Quote:

(gdb) help break
Set breakpoint at specified line or function.
break [LOCATION] [thread THREADNUM] [if CONDITION]
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.

THREADNUM is the number from "info threads".
CONDITION is a boolean expression.

Multiple breakpoints at one place are permitted, and useful if conditional.

Aquarius_Girl 09-07-2011 10:27 PM

I know that SigTerm, but in this case I "have to"
specify the file name.
Look here: http://www.ofb.net/gnu/gdb/gdb_29.html#SEC29

Aquarius_Girl 09-07-2011 10:33 PM

Code:

(gdb) help break
Set breakpoint at specified line or function.
break [LOCATION] [thread THREADNUM] [if CONDITION]
LOCATION may be a line number,
function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.

THREADNUM is the number from "info threads".
CONDITION is a boolean expression.

Multiple breakpoints at one place are permitted, and useful if conditional.

Do "help breakpoints" for info on other commands dealing with breakpoints.
(gdb)


SigTerm 09-07-2011 10:44 PM

Quote:

Originally Posted by Anisha Kaul (Post 4464525)
I know that SigTerm, but in this case I "have to"
specify the file name.
Look here: http://www.ofb.net/gnu/gdb/gdb_29.html#SEC29

It looks like it doesn't work for class methods, only for functions. You could try gdb mailing list or stackoverflow (I could be missing something important).
Code:

(gdb) break 1.cpp:main
Note: breakpoint 1 also set at pc 0x4013a9.
Breakpoint 3 at 0x4013a9: file 1.cpp, line 25.
(gdb) break 1.cpp:X::X
Can't find member of namespace, class, struct, or union named "1.cpp:X::X"
Hint: try '1.cpp:X::X<TAB> or '1.cpp:X::X<ESC-?>
(Note leading single quote.)


Aquarius_Girl 09-07-2011 10:46 PM

List the version of GDB you have SigTerm,
StackOverflow people say, that this runs
only version 7.3, not even on 7.2!


All times are GMT -5. The time now is 08:21 PM.