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