Linux debugging Skills 1

Source: Internet
Author: User
Linux debugging Tips 1-General Linux technology-Linux programming and kernel information. The following is a detailed description. I recently encountered a very depressing situation when I was developing a tool in LINUX to debug a BUG:

There is a segmentation fault somewhere. I am too lazy to use gdb, so I just added a few debugging information, compiled, and run it. The error message is displayed directly.

Well, before the last piece of information, the BUG will be subdivided, followed by debugging information, compilation, and running. Well, it will have to be further divided.

After 3 times, I am depressed. The real depressing bird ...... two messages, one of which can be normally displayed, followed by no statement in the middle-or multi-thread-the second message cannot be displayed! Rely on me! Who did I provoke? No interference

Okay, I am angry with the company. I went to GDB!

In the first call, it is even more depressing. Obviously, both statements are called normally. No error?

Let's take a closer look. Why is it not displayed even though printf is called normally? Check the code to find out the cause. There is no carriage return on the display information of the second statement.

The reason is: the LINUX printf () function does not immediately output the string to the device, but first stores it in a buffer, and then outputs the string to the device after the buffer is filled to a certain extent, therefore, if the program stops running before the buffer is filled up, congratulations! The content displayed after the last carriage return is lost.

SO, the way to improve the performance becomes the root cause of confusion in the debugging status. When using printf () to output debugging information, you must press Enter.

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.