LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-07-2011, 10:16 PM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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?
 
Old 09-07-2011, 10:21 PM   #2
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Anisha Kaul View Post
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.

Last edited by SigTerm; 09-07-2011 at 10:27 PM.
 
Old 09-07-2011, 10:27 PM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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
 
Old 09-07-2011, 10:33 PM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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)

Last edited by Aquarius_Girl; 09-07-2011 at 10:35 PM.
 
Old 09-07-2011, 10:44 PM   #5
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Anisha Kaul View Post
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.)
 
Old 09-07-2011, 10:46 PM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++ class member pointer changes after function returns Snark1994 Programming 5 03-30-2011 06:46 PM
Problem setting breakpoint on function with GDB Ganahim Programming 4 02-24-2011 08:03 AM
c++: template member function used in a different templated class matze Programming 5 04-10-2008 09:26 AM
How to register deeper member function in above class? kornerr Programming 3 01-30-2007 02:27 PM
passing a class member function to pthread_create. dmail Programming 1 07-29-2006 11:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration