Core dumped
例子程序如下
#include <stdio.h>
int func(int a, int b)
{
return a / b;
}
int main()
{
int x = 10;
int y = 0;
printf("%d / %d = %d\n", x, y, func(x, y));
return 0;
}
测试
程序名称test.c
Ubuntu16.04下编译
gcc -o test -g test.c
测试编译出的test文件,指令如下,出现core dumped
./test
问题分析
方法一:dmesg+addr2line
1.使用dmesg查看错误信息如下
dmesg | grep test
[181739.997179] traps: test[101269] trap divide error ip:400534 sp:7ffc030999d0 error:0 in test[400000+1000]
其中ip后面的地址就是程序出错的地址,使用addr2line指令找到程序出错位置,指令如下:
# addr2line –e test 400534
这里的test.c:5指的就是test.c的第五行,对应的就是
return a / b;
这是由于b=0作为除数非法
方法二:dmesg+gdb
# gdb ./test
输入r就可以看到错误信息
方法三:strace+addr2line
strace:用来跟踪进程执行时的系统调用和所接收的信号。实际上strace是一个集诊断,调试,统计与一体的工具。strace可以跟踪到一个进程产生的系统调用,包括参数,返回值,执行消耗的时间。
strace -i可以定位core地址
然后执行addr2line –e ./test 400534
参考链接
使用addr2line分析代码错误_看云上有个人的专栏-CSDN博客_addr2line显示问号