3. Coredump Fault Analysis

Source: Internet
Author: User

3. Coredump Fault Analysis

First, the definition: Core dump is also called the kernel dump. When an exception occurs while the program is running, the Linux system can store the contents of the memory in a core file when the program goes wrong, called core Dump.

Second, Segment fault: This is the main solution of core dump error. Linux applications often encounter errors such as Segment fault (segment error) while they are running. The causes of such errors are usually:

    1. Array access is out of bounds.
    2. Accesses a null pointer.
    3. Stack overflow.
    4. Modifies read-only memory.

Third, Core dump enable

???? On Linux systems, the core dump function is turned off by default, but the core dump function can be turned on/off via the Ulimit command:

???? Open: Ulimit–c Unlimited

???? Close: Ulimit–c 0

???? Iv. Core file analysis.

???? After core dump occurs, you can use GDB to view the contents of the core file to locate where the program went wrong.

???? Usage: GDB Program name core file name

???? Example: GDB./test Core.core

???? Use Gdb+core file to find errors in the program.

Then there are two instances:

    1. To access a null pointer:

#include <stdio.h>

#include <stdlib.h>

?

void Main ()

{

int *ptr = NULL;

?

*ptr = 0;

}

But at this point we can not find the wrong information with GDB, this is because we just did not add-G at compile time, generate debugging information. Next, add debugging information. The following debugs see that he directly locates the wrong place:

?

2. Access to read-only memory.

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

?

void Main ()

{

???? Char ptr[] = "123456";

Ptr[0] = ' 7 ';

}

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

3. Coredump Fault Analysis

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.