Talk to GCC (sixth: GCC debugging)

Source: Internet
Author: User


Hello, everyone, crossing, last time we were talking about GCC optimization-related content. This time we're going to talk about how to use GCC for debugging,

Gossip Hugh, words return to the positive. Let's talk about GCC together!


Crossing, as we all know, people sometimes make mistakes when they write code. Sometimes it causes a compile error, sometimes it causes a logic fault.

Miss. Of course, experienced programmers do not cause the low-level errors of compilation errors, but logic errors, more or less always there. Program out

Wrong, what to do? It must have been a mistake, haha, it is still used to say. Errors are caused by people who do not know, so want to

There are some difficulties in modifying errors, especially logic errors. But crossing don't worry. GCC will provide debugging functions to facilitate everyone to find

Errors in the program. The debugging capabilities of GCC need to be combined with GDB to be used. On GDB's content, we will later say that we are now

As long as you understand, GCC will help you find bugs in your program.


The debugging function of GCC is to write debug information to the compiled generated target file during compilation, and then GDB will use such a debug letter

For debugging. The debugging capabilities of GCC are also implemented by options, and the use of option G is exactly the same as the use of option O. If you remember

The option that we said in the last time O. Then it is quite easy to understand the use of option G. Anyway, let's give an example:


GCC-GN File.c-o F.O


In the example, N is a number from 1 to 3, the larger the number, the more debug information is added, and if no number is added, the default value of N is 2.

Use G2 for debugging. Because GCC needs to write debug information in the destination file, it increases the size of the target file. This is also a debug

can have a negative effect on it. For this reason, GCC does not add debug information to the build-generated target file by default. In my

When using GCC to compile the program, usually the G2 is sufficient, so that you can add debug information in the target program, without too much

Increase the size of the target program.


Crossing, here's what we're going to say about GCC today. Want to know how to funeral, and listen to tell!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk to GCC (sixth: GCC debugging)

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.