当前位置:网站首页>core dump
core dump
2022-07-24 18:33:00 【Li-Yongjun】
前言
段错误(核心已转储)!!!
# ./test.out
Segmentation fault (core dumped)
$ ./core.out
段错误 (核心已转储)
运行一个程序,不小心发生了 段错误(核心已转储),多悲催啊。幸好我们有 core dump,能够帮助调试程序崩溃问题。今天我们就来聊一聊 core dump。
概述
core dump 一词来源于 magnetic-core memory,这是上世纪六七十年代主流的内存介质。core 指记忆体也就是现在的内存。
操作系统在进程收到某个信号而终止运行时,将此时进程地址空间的内容以及进程相关状态信息写入一个磁盘文件,这个过程就叫 core dump,产生的文件就叫 core 文件。
core dump 记录了程序崩溃时的案发现场。我们可以使用 gdb 对 core 文件进行分析,叫做现场还原,就能够看到程序是因何而崩溃。
前提条件
a) 需要事先开启 core dump 功能,使用如下命令
ulimit -c 1024
b) gcc 编译程序需要加上 -g 选项以增加调试信息。
测试环境
BananaPi M1(在 ubuntu 上始终无法生成 core 文件,知道方法的同学可以留言)
测试程序
test.c
#include <stdio.h>
int main(int argc, char argv)
{
int *p = NULL;
*p = 0; // 给空指针指向的地址赋值,引发core dump
return 0;
}
编译
$ /home/liyongjun/project/board/buildroot/BPi-M1/host/bin/arm-buildroot-linux-uclibcgnueabihf-gcc -g test.c -o test.out
core dump
在 BananaPi M1 上运行
# ./test.out
Segmentation fault
# ulimit -c 1024
# ./test.out
Segmentation fault (core dumped)
# ls
core test.out
第一次运行,发现并没有出现 core dump,是因为没使能 core dump 功能,使用 ulimit -c 1024 使能后,就出现了 core dump,ls 能看到 core 文件。
gdb 分析
上传到 ubuntu 使用 gdb 分析
$ arm-linux-gnueabihf-gdb test.out core
GNU gdb (Linaro_GDB-2017.08) 8.0.0.20170823-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test.out...done.
[New LWP 149]
warning: Could not load shared library symbols for 2 libraries, e.g. /lib/libc.so.0.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `./test.out'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x004e15a0 in main (argc=1, argv=116 't') at test.c:7
7 *p = 0; // 给空指针指向的地址赋值,引发core dump
(gdb)
gdb 直接就定位到了崩溃点:第 7 行:*p = 0;。
边栏推荐
- Rookie colleagues cost me 2K. Did you recite the secret of salary increase? (collect it quickly!)
- Wechat applet
- Space three point circle code
- Encapsulate function basedata.js
- Missing value processing
- 数组常用方法(2)
- Valentine's Day gift ----- use her photos and our chat records to generate word clouds~
- jmeter -- prometheus+grafana服务器性能可视化
- We have to understand the four scopes: application, session, request and page
- 线段树合并板子
猜你喜欢

开窗函数(1)-部门工资前三员工

【刷题记录】20. 有效的括号

4. Basic type and reference type?

Type-C边充边听PD协议芯片

9. BOM object?

第五届数字中国建设峰会在福建福州开幕

Ionic4 learning notes 4 -- add a tab page

Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it

Wechat applet

如何用WebGPU流畅渲染百万级2D物体?
随机推荐
CF. Bits And Pieces(子集状压dp + 剪枝)
16. What is the difference between target and currenttarget?
【刷题记录】20. 有效的括号
Techempower web framework performance test 21st round results release --asp Net core continue to move forward
[record of question brushing] 20. Valid brackets
Show or hide password plaintext + password box verification information
How to render millions of 2D objects smoothly with webgpu?
3. Variable declaration promotion?
移动端实现0.5px的实用方案
奶头乐理论介绍及个人感悟
Namespace:集群环境共享与隔离
Pytorch的旅程一:线性模型
undefined reference to H5PTopen
Latex mathematical formula
数组对象方法 常用遍历方法&高阶函数
球面上绘制圆matlab仿真
全国职业院校技能大赛网络安全竞赛——Apache安全配置详解
Rookie colleagues cost me 2K. Did you recite the secret of salary increase? (collect it quickly!)
数组常用方法(2)
Segment tree merge board