简体   繁体   中英

Eclipse/MinGW/CDT/GDB and problems with debugging

I have some C++ code and try to debug it. main.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:

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?

This seems to be a relatively frequent reoccurring issue when using eclipse +cdt with gdb. Changing the default launcher from GDB (DSF) Create Process to Standard Create Process seems to solve the issue most of the time.

You can find this option under Preferences->Run/Debug->Launching->Default Launchers :

默认启动器

Also make sure you are compiling with -g debug info enabled.

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()':

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

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.

You get the "Cannot access memory at address 0x0" from the gdb command line if 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.

This is true for C or C++ compilation.

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 until I 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.

There is still an error in the gdb output window (no symbol "new" in the current context?), but breakpoints can be set.

HTH, -nick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM