Software debugging technology (2)--coredump How to implement _php tutorial

Source: Internet
Author: User

Software debugging technology (2)--coredump how to implement


Recently learned in the work of the application software in the crash can be set to build dump files, this function is coredump. Whether the application crashes or the kernel crash dump feature is a practical technique. This paper is to understand the implementation of these two technologies from the perspective of the principle of implementation. First, analyze the implementation of application Coredump.

What conditions trigger the dump
This dump occurs when the application receives a fatal signal, and when the signal is processed, the application is dumped and then exited to execute. It is important to note that if a user installs a custom handler for these fatal signal, the dump will not happen. OK, so here's a summary of two points:
1, the fatal signal will start to dump the occurrence, these signal include the following content.

    1. 398 #define SIG_KERNEL_COREDUMP_MASK (\
    2. 399 Rt_sigmask (Sigquit) |rt_sigmask (Sigill) |\
    3. Rt_sigmask (SIGTRAP) |rt_sigmask (SIGABRT) |\
    4. 401 Rt_sigmask (SIGFPE) |rt_sigmask (SIGSEGV) |\
    5. 402 Rt_sigmask (Sigbus) |rt_sigmask (Sigsys) |\
    6. 403 Rt_sigmask (SIGXCPU) |rt_sigmask (SIGXFSZ) |\
    7. 404 Sigemt_mask
2, Coredump will not occur if the above fatal signal is installed by the user with a custom handler function.

    1. 2264if (KA->SA.SA_HANDLER!=SIG_DFL) {
    2. 2265/*run the handler.*/
    3. 2266 ksig->ka=*ka;
    4. 2267
    5. 2268if (Ka->sa.sa_flags&sa_oneshot)
    6. 2269 ka->sa.sa_handler=sig_dfl;
    7. 2270
    8. 2271 Break;/*will return Non-zero "Signr" value*/
    9. 2272}
In kernel find need to deal with the signal, first will determine whether this signal is the default processing mode, if the default processing will continue to execute to the Coredump branch, or jump out of the search link, perform user-defined processing mode.

The branch that triggered the Coredump execution

    1. 2335if (Sig_kernel_coredump (SIGNR)) {
    2. 2336if (Print_fatal_signals)
    3. 2337 print_fatal_signal (Ksig->info.si_signo);
    4. 2338 Proc_coredump_connector (current);
    5. 2339/*
    6. 2340*ifit was abletodump core,this kills all
    7. 2341*other threadsinthe groupandsynchronizes with
    8. 2342*their demise. Ifwe lost the race with another
    9. 2343*thread getting Here,itsetgroup_exit_code
    10. 2344*firstandour Do_group_exitcallbelow would use
    11. 2345*that Valueandignore The one we pass it.
    12. 2346*/
    13. 2347 Do_coredump (&ksig->info);
    14. 2348}


Tips for printing a fatal signal to the console
If you open the option under the proc directory below, the ability to print the fatal signal to the console will be turned on.
/proc/sys/kernel/print-fatal-signals

Coredump Main steps
In fact, the process of writing this application to disk is certainly very responsible. I'm not going to buckle up here. No details, some of the original rational details may be pushed to the back part of the detailed study and analysis. However, here are a few of the key processes that we need to know about coredump.
1, between Coredump, first check whether all threads in the thread group have entered hibernation. We want Coredump to make sure that some of the threads in the process are still running and overwriting the memory space while copying the memory space of the process.
2, there is nothing special about switching the process memory directly to a file, which is to open a file and start writing.
3, for the development of a user space script, to do some compression operations, here will start a user-state process, and the kernel and user-state process to establish a pipeline between the
kernel========= Read =========== user-state process (compression)-----------Write--------> file

For the first step, kernel wants all threads in the process group to send a kill signal signal, and then waits for all processes to be out of the running state.
For the second step, the process is relatively straightforward, but if you are interested, you can delve into what the format of the Coredump file looks like.
The third step, relatively complex, the more ingenious place is to establish a pipeline in the kernel, kernel processing signal part will coredump write to the pipeline, and the new process in the pipeline is set to the other end of the standard input.

Methods for compressing process dumps
We can build a shell execution file
#!/bin/sh
Execgzip->/root/$1.core.$2.gz
Then write in the/proc/sys/kernel/core_pattern
|/usr/sbin/core_helper%e%p

http://www.bkjia.com/PHPjc/1086427.html www.bkjia.com true http://www.bkjia.com/PHPjc/1086427.html techarticle Software Debugging technology (2)--coredump How to realize recently in the work of the application software in the crash can be set up the generation of dump files, this function is coredump. Whether it is application ...

  • 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.