Find segment errors using GDB and core

Source: Internet
Author: User
Tags file size
Find segment errors using GDB and core

Use GDB and core to find a segment error when a program appears with a segment error, the following prompt appears to view the core file size limit change it to an unrestricted Run command example

1. When a program appears with a segment error, the following prompt appears:

Segmentation fault (core dumped)

Core refers to the memory distribution of process space when the program is running
Dumped says the kernel has thrown the core
In general, a core file should be automatically generated in the program run directory when a segment error occurs, but the core file cannot normally be generated because the Linux environment generally defaults to a core file limit of 0. 2. View the core file size limits:

Ulimit-c

3. Change it to unlimited:

Ulimit-c Unlimited


Once this is set, a core file is generated if a segment error occurs.
After compiling the program with the-G option, run the program to get the core file, and with GDB you can find the location of the segment error 4. Run command

GDB A.out Core
5. Sample code:

The program ran a segment error:

do the following:


Following the steps shown above, it is easy to get a segment error on line 5th of the test.c file (under the test function, called by the main function)

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.