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
我试着在网上搜索这个问题,但似乎找不到一个好的解决方法。我正在尝试使用gdb来调试我的c++程序。这个程序由一个简单的主程序组成。cpp和model.h。编译命令是。
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
因为几乎所有的算法都存储在模型中。我需要调试那个头文件而不是cpp文件。但是,每当我试图在header中放置断点时
tbreak model.h:163
gdb always give me a message that"No source file named TNFmodel.h".
gdb总是给我一个消息,“没有名为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
在GDB中的另一个问题断点中,我看到了通过“dir”将包含头部的文件夹添加到库中的解决方案。但是我的头文件已经在源文件夹中,在尝试之后
dir ./
The problem maintains.
维护的问题。
So anybody know what's wrong? How to use gdb to debug a header file?
有人知道怎么回事吗?如何使用gdb调试头文件?
2 个解决方案
#1
3
As suggested by https://*.com/users/760746/nobody, one way to make sure the header to be in the sources is to veryfy it by checking
正如https://*.com/users/760746/nobody所建议的,确保消息头位于消息源中的一种方法是通过检查使其变得非常有用
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.
在确保消息头本身位于源文件之后(在我的例子中,问题是标题名称中的字母的情况被混淆了,并且不知怎么地,它通过了我的mac book的编译),在头文件的行中插入断点可以很好地工作。
#2
1
Try to use break with your class/method name like this:
尝试使用break与您的类/方法名如下:
break class::method
#1
3
As suggested by https://*.com/users/760746/nobody, one way to make sure the header to be in the sources is to veryfy it by checking
正如https://*.com/users/760746/nobody所建议的,确保消息头位于消息源中的一种方法是通过检查使其变得非常有用
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.
在确保消息头本身位于源文件之后(在我的例子中,问题是标题名称中的字母的情况被混淆了,并且不知怎么地,它通过了我的mac book的编译),在头文件的行中插入断点可以很好地工作。
#2
1
Try to use break with your class/method name like this:
尝试使用break与您的类/方法名如下:
break class::method