使用GDB分析核心文件

本文介绍了如何配置系统以生成核心文件,并使用GDB进行分析。通过修改`ulimit`和`sysctl.conf`,设置core文件的路径和格式。当程序发生段错误时,可以利用GDB查看崩溃原因,如信号、调用堆栈和变量值,以便于调试。
摘要由CSDN通过智能技术生成

首先需要对环境进行配置,即配置core文件的输出:
运行命令:ulimit -c unlimited 
该命令用于设置core文件大小不限制
修改/etc/sysctl.conf文件,在文件末尾添加下面一行
kernel.core_pattern=/tmp/core-%e
并修改kernel.core_uses_pid = 1 为
kernel.core_uses_pid = 0 这样core文件的格式就是
core-可执行文件的名字,这里我把进程号去掉了,觉得进程号在此处没多大用处。文件所在目录为/tmp下,也可以自己修改为可执行文件所在目录,这样比较直观。
然后运行命令:sysctl -p /etc/sysctl.conf

假设将其值改变为:"/home/duanbei/corefile/core-%e-%p-%t", 那么所有的core文件将保存在"/home/duanbei/corefile"目录下,文件名格式为“core-程序名-pid-时间戳”

格式参数列表

[plain] view plaincopyprint?
%p - insert pid into filename 
%u - insert current uid into filename 
%g - insert current gid into filename 
%s - insert signal that caused the coredump into the filename 
%t - insert UNIX time that the coredump occurred into file

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值