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?
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.
Try to use break with your class/method name like this:
break class::method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With