11

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?

3
  • This code seems not complete (where does the graph template type come from?), but since the error seems not related to the contents of the file, all the graph stuff is distracting; I think a minimal code would be "int main() { /*line-break*/ return 0; /*line-break*/ }" and put a breakpoint on line "return 0;". Commented Nov 10, 2013 at 19:32
  • @gx_ Same problem with int main() { /*line-break*/ return 0; /*line-break*/ } Commented Nov 10, 2013 at 20:39
  • Simplify your PATH as much as possible (temporarily). I've seen eclipse having issues with valid path it did not like. Is this a makefile project? Try refering to paths in msys way (/c/users/home...). Commented Nov 11, 2013 at 7:58

3 Answers 3

12
+50

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:

Default Launchers

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

Sign up to request clarification or add additional context in comments.

7 Comments

I don't have a Standard Create Process; just the first displayed option, and Legacy Create Process.
standard was renamed to legacy. bugs.eclipse.org/bugs/show_bug.cgi?id=426586
Thanks that solved the issue for me, but I wander why Dsf does not function correctly
I have a project from Makefile with existing code and I have the same problem, but I can't find this menu option? Is it in the Makefile this setup or am I missing something?
@Elod Perhaps give Luna SR2 release a try -- it comes packaged with CDT 8.6.0. I just checked it out and the setup is the same except its renamed to Legacy Create Process as tzafrir pointed out. Make sure you have [Debug] selected in the 'Launch Type/Mode' otherwise 'Preferred Launcher' will be empty.
|
0

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

Comments

0

This problem still exists in 2024. It's cause by different path names in the generated objects, the path used by eclipse and the path wanted by gdb.

When eclipse tries to set a breakpoint, it uses the absolute windows path to that file. Gdb compares that to the paths it got from the executable.

The message:

No source file named C:\Users\home\workspace\graphcpp\main.cpp.

means that in the executable is a different path.

If you are using CDT generated makefile then the paths are relative

../main.cpp

Since I found no working mapping setup, I switched from the generated makefile to my own Makefile and ensured that the files get compiled with the absolute path. To achieve this I'm using the make variable $(DIR)

DIR       = $(subst \,/,$(PWD))

This variable is then used when an object gets compiled:

$(OUTDIR)/%.o: %.c Makefile $(HEADERS)
    $(CC) -c $(LDFLAGS) $(CFLAGS) $(patsubst %,$(DIR)/%,$<) -o $@

$(OUTDIR)/%.o: %.cpp Makefile $(HEADERS)
    $(C++) -c $(LDFLAGS) $(CFLAGS) $(C++FLAGS) $(patsubst %,$(DIR)/%,$<) -o

This results in object files having an absolute path usable by gdb

C:/Users/home/workspace/graphcpp/main.cpp

You may still need some mapping to locate the source files, but this can be achieved by using the Locate file button.

Here's my full Makefile

DIR       = $(subst \,/,$(PWD))

TARGETS   = test.exe
XTARGETS  = $(patsubst %,$(OUTDIR)/%,$(TARGETS))

HEADERS   = $(wildcard *.h)
SOURCES   = $(wildcard *.c)
RESOURCES = $(wildcard *.rc)
OBJECTS   = $(patsubst %.c,$(OUTDIR)/%.o,$(SOURCES)) $(patsubst %.rc,$(OUTDIR)/%.ro,$(RESOURCES))
LIBS      = -luxtheme -lcomctl32 -lgdi32

CFLAGS    = -g -O0

.PHONY: all pre
all: $(XTARGETS)

pre:
    mkdir -p $(OUTDIR)
    
$(OUTDIR)/test.exe: pre $(OBJECTS)
    gcc  -o $@ $(OBJECTS) $(USER_OBJS) $(LIBS)
    
$(OUTDIR)/%.o: %.c Makefile $(HEADERS)
    echo $(DIR)
    $(CC) -c $(LDFLAGS) $(CFLAGS) $(C++FLAGS) $(patsubst %,$(DIR)/%,$<) -o $@
    
$(OUTDIR)/%.ro: %.rc Makefile $(HEADERS)
    windres -O COFF $< -o $@

The variable $(OUTDIR) is set as custom build argument in the Eclipse C/C++ Build dialog of the project

OUTDIR=${ConfigName}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.