setup breakpoints using gdb debugger

HiME

Senior member
Jan 30, 2006
209
0
76
Anybody knows how to setup up breakpoints on a header file under GDB?

Thanks!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I haven't used GDB, but here's a bump for you anyway. What are you trying to break on in a header? Inline function?
 

HiME

Senior member
Jan 30, 2006
209
0
76
I simply want to debug a function from another class which resides on a header file. With GDB I can setup breakpoints on the .cpp file using 'br #' after loading the file with 'file XXX'... but I cannot find information on how to specify the breakpoint on a header file.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
The reason I asked is that there shouldn't be functions in a header other than inlined ones, and some debuggers have a problem following inline function defs.
 

HiME

Senior member
Jan 30, 2006
209
0
76
Thanks for replies. I don't understand though, I have multiple classes, shouldn't it make sense for me to separate them for management purposes? I usually have the source file storing just the main function.

Visual studio's debugger seems to be a lot more powerful and user friendly to me =) you can setup breakpoints with a simple click (including the header files), and easily monitor variables through the GUI interface.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Yes it definitely does make sense. The thing is, header files don't contain executable code, or at least they are not supposed to (it's all just convention, anyway). When you see a function defined in a class declaration that is what is known as an "inline" function, and will be expanded inline (potentially) at the point of call. Think of it as macro++. So the code that is executing when that inline function is called is not actually closely related to the header in which it was declared. Rather, it has been sort of "pasted in" to the .cpp module in which it was called, and this confuses some debuggers.
 

iCyborg

Golden Member
Aug 8, 2008
1,330
56
91
Can you try setting a breakpoint as "b Class::Method" and see if that works?

I think GDB should be able to handle inline if the program is compiled in debug mode, perhaps the 'inline' keyword gets macro-ed out or something...
 

HiME

Senior member
Jan 30, 2006
209
0
76
Thanks Markbnj. I understand what you mean.

Tried "b Class::Method" and got the following error...

"Can't find member of namespace, class, struct, or union named "XXXXX" "
 

iCyborg

Golden Member
Aug 8, 2008
1,330
56
91
How do you compile your exec? I've never had to use 'file xxx' command. If you compile it with -g (I assume you use gcc/g++), and just run 'gdb execname' it should load all the symbols. Do you have any optimizations specified?

What happens when you set a breakpoint in cpp before the call to the function in the header and try to step into?

Originally posted by: HiME
I have multiple classes, shouldn't it make sense for me to separate them for management purposes? I usually have the source file storing just the main function.

The usual way is to have multiple source files, e.g. program.cpp has the main() and uses class X included from X.h and implemented in X.cpp.
 

HiME

Senior member
Jan 30, 2006
209
0
76
g++ -g filename
gdb
file filename
br X
r
b Class::Method
Can't find member of namespace, class, struct, or union named "XXXXX"

I guess I will live up with setting up breakpoints in cpp before I call the function =)
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: iCyborg
The usual way is to have multiple source files, e.g. program.cpp has the main() and uses class X included from X.h and implemented in X.cpp.

e.g.:
File: ***************MyClass.h***************

#ifndef MYCLASS_H
#define MYCLASS_H

class MyClass{
public:
MyClass();
~MyClass();

void MyFunction();

private:
int m_nMyInteger;
};

#endif

File: ***************MyClass.C***************
#include "MyClass.h"

MyClass::MyClass() {
m_nMyInteger = 0;
}

MyClass::~MyClass() {}

void MyClass::MyFunction() {
std::cout << "My integer is " << m_nMyInteger << std::endl;
}
 

HiME

Senior member
Jan 30, 2006
209
0
76
I understand why to separate the functions from a .h to a .cpp file. Just curious, if I don't declare inline on my functions there won't be any paste in effects right?

And I just found out the syntax to setup the breakpoints on a .h file.

b CLASSNAME.h:LINE_NUMBER
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: HiME
I understand why to separate the functions from a .h to a .cpp file. Just curious, if I don't declare inline on my functions there won't be any paste in effects right?

It depends on your compiler and your optimization settings. Some compiler settings will aggressively inline non-inline functions, and some compilers and settings will ignore inline directives. Check your compiler's documentation, or just look at the assembly output (-S for gcc).

And I just found out the syntax to setup the breakpoints on a .h file.

b CLASSNAME.h:LINE_NUMBER

Neat!
 

iCyborg

Golden Member
Aug 8, 2008
1,330
56
91
Originally posted by: HiME
I understand why to separate the functions from a .h to a .cpp file. Just curious, if I don't declare inline on my functions there won't be any paste in effects right?

And I just found out the syntax to setup the breakpoints on a .h file.

b CLASSNAME.h:LINE_NUMBER

Hm, I thought that's what you did first. Curious then, what other way is there besides breaking on a certain line and on a particular function?
It's not really a syntax: I usually do 'b filename:lineNum', but it often doesn't work for me for .h files.
 

HiME

Senior member
Jan 30, 2006
209
0
76
There isn't any other ways. I normally just setup breakpoints before I call a function using 'b LINENUMBER' or 'b FUNCTION'.

'b filename:lineNum' is functioning as expected here.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |