无法在gdb中设置断点 [英] Not able to set breakpoints in gdb
问题描述
我的C ++项目文件夹结构如下所示。
My C++ project folder structure is as shown below.
我试图使用gdb在我的linux机器调试程序。我的主要功能是在g2o.cpp里面g2o_cli文件夹。我可以通过
I am trying to debug the program using gdb in my linux machine. My main function is in g2o.cpp which is inside g2o_cli folder. I am able to put breakpoints in the files in this folder by
break g2o.cpp:<line_number>
但我不能在其他文件夹的文件中放置断点,例如文件优化器.cpp在'core'文件夹中。我尝试从我的主目录提供绝对路径
But I am not able to put breakpoints in the files in other folders, for example, a file optimizer.cpp in the 'core' folder. I tried giving the absolute path from my home directory
break ~/HOME/g2o/core/optimizer.cpp:<line_number>
但它给出错误
No source file named ~/HOME/g2o/core/optimizer.cpp
我也试过../../core/optimizer.cpp而不是绝对路径。仍然无法正常工作。
I also tried ../../core/optimizer.cpp instead of the absolute path. Still it did not work.
我看到一个类似的问题这里。但答案中提到的任何可能的原因都不适用于我的情况。文件optimizer.cpp不是共享库,整个项目是使用cmake编译的。
I saw a similar question here. But none of the possible reasons mentioned in the answer is applicable in my case. The file optimizer.cpp is not a shared library and the entire project was compiled using cmake.
gdb如何处理文件夹路径?如何给相对文件夹路径?
How does gdb take folder paths? How can I give the relative folder path?
推荐答案
你可以在x86上使用的一个脏的黑客是使用 int3
。只需在你想要断点的代码中使用语句 asm volatile(int 3);
。
A dirty hack you can use on x86 is to use int3
. Just use the statement asm volatile ("int 3");
in the code where you want the breakpoint.
这篇关于无法在gdb中设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!