Search code examples
cgdbcygwinbreakpoints

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?


Solution

  • 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.