DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

什么是core dump?
Coredump叫做核心转储,它是进程运行时在突然崩溃的那一刻的一个内存快照。操作系统在程序发生异常而异常在进程内部又没有被捕获的情况下,会把进程此刻内存、寄存器状态、运行堆栈等信息转储保存在一个二进制文件里。

设置core dump文件大小,默认0,即不会生成core文件

ulimit -c unlimited
设置core dump文件的位置文件名格式,%e和%p会被替换成程序文件名以及进程ID。缺省情况下,内核在coredump时所产生的core文件放在与该程序相同的目录中,并且文件名固定为core。

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

core文件调试
1:
编译加-g参数
2:
gdb program core

手动生成core文件
程序卡死的时候,有时需要把卡死状态保持起来,生成core文件,然后慢慢分析。

gcore
usage: gcore [-o filename] pid
gdb的generate-core-file命令
[root@htdev ~]# gdb attach 19388
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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"...
attach: No such file or directory.
Attaching to process 19388
Reading symbols from /usr/local/bin/node...done.
Reading symbols from /lib64/librt.so.1...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /lib64/libdl.so.2...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /usr/lib64/libstdc++.so.6...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libpthread.so.0...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x2b46ed999890 (LWP 19388)]
[New Thread 0x43e62940 (LWP 19399)]
[New Thread 0x43461940 (LWP 19398)]
[New Thread 0x42a60940 (LWP 19397)]
[New Thread 0x4205f940 (LWP 19396)]
[New Thread 0x41018940 (LWP 19390)]
[New Thread 0x41007940 (LWP 19389)]
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libc.so.6...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /root/eicn/work/web/node_modules/hiredis/build/Release/hiredis.node...done.
Loaded symbols for /root/eicn/work/web/node_modules/hiredis/build/Release/hiredis.node
0x000000364b4d06d9 in syscall () from /lib64/libc.so.6
(gdb) generate-core-file
Saved corefile core.19388
(gdb) detach
Detaching from program: /usr/local/bin/node, process 19388

设置core文件路径
1.编辑环境配置文件,让shell启动时自动设置ulimit
2.更改core文件生成路径
3.sysctl配置生效
vi /etc/profile
ulimit -c unlimited > /dev/null 2>&1
vi /etc/sysctl.conf
kernel.core_uses_pid = 1
kernel.core_pattern=/tmp/core-%e-%p
sysctl -p /etc/sysctl.conf

posted on 2021-05-10 18:04  DoubleLi  阅读(1152)  评论(0编辑  收藏  举报