Linux coredump 笔记
查看是否开启coredump
$ ulimit -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) 63220
max locked memory (kbytes, -l) 65536
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) 63220
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
core file size (blocks, -c) unlimited
表示已开启coredump。
开启coredump,当前进程生效。
ulimit -c unlimited
开启coredump,全局生效。
vim /etc/profile #在profile文件末尾追加
ulimit -c unlimited
source /etc/profile #不重启电脑使配置生效
修改coredump文件保存位置
修改/proc/sys/kernel/core_pattern
文件,添加如下配置。
echo '/var/log/core-%e-%p-%t' > /proc/sys/kernel/core_pattern
如果提示无法修改文件,bash: /proc/sys/kernel/core_pattern: Permission denied
,则尝试如下命令
sudo bash
echo '/var/log/core-%e-%p-%t' > /proc/sys/kernel/core_pattern
%p - insert pid into filename 添加 pid
%u - insert current uid into filename 添加当前 uid
%g - insert current gid into filename 添加当前 gid
%s - insert signal that caused the coredump into the filename 添加导致产生 core 的信号
%t - insert UNIX time that the coredump occurred into filename 添加 core 文件生成时的 unix 时间
%h - insert hostname where the coredump happened into filename 添加主机名
%e - insert coredumping executable name into filename 添加命令名
gdb查看coredump日志
程序的编译参数最好带上-g
选项。
gdb exe_file core_file
启动程序:run
设置断点:b 行号|函数名
删除断点:delete 断点编号
禁用断点:disable 断点编号
启用断点:enable 断点编号
单步跟踪:next 也可以简写 n
单步跟踪:step 也可以简写 s
打印变量:print 变量名字
设置变量:set var=value
查看变量类型:ptype var
顺序执行到结束:cont
顺序执行到某一行: util lineno
打印堆栈信息:bt