浅谈core dump
来源:互联网 发布:光良 童话 知乎 编辑:程序博客网 时间:2024/06/02 01:05
core文件描述
1.什么是core dump
2.core一般性原因(其实就是一些常见的调试错误)
3.core文件的存储位置以及设置生成core文件
cat /proc/sys/kernel/core_pattern2.设置生成core文件
3.gdb利用core文件进行调试
4.不产生core文件的几种情况
*进程没有写入core dump文件的权限。(默认情况下,core file称为core,并在当前工作目录中创建。)如果core文件它的目录被创建,并且是nonwritable的,core文件就会创建失败,或者如果一个具有相同名称的文件已存在,不可写或是不正规的文件(例如,它是一个目录或符号链接)都会失败。
*将用于core dump,但是相同的文件名称已经存在,并且有多个硬链接文件。
*文件系统的core dump被创建为已满;或已用完默认的字节数;或是设为只读;或用户已达到文件系统的配额数量等。
*要创建core dump的目录不存在。
* RLIMIT_CORE(core文件大小)或 RLIMIT_FSIZE(文件大小)的进程的资源限制设置为零;看getrlimit(2)与查看shell文件的ulimit下显示的文件((limit in csh(1))。
*进程所执行的二进制文件没有启用读权限。
*进程正在执行由用户(组)所拥有的set-user-ID (set-group-ID)程序,而不是该进程的真实用户(组)ID。(不过,可以查看 prctl(2) PR_SET_DUMPABLE的操作,和文件过程描述在 /proc/sys/fs/suid_dumpable file in proc(5)中.)
*(自从Linux 3.7内核配置)没有CONFIG_COREDUMP选项。
此外,一个core dump文件可以排除该进程的地址空间的一部分,如果 madvise(2) MADV_DONTDUMP标志存在的
5.core_pattern的格式(/proc/sys/kernel/core_pattern)
%%单个%字符
%p被dump的进程的进程ID
%u(数字)被dump的进程的实际用户ID
% g(数字)被dump的进程的实际组ID
%s导致本次dump的信号
%t dump的时间,秒表示由于时代,1970-01-0 00:00:00 + 0000(UTC)
% h主机名(same as nodename returned by uname(2)))
%e可执行文件名(无路径前缀)
%E生成可执行的路径,以斜杠(/)取代标记('!')。
%C core文件资源大小限制崩溃的进程(自Linux 2.6.24)
6.编写一个利用管道指定core_pattern_pipe_test(在文件 /proc/)
$ cc -o core_pattern_pipe_test core_pattern_pipe_test.c $ su Password: # echo "|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s" > \ /proc/sys/kernel/core_pattern # exit $ sleep 100 ^\ # type control-backslash Quit (core dumped) $ cat core.info argc=5 argc[0]=</home/mtk/core_pattern_pipe_test> argc[1]=<20575> argc[2]=<UID=1000> argc[3]=<GID=100> argc[4]=<sig=3> Total bytes in core dump: 282624
Program source
/* core_pattern_pipe_test.c */ #define _GNU_SOURCE #include <sys/stat.h> #include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define BUF_SIZE 1024 int main(int argc, char *argv[]) { int tot, j; ssize_t nread; char buf[BUF_SIZE]; FILE *fp; char cwd[PATH_MAX]; /* Change our current working directory to that of the crashing process */ snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]); chdir(cwd); /* Write output to file "core.info" in that directory */ fp = fopen("core.info", "w+"); if (fp == NULL) exit(EXIT_FAILURE); /* Display command-line arguments given to core_pattern pipe program */ fprintf(fp, "argc=%d\n", argc); for (j = 0; j < argc; j++) fprintf(fp, "argc[%d]=<%s>\n", j, argv[j]); /* Count bytes in standard input (the core dump) */ tot = 0; while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0) tot += nread; fprintf(fp, "Total bytes in core dump: %d\n", tot); exit(EXIT_SUCCESS); }
7.结言
- 浅谈core dump
- Core Dump
- Core Dump
- Core Dump?!
- Core Dump?!
- Core Dump?!
- core dump
- core dump
- Core Dump
- core dump
- Core dump
- core dump
- Core Dump
- core dump
- core dump
- Core Dump
- core dump
- Core Dump
- Web模板引擎——Mustache
- 解决Jenkins获取Git Commit乱码
- butterknife 8.5.1配置使用
- Mysql保存字符串(回车符)
- jQuery EasyUI详解-EasyUI布局和标签页
- 浅谈core dump
- C++关键点总结系列-1
- matlab目录操作及日期函数 matlab20170314
- Angular.js 的一些学习资源
- 技术管理-概要设计评审指南
- 数据存储
- Dual Low-Rank Pursuit: Learning Salient Features for Saliency Detection
- Presentation 常用的承接句——技术分享、学术报告串联全场不尴尬
- Android开发之十位大牛经典博客大全