内容提要:
主要包含两部分内容:
1,core文件描述
2,core文件分析
说明:
一,Core 文件描述
Coredump 在unix 平台是非常容易出现的一种错误形式,直接表现形式为core 文件, core 文件产生于当前目录下,
通常,象内存地址错误、非法指令、总线错误等会引起coredump ,core 文件的内容包含进程出现异常时的错误影
像。如果错误进程为多线程并且core 文件的大小受限于ulimit 的系统限制,则系统只将数据区中错误线程的堆栈区
复制到core 文件中。
应当注意,从AIX 5L 版本5.1 开始core 文件的命名格式可以通过环境变量CORE_NAMING 设置,其格式为:
core.pid.ddhhmmss ,分别代表为:
pid :进程标示符
dd :当前日期
hh :当前小时
mm :当前的分钟
ss :当前的秒
core 文件的缺省格式为老版本的格式,coredump 文件的内容按照以下的顺序组织:
1 ) core 文件的头部信息
- 定义
2 ) ldinfo 结构信息
- 定义
3 ) mstsave 结构信息
- 定义核心线程的状态信息,错误线程的
程序有效,除错误线程外的其他线程的 mstsave 结构信息存与此区域。
4 ) 缺省的用户堆栈数据
- 存储
5 ) 缺省的数据区域
- 存储用户数据区域信息
6 ) 内存映射数据
- 存储匿名的内存映射数据
7 ) vm_info 结构信息
- 存储内存映射区域的地址偏移量和大小信息
缺省情况下,用户数据、匿名的内存区域和vm_info 结构信息并不包含在core 文件中,core 文件值包含当前的进
程堆栈、线程堆栈、线程mstsave 结构、用户结构和错误时的寄存器信息,这些信息足够跟踪错误的产生。Core
文件的大小也可以通过setrlimit 函数设定。
二,Core 文件分析
首先分析coredump 的结构组成,core 文件的头信息是由结构core_dump 结构定义的,结构成员定义如下:
成员 | 类型 | 描述 |
c_signo | char | 引起错误的信号量 |
C_entries | ushort | Coredump 的模块数 |
*c_tab | Struct ld_info | Core 数据的地址偏移量 |
成员 | 类型 | 描述 |
c_flag | char | 描述coredump 的类型,类型为: |
![]() | ![]() | FULL_CORECore 包含数据区域 |
![]() | ![]() | CORE_VERSION_1 生成 core 文件的AIX 的版本 |
![]() | ![]() | MSTS_VALID 包含mstsave 的结构 |
![]() | ![]() | CORE_BIGDATACore 文件包含大数据 |
![]() | ![]() | UBLOCK_VALIDCore 文件包含u_block 结构 |
![]() | ![]() | USTACK_VALIDCore 文件包含用户堆栈数据 |
![]() | ![]() | LE_VALIDCore 文件至少包含一个模块 |
![]() | ![]() | CORE_TRUNCCore 文件被截短 |
c_stack | Caddr_t | 用户堆栈的起始地址偏移量 |
C_size | int | 用户堆栈的大小 |
C_mst | Struct mstsave | 错误mst 的拷贝 |
C_u | Struct user | 用户结构的拷贝 |
C_nmsts | int | Mstsave 结构的数量 |
C_msts | Struct mstsvae * | 线程的mstsave 结构的地址偏移量 |
C_datasize | int | 数据区域的大小 |
C_data | Caddr_t | 用户数据的地址偏移量 |
C_vmregions | int | 匿名地址映射的数量 |
C_vmm | Struct vm_info * | Vm_info 数据表的起始地址偏移量 |
借助于下面提供的程序可以分析core 文件的部分信息:
#include <stdio.h>
#include <sys/core.h>
void main(int argc, char *argv[])
{
FILE *corefile;
struct core_dumpx c_file;
char command[256];
if (argc != 2) {
fprintf(stderr, "Usage: %s <corefile>/n", *argv);
exit(1);
}
if ((corefile = fopen(argv[1], "r")) == NULL) {
perror(argv[1]);
exit(1);
}
fread(&c_file, sizeof(c_file), 1, corefile);
fclose(corefile);
sprintf(command, "lquerypv -h %s 6E0 64 | head -1 | awk '{print $6}'", argv[1]);
printf("Core created by: /n");
system(command);
printf("Signal number and cause of error number: %i/n", c_file.c_signo);
printf("Core file type: %i/n", c_file.c_flag);
printf("Number of core dump modules: %i/n", c_file.c_entries);
printf("Core file format number: %i/n", c_file.c_version);
printf("Thread identifier: %i/n", c_file.c_flt.th.ti_tid);
printf("Process identifier: %i/n", c_file.c_flt.th.ti_pid);
printf("Current effective priority: %i/n", c_file.c_flt.th.ti_pri);
printf("Processor Usage: %i/n", c_file.c_flt.th.ti_cpu);
printf("Processor bound to: cpu%i/n", c_file.c_flt.th.ti_cpuid);
/* if (c_file.c_flt.th.ti_cpu > 1) printf("Last Processor: cpu%i/n", c_file.c_flt.th.ti_affinity);
*/
exit(0);
}
假定以上程序的可执行程序名称为anacore ,按照以下步骤察看其运行结果:
1 ) 通过下面的程序生成core 文件
- main() {
char *testadd;
strcpy(testadd, 搣Just a testing攠);
}
程序命名为core.c
2 ) 编译程序core.c
- xlc –o pcore core.c
3 ) 运行pcore 产生core 文件
4 ) 运行anacore 察看结果
- anacore core
5 ) 结果如下 [root@F80_1#]acore core
Core created by:
|pcore...........|
Signal number and cause of error number: 11
Core file type: 114
Number of core dump modules: 0
Core file format number: 267312561
Thread identifier: 40827
Process identifier: 9520
Current effective priority: 60
Processor Usage: 0
Processor bound to: cpu-1
从上面的结果,我们可以简单的分析产生core 文件的应用、信号量及进程等信息,如果要求一
些更详细的信息,可以借助于dbx 等调试工具进一步分析。
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow