Skip to content

Core dump file configuration and debugging.

eeliu edited this page Jul 10, 2024 · 1 revision

Description

Core dump files provide a snapshot of a system’s memory and process information, and are therefore useful when generated before a process crashes or otherwise exits abnormally. Core dumps are often used to assist in diagnosing and debugging errors in computer programs.

Enable core dump file

You can check whether core dump files are enabled with the following command:

ulimit -c

By default core dump files are disabled, in which case this command will return 0. To enable core dump files, use the following command:

ulimit -c unlimited

The unlimited argument refers to the core dump file size. By effectively removing a file size limit, we prevent the file from being truncated and from losing out on any useful information.

Degugging core file

To debug core file, for example: core file's name is "core.httpd.31999", use the following command:

gdb /*path to httpd*/httpd core.httpd.31999

Then you may get infomation like follows:

[test@naver corefile]$ gdb /home/test/apps/apache/httpd-2.4.34-all/bin/httpd core.httpd.31999
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7
Copyright (C) 2013 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/test/apps/apache/httpd-2.4.34-all/bin/httpd...done.
[New LWP 31999]

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./bin/httpd -k start'.
Program terminated with signal 6, Aborted.
#0  0x00007ff2d3cff989 in raise () from /lib64/libc.so.6
(gdb)

To display the program stack, input "bt" or "where", you may see program stack like follows:

(gdb) bt
#0  0x00007ff2d3cff989 in raise () from /lib64/libc.so.6
#1  0x00007ff2d3d01098 in abort () from /lib64/libc.so.6
#2  0x00007ff2d3cf88f6 in __assert_fail_base () from /lib64/libc.so.6
#3  0x00007ff2d3cf89a2 in __assert_fail () from /lib64/libc.so.6
#4  0x00007ff2cf7c24dd in _zend_hash_add_or_update_i (ht=0x7ff2c9e677e0, key=0x7ff2bab76100, pData=0x7fffeb4b5b60, flag=8, __zend_filename=0x7ff2d0016e98 "/home/test/tools/php-7.2.3/Zend/zend_builtin_functions.c", __zend_lineno=2554)
    at /home/test/tools/php-7.2.3/Zend/zend_hash.c:549
#5  0x00007ff2cf7c2962 in _zend_hash_add_new (ht=0x7ff2c9e677e0, key=0x7ff2bab76100, pData=0x7fffeb4b5b60, __zend_filename=0x7ff2d0016e98 "/home/test/tools/php-7.2.3/Zend/zend_builtin_functions.c", __zend_lineno=2554) at /home/test/tools/php-7.2.3/Zend/zend_hash.c:638
#6  0x00007ff2cf7d3076 in zend_fetch_debug_backtrace (return_value=0x7fffeb4b5ce0, skip_last=0, options=1, limit=1) at /home/test/tools/php-7.2.3/Zend/zend_builtin_functions.c:2554
#7  0x00007ff2c335597f in call_php_kernel_debug_backtrace (skip_last=0, frame=..., options=1) at /home/test/apps/p-github/pinpoint_php/php_function_helper.cpp:156
#8  0x00007ff2c333ba14 in pp_execute_plugin_core (internal=0, execute_data=0x7ff2c9e87000, return_value=0x0) at /home/test/apps/p-github/pinpoint_php/aop_hook.cpp:444
#9  0x00007ff2c333bc59 in pp_execute_ex (execute_data=0x7ff2c9e87000) at /home/test/apps/p-github/pinpoint_php/aop_hook.cpp:575
#10 0x00007ff2cf7ec5d3 in zend_generator_resume (orig_generator=0x7ff2c9e84000) at /home/test/tools/php-7.2.3/Zend/zend_generators.c:814
#11 0x00007ff2cf7ed862 in zend_generator_iterator_move_forward (iterator=0x7ff2c9e81180) at /home/test/tools/php-7.2.3/Zend/zend_generators.c:1159
#12 0x00007ff2cf834321 in ZEND_FE_FETCH_R_SPEC_VAR_HANDLER () at /home/test/tools/php-7.2.3/Zend/zend_vm_execute.h:16921
#13 0x00007ff2cf891c83 in execute_ex (ex=0x7ff2c9e1c030) at /home/test/tools/php-7.2.3/Zend/zend_vm_execute.h:60817
#14 0x00007ff2c333bada in pp_execute_plugin_core (internal=0, execute_data=0x7ff2c9e1c030, return_value=0x0) at /home/test/apps/p-github/pinpoint_php/aop_hook.cpp:481
#15 0x00007ff2c333bc59 in pp_execute_ex (execute_data=0x7ff2c9e1c030) at /home/test/apps/p-github/pinpoint_php/aop_hook.cpp:575
#16 0x00007ff2cf895a08 in zend_execute (op_array=0x7ff2c9e7a200, return_value=0x0) at /home/test/tools/php-7.2.3/Zend/zend_vm_execute.h:63760
#17 0x00007ff2cf7afa8d in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/test/tools/php-7.2.3/Zend/zend.c:1496
#18 0x00007ff2cf71da66 in php_execute_script (primary_file=0x7fffeb4b8910) at /home/test/tools/php-7.2.3/main/main.c:2590
#19 0x00007ff2cf8981c6 in php_handler (r=0x13f7680) at /home/test/tools/php-7.2.3/sapi/apache2handler/sapi_apache2.c:701
#20 0x0000000000452880 in ap_run_handler (r=r@entry=0x13f7680) at config.c:170
#21 0x0000000000452dc9 in ap_invoke_handler (r=r@entry=0x13f7680) at config.c:444
#22 0x000000000046870a in ap_process_async_request (r=0x13f7680) at http_request.c:453
#23 0x00000000004689ce in ap_process_request (r=r@entry=0x13f7680) at http_request.c:488
#24 0x0000000000464b75 in ap_process_http_sync_connection (c=0x13ed820) at http_core.c:210
#25 ap_process_http_connection (c=0x13ed820) at http_core.c:251
#26 0x000000000045c3b0 in ap_run_process_connection (c=c@entry=0x13ed820) at connection.c:42
#27 0x000000000045c8d8 in ap_process_connection (c=c@entry=0x13ed820, csd=<optimized out>) at connection.c:219
#28 0x00007ff2d38c2979 in child_main (child_num_arg=child_num_arg@entry=3, child_bucket=child_bucket@entry=0) at prefork.c:615
#29 0x00007ff2d38c2bd2 in make_child (s=0x11d43e0, slot=slot@entry=3, bucket=0) at prefork.c:716
#30 0x00007ff2d38c2c46 in startup_children (number_to_start=2) at prefork.c:735
#31 0x00007ff2d38c358b in prefork_run (_pconf=<optimized out>, plog=0x11d8358, s=0x11d43e0) at prefork.c:901
#32 0x0000000000435a9e in ap_run_mpm (pconf=pconf@entry=0x11ab138, plog=0x11d8358, s=0x11d43e0) at mpm_common.c:94
#33 0x000000000042eaeb in main (argc=3, argv=0x7fffeb4b9008) at main.c:819
(gdb)

At last input "q" to exit from GDB.


Further more, a core dump file's default name is "core". The core dump file is generally found in the location defined by the core_pattern file, which can be viewed with the following command:

cat /proc/sys/kernel/core_pattern

To change the name as "core.filename.pid" and location as "/data/coredump", you can use the followint command:

echo “/data/coredump/core.%e.%p”> /proc/sys/kernel/core_pattern

ps: To execute this command, current login-user must has root privileges
The /proc/sys/kernel/core_pattern file (since Linux 2.6 and 2.4.21) can be set to define a template that is used to name core dump files. The template can contain % specifiers which are substituted by the following values when a core file is created:

  • %%: a single % character
  • %p: PID of dumped process
  • %u: (numeric) real UID of dumped process
  • %g: (numeric) real GID of dumped process
  • %s: number of signal causing dump
  • %t: time of dump, expressed as seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
  • %h: hostname (same as nodename returned by uname(2))
  • %e: executable filename (without path prefix)
  • %E: pathname of executable, with slashes ('/') replaced by exclamation marks ('!').
  • %c: core file size soft resource limit of crashing process (since Linux 2.6.24)
Clone this wiki locally