linux 生成core 文件,并调试
2018-01-26 16:03
483 查看
本文讲述了实现core文件自动生成的配置方法,具体执行步骤如下:
1.编辑环境配置文件,让shell启动时自动设置ulimit
登陆 LINUX
服务器,任意位置键入 echo"ulimit -c 1024" >> /etc/profile 退出 LINUX 重新登陆 LINUX
键入 ulimit -c, 如果显示 1024 那么说明 coredump 已经被开启。
1024
制产生的 core 文件限的大小不能超过 1024kb,可以使用参数unlimited,取消该限制 ulimit -c unlimited
vi /etc/profile
ulimit -c unlimited > /dev/null2>&1
2.更改core文件生成路径
/proc/sys/kernel/core_uses_pid可以控制产生的 core文件的文件名中是否添加 pid 作为扩展 ,如果添加则文件内容为 1 ,否则为 0
proc/sys/kernel/core_pattern可以设置格式化的 core文件保存位置或文件名,比如原来文件内容是 core-%e
可以这样修改 :
echo "/corefile/core-%e-%p-%t"> core_pattern
将会控制所产生的 core文件会存放到/corefile 目录下,产生的文件名为 core- 命令名 -pid- 时间戳
以下是参数列表 :
%p -insert pid into filename添加 pid
%u - insertcurrent uid into filename添加当前 uid
%g - insert current gidinto filename添加当前 gid
%s - insert signal thatcaused the coredump into the filename添加导致产生 core的信号
%t - insert UNIX time thatthe coredump occurred into filename添加 core文件生成时的 unix 时间
%h - insert hostname wherethe coredump happened into filename添加主机名
%e -insert coredumping executable name into filename添加命令名
vi /etc/sysctl.conf
kernel.core_uses_pid = 1
kernel.core_pattern=/tmp/core-%e-%p
3.sysctl配置生效
sysctl -p /etc/sysctl.conf
这样就可以实现以后发生coredump时,core文件就可以自动生成到/tmp目录下。方便调试!
调试core
gcc -o main -g a.c
gdb main /tmp/core-main-10815
参考: http://blog.csdn.net/mrjy1475726263/article/details/44116289/
1.编辑环境配置文件,让shell启动时自动设置ulimit
登陆 LINUX
服务器,任意位置键入 echo"ulimit -c 1024" >> /etc/profile 退出 LINUX 重新登陆 LINUX
键入 ulimit -c, 如果显示 1024 那么说明 coredump 已经被开启。
1024
制产生的 core 文件限的大小不能超过 1024kb,可以使用参数unlimited,取消该限制 ulimit -c unlimited
vi /etc/profile
ulimit -c unlimited > /dev/null2>&1
2.更改core文件生成路径
/proc/sys/kernel/core_uses_pid可以控制产生的 core文件的文件名中是否添加 pid 作为扩展 ,如果添加则文件内容为 1 ,否则为 0
proc/sys/kernel/core_pattern可以设置格式化的 core文件保存位置或文件名,比如原来文件内容是 core-%e
可以这样修改 :
echo "/corefile/core-%e-%p-%t"> core_pattern
将会控制所产生的 core文件会存放到/corefile 目录下,产生的文件名为 core- 命令名 -pid- 时间戳
以下是参数列表 :
%p -insert pid into filename添加 pid
%u - insertcurrent uid into filename添加当前 uid
%g - insert current gidinto filename添加当前 gid
%s - insert signal thatcaused the coredump into the filename添加导致产生 core的信号
%t - insert UNIX time thatthe coredump occurred into filename添加 core文件生成时的 unix 时间
%h - insert hostname wherethe coredump happened into filename添加主机名
%e -insert coredumping executable name into filename添加命令名
vi /etc/sysctl.conf
kernel.core_uses_pid = 1
kernel.core_pattern=/tmp/core-%e-%p
3.sysctl配置生效
sysctl -p /etc/sysctl.conf
这样就可以实现以后发生coredump时,core文件就可以自动生成到/tmp目录下。方便调试!
调试core
gcc -o main -g a.c
gdb main /tmp/core-main-10815
参考: http://blog.csdn.net/mrjy1475726263/article/details/44116289/
相关文章推荐
- Linux生成core文件及gdb调试
- Linux环境崩溃生成core文件以及调试
- Linux环境崩溃生成core文件以及调试
- 打开linux调试宏开关生成core文件
- inux环境生成core文件 &&Linux Core Dump 配置与调试
- sunsunsun000的分享 分享 Linux环境生成core文件 &&Linux Core Dump 配置与调试
- linux下生成core文件及调试
- Linux中生成Core Dump系统异常信息记录文件的教程
- linux 下gdb 调试 core文件
- linux 为崩溃的程序生成core文件的相关函数,调用代码生成core dump file 但程序不用退出,gdb 分析core
- linux中core文件的生成和配置
- Linux下core文件调试方法、修改core文件的默认路径
- linux 生成core文件相关配置
- 在Linux下产生并调试core文件[转]
- Linux下core文件调试方法
- Linux下core文件调试方法
- c/c++基础(二十七) Linux下core文件调试方法
- Linux下交叉编译gdb,gdbserver+gdb的使用以及通过gdb调试core文件
- linux 下 gdb 利用core文件调试segment fault
- 在Linux下产生并调试core文件