Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No source file named main.c. gdb break point setting

Tags:

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?

like image 466
arslan Avatar asked Oct 03 '13 05:10

arslan


People also ask

How do I set a breakpoint in a specific file in gdb?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.

What is a break point in gdb?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.

What is a symbol file gdb?

symbol-file indicates that gdb should use this file as a reference for symbols and debug information. This includes translating a symbol (function or variable name) into an address, a line number into a code address or vice-versa, etc.


2 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

like image 129
Sohil Omer Avatar answered Sep 18 '22 10:09

Sohil Omer


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.

like image 28
wilywampa Avatar answered Sep 22 '22 10:09

wilywampa