Linux uses core and GDB queries for "segment errors" where __linux

Source: Internet
Author: User
Sometimes we are in a section of C code, because of an illegal memory operation, in the process of running the program, there is a "segment error."
Oh, this kind of question I think a lot of people will often encounter. Encountered this problem is very silent, just prompted the "paragraph error", and then nothing, if we blindly to see the code to find too painful, because we all believe that their own code to write no problem, the reality is reality. Here is a method that can be used to locate the "section of the wrong place" effectively.
When our program crashes, it is possible for the kernel to map the current memory of the program to the core file, so that the programmer can find out where the program is having problems.
What is core dump? Core means memory, dump means to throw it out and heap it out.
Why is there no core file generation?
Sometimes the program down, but the core file is not generated. core file generation and your current system environment settings are related, you can use the following statement to set up the core file will be generated
Ulimit-c Unlimited
Core files are generated in the same location as the path where the program is run, and in Ubuntu the filename is typically core.
What is a core file the stored image of the process is replicated in the core file of the current working directory of the process when a program is crashing. The core file is just a memory image (plus debugging information) that is used primarily for debugging.
Let's take a look at how to use the core file to locate the "segment error" where we appear.



Program Run Result:



From the above we can see that the first run of the program appears "segment error" does not appear core files, the general Linux operating system default core file size is 0, you need to manually set up. Debug core file Core file is a binary file, you need to use the appropriate tools to analyze the memory image when the program crashes.
Linux can be used to debug core files with GDB.


From the above we can clearly see that our program is where the error occurred.
Oh, with this method, I think we can not be so afraid of "paragraph mistake".
Related Article

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.