Talk about the segmentation fault (core dumped) problem-find the reason for the segment Error

Source: Internet
Author: User
再谈Segmentation fault (core dumped)问题 -查找段错误原因

   在前一篇文章“Segmentation fault (core dumped) ”有说了具体core dumped产生的原因。
下面主要来介绍下问题的解决与查找,在linux下一般都使用gdb进行调试,那今天我就以Ubuntu 14.04环境作为介绍
来查找正在的core dumped的原因。需要说明的是,你在编译程序的时候要加调试选项 -g。

$ gcc -o app reverse.c -g
 
语法:gdb 应用 core
$ gdb app core.36129 
这样出来的会有一堆东西,咱们先别管,在输入行中输入where.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `./app‘.
Program terminated with signal 11, Segmentation fault.
#0  0x0000003262a56ed0 in _IO_vfscanf_internal () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64
(gdb) where
#0  0x0000003262a56ed0 in _IO_vfscanf_internal () from /lib64/libc.so.6
#1  0x0000003262a646cd in __isoc99_scanf () from /lib64/libc.so.6
#2  0x0000000000400607 in main () at reverse.c:10
(gdb) 
这就回显示就是core是发生在什么地方,首先你看的顺序从列表的下方往上看,因为这是一个“栈”的顺序。
你可以马上可以看到是什么原因导致的,有兴趣的可以试试看。
    另外需要注意的是,如果你的机器上跑很多的应用,你生成的core又不知道是哪个应用产生的,你可以通过下列命令
 
进行查看:file core
[/ipla_app01/test/]$ l
total 124
-rwxrwxr-x 1 ipla_app01 ipla_app01   8438 Oct  8 14:12 app
-rw------- 1 ipla_app01 ipla_app01 200704 Oct  8 14:17 core.36129
-rw-rw-r-- 1 ipla_app01 ipla_app01    386 Oct  8 14:11 reverse.c
[/ipla_app01/test/]$ file core.36129 
core.36129: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from ‘./app‘

再谈Segmentation fault (core dumped)问题 -查找段错误原因

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.