1. Compiling source code
C:mingw\bin>gcc.exe-g-O program.exe program.c
Compile the option to add "G", so that the generated target program will contain debugging content, and then debugging with GDB to use. Obviously with the "G" option, the resulting application will be larger than the non-additive, but there is no difference between running them.
2, start debugging
C:mingw\bin>gdb.exe Program.exe
3. Set breakpoints and start running
(GDB) Break Main
(GDB) Start
Cannot start directly, because the program runs too fast, the direct start runs to the point where the program stops.
Break main sets the breakpoint that the program runs before the start command, so that the program runs to main at the end of the start. You can also use the command "Break Filename:lineno", which will stop at the Lineno specified line of the file specified by FILENAME, such as "Break Mycode.cpp:4".
4. Other commands
print VARNAME
. That's how you print values of variables, whether local, static, or global. For example, on for
the loop, you can type to print out the print temp
value of the temp
variable.
step
This was equivalent to "step into".
next
or adv +1
Advance to the next line (as "Step Over"). You can also advance to a specific line of a specific file with, for example adv mycode.cpp:8
.
bt
Print a backtrace. This is a stack trace, essentially.
continue
Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.
Reference: Http://stackoverflow.com/questions/4671900/ How-do-i-use-the-mingw-gdb-debugger-to-debug-a-c-program-in-windows