Coredump of C code

Source: Internet
Author: User

Important: The core code file is generated after the program terminates abnormally, adding the-G compilation option, which contains debug information. Locating outliers with GDB and Coredump files


When the program terminates abnormally, it generates coredump files, different systems, different settings, and this automatically generated Coredump file is not the same.


Sample code:

#include <stdio.h>
 
int core_dump () {
    int i;
 
    for (i = 5; I >= 0; i--) {
        printf ("(%d,%d) \ n", I, 100/i);
    }
 
    return 0;
}
 
int main () {
    core_dump ();
 
    return 0;
}

The code above has 0 exceptions, compiled to run:

Gcc-g core_dump.c-o core_dump
./core_dump

Run Result:

(5)
(4)
(3,)
(2)
(1, MB)
[1]    

To find out more clearly where the code went wrong, you can use GDB to parse the Coredump file:
~/examples/cpp/core_dump% gdb./a.out Core GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GP lv3+: GNU GPL version 3 or later  

You can see that no specific code & line number is given, because the-G compilation option needs to be added. Recompiling and running this time, the COREDUMNP file provides comprehensive information:
~/examples/cpp/core_dump% gdb./a.out Core GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GP lv3+: GNU GPL version 3 or later  

Add:

Of course, not all exceptions will generate Coredump files, please refer to "UNIX Environment Advanced Programming (2nd)," the tenth chapter signal. Some environments default to set the Coredump file to 0 bytes, which requires ulimit-c 1024 (file size).

Ulimit-c Unlimited

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.