Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use gdb on c++ header files?

I tried to search this question online, but it seems that I can't find a good solution for my problem. Well, I'm trying to use gdb to debug my c++ program. And the program is made up of a simple main.cpp and a model.h. And the compiling command is

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

As almost all the algorithm is stored in model.h, I need to debug that header file rather than the cpp file. However, whenever I tried to place a break point on the header like

tbreak model.h:163

gdb always give me a message that"No source file named TNFmodel.h".

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

dir ./

The problem maintains.

So anybody know what's wrong? How to use gdb to debug a header file?

like image 345
Chong Avatar asked Mar 04 '13 18:03

Chong


2 Answers

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

info sources

After ensuring the header itself be in the sources(in my case, the problem is that the case of a letter in the header name was mixed up, and somehow it went through the compiling on my mac book), inserting breakpoint in lines of a header file works just fine.

like image 173
Chong Avatar answered Oct 21 '22 20:10

Chong


Try to use break with your class/method name like this:

break  class::method
like image 25
Leo Chapiro Avatar answered Oct 21 '22 20:10

Leo Chapiro