Debugging Tools Gdb.exe debugging C programs under Windows using MinGW

Source: Internet
Author: User
Tags stack trace

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.
  • stepThis was equivalent to "step into".
  • nextor 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 .
  • btPrint a backtrace. This is a stack trace, essentially.
  • continueExactly 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.