Linux core dump Ben rout out the diagnostic process

       A recent project in question, the server-side program will quit suddenly collapse, we took a coredump technology to find the cause of the crash, which determine the function exits when the process is being executed is which, how its status.
       If the system is turned on coredump, accurate to say that if the current shell environment opens the coredump, under the current program to exit the shell environmental collapse, will then process the stack memory status is written core file. Using gdb can view the saved file in the core state of the stack, gdb a.out core. (Open and understanding of coredump to the shell, refer to my another blog "in-depth exploration of the shell caused by the open coredump" and about gdb refer to "GDB observation stack memory layout")
       position of the core files generated the default is the location of the executable file is located, the name defaults to the core, its location and name can be set, I set to:
                                                                                            mkdir / Home / CoreFile
echo "/ Home / CoreFile / E- core-%%% p-t "> / proc / sys / kernel / core_pattern
       Thus, the generated files are placed in a core / home / corefile the directory, the file name of the core appears in the form of core-% e-% p-% t, where% e represents name of the executable file,% p means the process,% t represents time generate core files (note the unix time).
       Here is a coredump routine can lead to:

#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 is %d\n",result);
}

       Crossed will lead to coredump place. Will produce the following files in / home under / corefile directory after execution:
[root @ localhostwin7] # LS / home / corefile /
 
 
 
 
core-a.out-5082-1490760381
 
 
 
 
a.out is the executable file name, 5082 is the PID, 1490760381 is to produce the document unix time. The a.out and core files in a directory, use the command:
gdb a.out core-a.out-5082-1490760381
enter gdb, and then use the backtrace command, you can see the state of the stack memory when the process exits, as follows below:

(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 () at gdbtest.cpp:19

       Visible, when the process exits, the last execution of a function is square function.
---------------------
Author: yunlong32
Source: CSDN
Original: https: //blog.csdn.net/u014585564/article/details/68063269
Disclaimer: This article as a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/xibuhaohao/p/11060200.html