Eclipse/MinGW/CDT/GDB 和调试问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19864204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse/MinGW/CDT/GDB and problems with debugging
提问by michaeluskov
I have some C++ code and try to debug it. main.cpp:
我有一些 C++ 代码并尝试调试它。主.cpp:
#include <iostream>
using namespace std;
int main() {
graph<int> a;
a.add(1);
a.addEdge(1,2);
std::vector<int> answ = a.getAdjacent(1);
for (unsigned int i = 0; i < answ.size(); i++)
std::cout<<answ[i]<<std::endl;
return 0;
}
I have a breakpoint on "graph a;". But when I start debugging, I get:
我在“graph a;”上有一个断点。但是当我开始调试时,我得到:
The target endianness is set automatically (currently little endian)
No source file named C:\Users\home\workspace\graphcpp\main.cpp.
[New Thread 3552.0xdc8]
What's the problem?
有什么问题?
回答by greatwolf
This seems to be a relatively frequent reoccurring issue when using eclipse +cdt with gdb. Changing the default launcher from GDB (DSF) Create Processto Standard Create Processseems to solve the issue most of the time.
这似乎是在 gdb 中使用 eclipse +cdt 时相对频繁出现的问题。将默认启动器从GDB (DSF) Create Process更改为Standard Create Process似乎可以解决大多数情况下的问题。
You can find this option under Preferences->Run/Debug->Launching->Default Launchers:
您可以在Preferences->Run/Debug->Launching->Default Launchers下找到此选项:
Also make sure you are compiling with -g
debug info enabled.
还要确保您在编译时-g
启用了调试信息。
回答by Jorge Gil
It seems that only with adding the standard parameters to your 'main()' function is enough (I noticed that you're not using parameters in your 'main()':
似乎只有在“main()”函数中添加标准参数就足够了(我注意到您没有在“main()”中使用参数:
check this link
检查此链接
I also see this problem. The folks at LinuxQuestions.org helped me make some progress... http://www.linuxquestions.org/questions/showthread.php?t=518283
我也看到这个问题。LinuxQuestions.org 的人帮助我取得了一些进展... http://www.linuxquestions.org/questions/showthread.php?t=518283
It appears that gcc 4.1.0 (ie. that in SUSE 10.1, 32-bit) has an optimization where if you don't use argc and argv in the body of main() those symbols are not present in the binary (even with -g and without any special optimization turned on). The 64-bit compiler doesn't do this incidentally.
似乎 gcc 4.1.0(即在 SUSE 10.1 中,32 位)有一个优化,如果你不在 main() 的主体中使用 argc 和 argv,这些符号不会出现在二进制文件中(即使使用-g 并且没有打开任何特殊优化)。64 位编译器不会偶然执行此操作。
You get the "Cannot access memory at address 0x0" from the gdb command lineif you simply "break main" and print argc in a program that doesn't use argc/argv (and was compiled with gcc 4.1.0). I note your example doesn't use argc/argv.
如果您只是“中断 main”并在不使用 argc/argv(并使用 gcc 4.1.0 编译)的程序中打印 argc,您会从 gdb命令行获得“无法访问地址 0x0 处的内存” 。我注意到你的例子没有使用 argc/argv。
This is true for C or C++ compilation.
这适用于 C 或 C++ 编译。
Eclipse is presumably confused by this error in some way when it hits the first break. I was also getting the inability to stop at further breakpoints untilI added code to reference argc/argv, or re-declare main (in C++) as "int main(int, char *[])" so that Eclipse wasn't expecting those symbols.
Eclipse 在遇到第一次中断时可能会以某种方式被这个错误弄糊涂。我也无法在进一步的断点处停止,直到我添加代码来引用 argc/argv,或者将 main(在 C++ 中)重新声明为“int main(int, char *[])”,以便 Eclipse 不期望那些符号。
There is still an error in the gdb output window (no symbol "new" in the current context?), but breakpoints can be set.
gdb 输出窗口仍然有错误(当前上下文中没有符号“new”?),但可以设置断点。
HTH, -nick
HTH,-尼克