Linux程序调试之core dump文件配置

  1. Linux core dump配置
    https://blog.csdn.net/star_xiong/article/details/43529637?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information. The name comes from the once-standard memory technology core memory. Core dumps are often used to diagnose or debug errors in computer programs.

On many operating systems, a fatal error in a program automatically triggers a core dump, and by extension the phrase “to dump core” has come to mean, in many cases, any fatal error, regardless of whether a record of the program memory is created.

  • 终端输入 ulimit -a

    查看系统core文件的大小限制(第一行),core文件大小显示为0 表示没有打开core dump设置:
    命令行输入:ulimit -a

  • 利用ulimit -c [kbytes]设置系统允许生成的core文件的大小

    ulimit -c 0 不产生core文件

    ulimit -c 1024 设置core文件大小为1024K

    ulimit -c unlimited 不限制core文件的大小

    此处执行ulimit -c unlimited,然后执行ulimit -a查看结果,可以发现core file size的值发生变化。

    此时,core dump设置已经打开,再次执行程序出现错误时候,将会在当前工作目录生成core文件,然后就可以使用gdb调试core文件。

  • 修改文件/etc/profile,添加语句 ulimit -c unlimited。重启或者执行source /etc/profile即刻生效

    如果需要修改特定用户配置core,则需要在用户的 ~/.bash_profile 里加上 ulimit -c unlimited 来让特定的用户可以产生 core 文件

  • 在core dump文件名自动添加进程ID

    #echo 1 > /proc/sys/kernel/core_uses_pid

  • 指定内核转存的文件名和目录**

    修改文件/etc/sysctl.conf,添加下述命令:

    kernel.core_pattern = /tmp/corefiles/core %e %p %t – 切记保证目录 /tmp/corefiles存在
    kernel.core_uses_pid = 1

    执行sysctl -p /etc/sysctl.conf 使得修改即刻生效

  • 测试是否配置成功

    kill -s SIGSEGV $$

  • PL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值