How about the -g flag? This the usual flag for gdb..
Correct GCC compile command for building exe (to use with gdb)
-
05-10-2022 - |
Question
I have a file called val_ref.c
and I compiled it using the command flag:
gcc val_ref.c -DDEBUG
after that, I opened gdb using the following command:
gdb a
% the resulting execuatable is called a
Then I used the following commands to set breakpoints and run the debugger:
(gdb) break main
(gdb) break incvar
(gdb) run
(gdb) continue
However, I cannot see the line-by-line proceeding information on the console. Instead, I see this:
I am not sure what I am doing wrong. For example, if I was to build this as a console application in VS2010 or Eclipse Kepler (with MinGW toolchain), and then run gdb
on the exec, it will work perfect, (I think). Seems like I am not adding the correct directives/flags in my compile. Can anybody help me with it?
Solution
OTHER TIPS
The best flags to use to compile for debugging are -g and -O0. -g causes GCC to add debugging information to the executable, and -O0 stops GCC enabling optimizations which would be confusing when debugging.