Talk GCC together (sixth time: GCC debugging), talkgcc

Source: Internet
Author: User

Talk GCC together (sixth time: GCC debugging), talkgcc


Hello, the last time we talked about GCC optimization. In this case, let's talk about how to use GCC for debugging,

When you leave the rest of your time, your words will go right. Let's talk GCC together!


As we all know, sometimes errors occur when people write code. Sometimes it may cause compilation errors, and sometimes it may cause logical errors.

Error. Of course, experienced programmers will not cause compilation errors such as low-level errors, but logical errors will always exist more or less. Program output

Wrong. What should I do? It must have been a modification error. Haha, do you still need to say this. Errors are caused by unknown information.

Modification errors, especially logical errors, are still difficult. However, do not worry. GCC will provide debugging functions for your convenience

Errors in the program. The debugging function of GCC must be used together with GDB. We will talk about the content of GDB later.

As long as you understand it, GCC will help you find errors in the program.


The debugging function of GCC is mainly to write debugging information into the target file generated by compilation during compilation, and GDB will use this debugging letter

. The debugging function of GCC is also implemented through options. The usage of option g is the same as that of option O. If you still remember

We have to say option O in the previous one. So it is quite easy to understand the usage of option g. In any case, let's give an example:


Gcc-gn file. c-o f. o


In this example, n is a number ranging from 1 to 3. The larger the number, the more debugging information is added. If no number is added, the default value of n is 2. That is

Use g2 for debugging. Because GCC needs to write debugging information in the target file, the size of the target file will be increased. This is a debugging task.

A negative impact. For this reason, by default, GCC does not add debugging information to the target file generated by compilation. In my

When using GCC to compile a program, g2 is usually enough, so that debugging information can be added to the target program without excessive

Increase the size of the target program.


Let's talk about GCC today. I want to know what to do later, and listen to the next decomposition!


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.