How to use gdb for C ++ header files?

I tried to find this question on the Internet, but it seems that I can not find a good solution for my problem. Well, I'm trying to use gdb to debug my C ++ program. And the program consists of simple main.cpp and model.h. And the compilation team

g++ -Wall -g -c main.cpp g++ -Wall -g main.o -o OUTPUT 

As almost the entire algorithm is stored in model.h, I need to debug this header file, not the cpp file. However, whenever I tried to place a breakpoint in the header, for example

 tbreak model.h:163 

gdb always gives me a message that "There is no source file named TNFmodel.h".

In another checkpoint question in GDB, I saw a solution by adding a folder containing the header to the library using "dir". But my header file is already in the source folder and after trying

 dir ./ 

The problem persists.

So does anyone know what happened? How to use gdb to debug the header file?

+8
c ++ debugging header gdb
source share
2 answers

As suggested by https://stackoverflow.com/users/760746/nobody , one way to make sure the header is in the sources is very convenient by checking

 info sources 

After providing the header itself in the sources (in my case, the problem is that the case of the letter in the header name was involved, and somehow went through compilation in my mac book), inserting a breakpoint in the header file lines works very well.

+3
source share

Try using break with your class / method name as follows:

 break class::method 
+1
source share

All Articles