core dump 2023-07-29

2023-07-28  本文已影响0人  9_SooHyun

Core Dump

what is it

In computing, a core dump, memory dump, crash dump, storage dump, system dump, or ABEND dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has crashed or otherwise terminated abnormally.

简而言之,core dump/crash dump就是一个由操作系统记录的进程死亡现场

causes of a core dump

A process dumps core when the operating system terminates it due to an error in the program. The most usual reason for this is that the program accessed an invalid pointer value.

core dump file

core dump 是一个在程序崩溃时由操作系统自动生成的文件,它的存储路径为/data/corefile/,文件名通常带有.{pid}后缀

它包含了程序崩溃时的内存快照、CPU寄存器状态以及其他与程序执行相关的信息。然而,core dump文件可能会包含敏感信息(如密码、密钥等),因此在处理core dump文件时应注意保护数据的安全和隐私。此外,core dump文件通常非常大,可能会占用大量磁盘空间,因此在生产环境中通常会限制core dump文件的大小或完全禁用core dump功能

设置 core dump file 大小

临时配置系统级 core dump

ulimit命令用于设置shell会话中进程的资源限制。要通过ulimit命令设置core dump的大小,执行ulimit -c查看当前会话允许的core dump文件大小限制,执行ulimit -c int设置当前会话允许的core dump文件大小

注意,使用ulimit命令设置的core dump大小限制仅适用于当前shell会话。当您关闭终端或启动新的shell会话时,这些设置将不再生效

持久配置系统级 core dump

在大多数Linux发行版中,可以在/etc/security/limits.conf文件中设置资源限制。例如,要将core dump文件大小限制设置为1 GB,请在文件末尾添加以下行:

#        - core - limits the core file size (KB)
* soft core 1048576
* hard core 1048576

这将为所有用户设置core dump文件的软限制和硬限制。保存文件并重新启动系统以使更改生效

对特定进程配置core dump

使用 gdb 分析core dump

  1. 使用gdb打开core dump文件和对应的可执行文件:

gdb your_executable your_core_dump_file

这将启动gdb并加载core dump文件

如果你不清楚core dump文件是哪个可执行文件产生的,可以使用gdb -c your_core_dump_file让gdb [尝试] 从core dump文件的元数据中获取可执行文件的信息。如果成功,gdb将自动加载对应的可执行文件

  1. 使用gdb中常用的分析命令进行分析调试:

许多编程IDE(集成开发环境)的调试器底层实际上是基于类似gdb这样的命令行调试工具。IDE将这些底层调试工具的功能封装成了图形界面,使得开发人员可以更方便地设置断点、查看变量值、单步执行代码等。

例如,在C和C++开发领域,许多流行的IDE(如Eclipse、Visual Studio Code、CLion等)都支持使用gdb作为底层调试器

  1. 样例
[root@VM-241-167-centos /data/devops/os/corefilecheck]# gdb proccore5 /data/corefile/core_proccore5_1690614962.30432
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.tl2
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 /data/devops/os/corefilecheck/proccore5...(no debugging symbols found)...done.
[New LWP 30432]
Core was generated by `./proccore5'.    ### Attention: mark core's generator here
Program terminated with signal 11, Segmentation fault.
#0  0x00007f685a89f9e0 in __nanosleep_nocancel () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install bash-4.2.46-34.tl2.3.x86_64 glibc-2.17-326.tl2.x86_64 libgcc-4.8.5-44.tl2.1.x86_64 libstdc++-4.8.5-44.tl2.1.x86_64
(gdb)
(gdb) bt
#0  0x00007f685a89f9e0 in __nanosleep_nocancel () from /lib64/libc.so.6
#1  0x00007f685a89f894 in sleep () from /lib64/libc.so.6
#2  0x000000000040056b in main ()
(gdb)
(gdb) info registers
rax            0xfffffffffffffdfc       -516
rbx            0x7ffdafe16390   140727554237328
rcx            0x7f685a89f9e0   140086172318176
rdx            0x0      0
rsi            0x7ffdafe16380   140727554237312
rdi            0x7ffdafe16380   140727554237312
rbp            0xffffffff       0xffffffff
rsp            0x7ffdafe16378   0x7ffdafe16378
r8             0x7ffdafe16490   140727554237584
r9             0x7ffdafe162d0   140727554237136
r10            0x8      8
r11            0x246    582
r12            0x7ffdafe16410   140727554237456
r13            0x7ffdafe16640   140727554238016
r14            0x0      0
r15            0x0      0
rip            0x7f685a89f9e0   0x7f685a89f9e0 <__nanosleep_nocancel+7>
eflags         0x246    [ PF ZF IF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0
(gdb) list
No symbol table is loaded.  Use the "file" command.
(gdb) file
No executable file now.
No symbol file now.
(gdb) quit

上一篇 下一篇

猜你喜欢

热点阅读