详细内容见man文档:
man 5 core。http://man7.org/linux/man-pages/man5/core.5.html
man ulimit
把上面的man文档看一遍就差不多了。
我遇到的问题是,没能成功生成coredump文件。
解决办法:使用ulimit 改变core文件大小限制。
$ ulimit -S -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 24110 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
$ ulimit -S -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 24110 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
注意这样只对当前终端有效。
设置好core 文件大小之后,可以调试一个core dump文件练练手。可以使用gdb 进行调试。
例子:
代码
main.c
int main() { char *p = "helloworld"; p[0] = 'h'; return 0; }
./main
会产生coredump文件,core.8151
gdb main core.8151 注意用gdb调试要带上原来的可执行文件,后面加上coredump文件。
$ gdb main core.8151 GNU gdb (GDB) Fedora (7.4.50.20120120-50.fc17) Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/huntinux/work/linker_loader/coredump/main...done. [New LWP 8151] Core was generated by `./main'. Program terminated with signal 11, Segmentation fault. #0 0x080483e0 in main () at main.c:4 4 p[0] = 'h'; Missing separate debuginfos, use: debuginfo-install glibc-2.15-57.fc17.i686 (gdb) l 1 int main() 2 { 3 char *p = "helloworld"; 4 p[0] = 'h'; 5 6 return 0; 7 } (gdb) b 4 Breakpoint 1 at 0x80483dd: file main.c, line 4. (gdb) r Starting program: /home/huntinux/work/linker_loader/coredump/main Breakpoint 1, main () at main.c:4 4 p[0] = 'h'; (gdb) s Program received signal SIGSEGV, Segmentation fault. 0x080483e0 in main () at main.c:4 4 p[0] = 'h';
参考: http://prefetch.net/blog/index.php/2012/01/19/using-the-automated-bug-reporting-tool-abrt-to-generate-core-dumps-when-a-linux-process-fails/
http://man7.org/linux/man-pages/man5/core.5.html