core dumped ?完了?

2023-05-16

 

微信公众号:linux码头

 

core dumped:当程序在运行过程中发生异常,这时linux系统可以把程序出错的内存

内容存储在一个core文件中,又叫核心转存。

 

应用程序在运行过程汇总经常会遇到segment fault,通常产生的原因:

数组访问越界

访问空指针

栈溢出

修改只读内存 

 

linux系统默认关闭core dumped功能,但可以通过ulimit命令打开或关闭

core dumped功能。

打开 ulimit -c unlimited

关闭 ulimit -c 0

 

发生core dumped后,可以使用gdb进行查看core文件内容,定位程序出错位置

用法:gdb 程序名 core文件名

在编译文件时加上-g,对于执行的程序产生core文件后,gdb后可以找出错误

记得养成编译时加上-g的习惯。

 

 

案例一:空指针赋值          

#include <stdio.h>
int main()
{        
    int *ptr = NULL;       
    *ptr = 1314;
    return 0;
}

 

没加-g调试选项:

 

chh001@lucky:~$ gcc a.c -o a
chh001@lucky:~$ ./a
Segmentation fault (core dumped)
chh001@lucky:~$ gdb a core
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "x86_64-linux-gnu".
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 a...(no debugging symbols found)...done.
[New LWP 47460]
Core was generated by `./a'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000004004e6 in main ()
(gdb) 

 

加上-g调试选项:

 

chh001@lucky:~$ gcc -g a.c -o a
chh001@lucky:~$ ./a
Segmentation fault (core dumped)
chh001@lucky:~$ gdb a core
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "x86_64-linux-gnu".
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 a...done.
[New LWP 47499]
Core was generated by `./a'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000004004e6 in main () at a.c:6
6        *p = 1314;     --->错误处
(gdb) 

 

案例2:修改只读变量

#include <stdio.h>
int main()
{
    char *p = "iloveyou";
    p[0]='h';
    return 0;
}

 

chh001@lucky:~$ gcc -g a.c -o a
chh001@lucky:~$ ./a
Segmentation fault (core dumped)
chh001@lucky:~$ gdb a core
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "x86_64-linux-gnu".
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 a...done.
warning: exec file is newer than core file.
[New LWP 47499]
Core was generated by `./a'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000004004e6 in main () at a.c:6
6        p[0]='h';
(gdb) 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

core dumped ?完了? 的相关文章

随机推荐

  • Error_Error converting bytecode to dex_ Cause_ Dex cannot parse version 52 byte code.

    报错 xff1a Error Error converting bytecode to dex Cause Dex cannot parse version 52 byte code This is caused by library de
  • Inter RealSenseT265说明文档

    Inter RealSenseT265 Inter RealSenseT265追踪相机T265包括两个带鱼眼的灰度相机 xff0c 一个IMU和一个因特尔Movidius Myriad 2 VPU 所有V SLAM算法都直接在VPU上运行
  • Warning_The `android.dexOptions.incremental` property is deprecated and it has no effect on the buil

    报错 xff1a Warning The 96 android dexOptions incremental 96 property is deprecated and it has no effect on the build proce
  • Android实战SDK对接机智云平台(基础篇) > 2、下载并导入Android的SDK到工程中 学习笔记

    物联网平台机智云Android开源框架入门之旅 gt 搭建Andriod的开发环境 机智云SDK下载地址 把如下文件复制到lib文件中 选中后点击Add As Library 主界面 xff1a 480853 加号 xff1a 150150
  • Android实战SDK对接机智云平台(基础篇) > 3、SDK初始化的实现+快捷键 学习笔记+字体颜色模板

    1 把以下代码复制到AndroidManifest xml中 package 61 34 com myapplication 34 gt 添加 lt uses permission android name 61 34 android pe
  • csdn如何修改文字体及颜色

    csdn如何修改文字体及颜色
  • Android实战SDK对接机智云平台(基础篇) > 6、配网界面的UI搭建 学习笔记

  • 如何保证APP与服务端通信安全

    如何保证APP与服务端通信安全
  • 奎享雕刻使用教程

    软件下载地址 提取码 xff1a g3zk 将类似于u盘似的加密狗插在电脑上 机器和软件连接 xff1a 参数配置 xff1a 实心图 xff1a 1 打开要绘制的图片 2 选择绘制方式 xff1a 笔记 页面宽 xff1a 纸张的宽 左边
  • 万用表的使用方法,焊接

    万用表的使用方法 测量电容时 xff0c 现将电容 短接放电 测量电流时 xff0c 先将电路断开 通断挡在70欧姆以下认为导通 吸锡带 引脚密集的贴片元件在焊接的过程中 xff0c 很容易造成焊锡过多导致引脚短路的现象 xff0c 使用吸
  • STM32学习教程

    STM32学习教程 硬石电子 资料下载库的区分启动模式选择NVICDMAstm32 hal库 pb3做普通ioUSART 串口通讯DMA 直接存储寄存器读取DMA USART1接发RS 485通信 洋桃电子 STM32入门100步第33步U
  • 写字机器人使用教程

    一次制作写字机器人的过程 xff08 含制作教程 xff09 arduino 写字机器人制作教程 写字机器人制作教程2 0 购买链接 资料下载地址 xff1a 智宇科技 写字机器人 光盘资料 xff08 A盘资料 xff09 解压密码 xf
  • Inter RealSenseT265测试总结

    1 光线对定位有影响 xff0c 在一定范围内 xff0c 光线越充足 xff0c 定位精度越高 xff0c 但是当光线达到一定条件之后 xff0c 光照强度就不再跟定位精度成正比了 xff1b 2 周围环境对定位有影响 xff0c 周围的
  • 论文小技巧

    文件 选项 LM3405AXMKE NOPB與LM3405AXMK NOPB LM3405AXMKX NOPB對比 激光二极管 期刊查询 在word里面插入图片时怎样才成是100 比例的 文献 封装与功率 高手支招 xff1a 教你利用裸露
  • 激光啄木鸟使用教程

    软件下载地址 1 红色方框内的按钮长按开机 2 红色方框内的按钮轻触自动对焦 3 打开手机APP选择要雕刻的素材 4 设置要雕刻区域的大小 xff0c 开始预览可以查看雕刻的位置 5 打开蓝牙 xff0c 点击连接设备 6 选择被雕刻物件的
  • STM32 HAL库

    STM32 HAL库 第三章 MDK5 软件入门bug解决关键文件介绍程序仿真User Keywords语法提示代码编辑 查看技巧 第四章 STM32F1 基础知识入门MDK 下 C 语言基础复习STM32F103 时钟系统STM32F10
  • LWIP网络-基于STM32平台

    LWIP P1无操作系统移植RAW UDP实验RAW TCP实验Webserver实验 P1无操作系统移植 MAC 43 PHY 通过符合 IEEE802 3的MII和RMII接口与外接快速以太网PHY进行通信 MII和RMII实现数据交换
  • 树莓派学习

    树莓派学习教程 系统安装数据源的更新与配置命令设定固定IP网络地址 xff1a 法一法二 给树莓派安装中文环境和中文输入法远程控制树莓派SSH方式 xff1a 通过putty软件实现 xff08 不需要屏幕 xff09 VNC方式 xff0
  • C++学习教程

    C 43 43 学习教程 C 43 43 内存分区模型数据类型循环语句for循环语句 跳转语句指针指针 数组 函数 结构体指针 内存分区模型 工具vs codeDEV C 43 43 C 43 43 内存分区模型 程序运行前 全局区和代码区
  • core dumped ?完了?

    微信公众号 xff1a linux码头 core dumped xff1a 当程序在运行过程中发生异常 xff0c 这时linux系统可以把程序出错的内存 内容存储在一个core文件中 xff0c 又叫核心转存 应用程序在运行过程汇总经常会