Coredump technology to find the cause of the crash

Source: Internet
Author: User

There was a problem in the recent project where the server-side program suddenly crashed and exited, and we took the Coredump technology to find the cause of the crash, which is determining which function is executing when the process exits, and what its status is.

If the system is coredump, it is accurate to say that if the current shell environment is open coredump, the current shell environment of the program crash exit, will be the memory state of the stack of the process to write to the core file. Using GDB, you can view the status of the stack saved in this core file, GdB a.out core. (About coredump and understanding of the shell, please refer to my other blog, "opened by the coredump of the shell of the in-depth inquiry," about GDB please refer to the GDB watch stack memory layout)

The location where the core file is generated defaults to the location where the executable file is located, the name defaults to core, and the location and name can be set, and my settings are:

Mkdir/home/corefile

echo "/home/corefile/core-%e-%p-%t" >/proc/sys/kernel/core_pattern

In this way, the resulting core file is placed in the/home/corefile directory, and the core file name appears in Core-%e-%p-%t, where%e represents the name of the executable,%p represents the process, and%t indicates when the core file was generated (note Unix time).

The following is a routine that can cause Coredump:

#include <stdio.h>

int square (INTA, int b) {

int ret;

int *p = NULL;

*p = 666;

return ret;

}

int Docalc (INTNUM1, int num2) {

int ret = Square (NUM1, num2);

return ret;

}

int main () {

int param1 = 1;

int param2 = 2;

int result = Docalc (param1, param2);

printf ("Result was%d\n", result);

}

The line will cause the coredump to take place. After execution, the following files are generated in the/home/corefile directory:

[root@localhostwin7]# ls/home/corefile/

core-a.out-5082-1490760381

A.out is the executable file name, 5082 is pid,1490760381 is the Unix time that generated the file. Put the a.out and core files in a directory, using the command:

GDB a.out core-a.out-5082-1490760381

Enter GDB and then use the BackTrace command to see the memory state of the stack at the time the process exits, as follows:

(GDB) bt

#0 0x00000000004005ba in Square (A=1, b=2) at Gdbtest.cpp:7

#1 0x00000000004005e2 in Docalc (Num1=1, num2=2) at Gdbtest.cpp:12

#2 0x000000000040060f in Main () gdbtest.cpp:19

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.