$ coredumpctl info 3252 PID: 3252 (segv.sh) UID: 1000 (unamu) GID: 1000 (unamu) Signal: 11 (SEGV) Timestamp: Sun 2020-12-06 22:29:21 JST (6min ago) Command Line: /bin/bash ./segv.sh Executable: /usr/bin/bash Control Group: /user.slice/user-1000.slice/user@1000.service/gnome-terminal-server.service Unit: user@1000.service User Unit: gnome-terminal-server.service Slice: user-1000.slice Owner UID: 1000 (unamu) Boot ID: 35a2b597dc5a4a6ebe37fd3a7e97bd73 Machine ID: c4f822f021d5433ab143f054bca5b672 Hostname: localhost.localdomain Storage: /var/lib/systemd/coredump/core.segv\x2esh.1000.35a2b597dc5a4a6ebe37fd3a7e97bd73.3252.1607261361000000.lz4 Message: Process 3252 (segv.sh) of user 1000 dumped core. Stack trace of thread 3252: #0 0x00007fe849946d79 _int_malloc (libc.so.6) #1 0x00007fe84994850e malloc (libc.so.6) #2 0x00005625a34934c2 xmalloc (bash)
coreファイルのファイルサイズの変更
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ cat /proc/self/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size unlimited unlimited bytes Max resident set unlimited unlimited bytes Max processes 3140 3140 processes Max open files 1024 262144 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 3140 3140 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
の Max core file size の項目がCoreファイルサイズの設定になります。 softlimitが0だとcoreファイルが作成されません。
unlimitedに設定すると上限なしで作成してくれます。
1
$ ulimit -c unlimited
OSを再起動すると元の設定値に戻ります。
SIGSEGVエラーを出して、coreファイルが作成されている確認する
下記のシェルスクリプトを実行して、SIGSEGVエラーを出す。
segv.sh
1 2 3 4 5
#!/bin/bash function func { func } func
1 2 3 4
# ./segv.sh Segmentation fault (コアダンプ) # ls /tmp core-segv.sh-41856
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-11.el8 Copyright (C) 2018 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". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /bin/bash...Reading symbols from .gnu_debugdata for /usr/bin/bash...(no debugging symbols found)...done. (no debugging symbols found)...done.
warning: core file may not match specified executable file. [New LWP 41856]
warning: Loadable section ".note.gnu.property" outside of ELF segments Core was generated by `/bin/bash ./segv.sh'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x000055b592ffb6db in expand_word_list_internal () Missing separate debuginfos, use: yum debuginfo-install bash-4.4.19-10.el8.x86_64 (gdb)
gdbの対話モードになったら bt or backtrackでコアダンプされる前の状態をさかのぼって原因を調査できます。
1 2 3 4 5 6 7 8 9 10 11
(gdb) bt #0 0x000055b592ffb6db in expand_word_list_internal () #1 0x000055b592fd2fa7 in execute_simple_command () #2 0x000055b592fd51a6 in execute_command_internal () #3 0x000055b592fd4ab5 in execute_command_internal () #4 0x000055b592fd7a79 in execute_function.isra () #5 0x000055b592fd4124 in execute_simple_command () #6 0x000055b592fd51a6 in execute_command_internal () #7 0x000055b592fd4ab5 in execute_command_internal () #8 0x000055b592fd7a79 in execute_function.isra () #9 0x000055b592fd4124 in execute_simple_command ()