No Source File Named Main. C. Gdb Break Point Setting

I am using gdb for debugging C project source code. I compile as shown:

./configure --enable-debug CFLAGS="-g -o0" 
make --debug=a

I want to debugging stop at specific file. So when I set break point by using

(gdb) break main.c:672

It says:

No source file named main.c.

Even when I pass specific function name (in main.c file) to break . it says: such function not defined.

My current directory has this main.c file. I am using Cygwin on Windows. When I set break point by using

(gdb) break main

It set break point at a main function of Cygwin file, not in my source code.

  1. how can I fix my first problem?

  2. just curious, how to avoid second problem, if there is same function name within Cygwin files and my source code?

5 Answers

When you compile your .c file, make sure you use:

gcc filename.c -g 

gdb <binary name>

Search for load debugging symbols done or not?

If not:

gdb) symbol-file <path-of-symbol-file>

you can find symbol file in obj directory

7

If you're compiling with -g and still not able to set a breakpoint, try adding raise(SIGTRAP) in your main(), run the process in gdb, then set the breakpoint you want again after it hits the SIGTRAP.

Crucial is gcc parameter -g during compilation.

Everything else is secondary.

See breakpoints in GDB

I also encountered with similar problem earlier. I just deleted .metadata folder and imported the particular project again and that work well.

0

Whenever you have to use GDB, type the following in command line

gcc -g -o outputfile sourcefile.c

Now type

gdb -tui outputfile

and then enter the break command

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest