zoukankan      html  css  js  c++  java
  • core 文件查看

    步骤:

           (1)无论你是用Makefile来编译,还是直接在命令行手工输入命令来编译,都应该加上 -g 选项。

           (2)一般来说,在默认情况下,在程序崩溃时,core文件是不生成的(很多Linux发行版在默认时禁止生成核心文件)。所以,你必须修改这个默认选项,在命令行执行:

           ulimit -c unlimited

           表示不限制生成的core文件的大小。

           (3)运行你的程序,不管用什么方法,使之重现Segmentation Fault错误。

           (4)这时,你会发现在你程序同一目录下,生成了一个文件名为 core.*** 的文件,即核心文件。例如,“core.15667”这样的文件。

           (5)用GDB调试它。假设你的可执行程序名为test,则在命令行执行:

           gdb test core.15667

           然后可能会显示出一堆信息:

    GNU gdb Fedora (6.8-27.el5)

    Copyright (C) 2008 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 "i386-redhat-linux-gnu"...

    warning: Can't read pathname for load map: Input/output error.

    …………………(中间还有很多内容,此处省略)……………………………

    Loaded symbols for /usr/lib/libgpg-error.so.0

    Core was generated by `./test'.

    Program terminated with signal 11, Segmentation fault.

    [New process 15668]

    #0  0x0804c760 in thread _handler () at test.cpp:707

    707                             CDev* cur_dev = *it_d;

    然后我们输入并执行命令 bt :

    (gdb) bt

    就会得到类似于下面的信息:

    #0  0x0804c760 in thread _handler () at test.cpp:707

    #1  0x006b149b in start_thread () from /lib/libpthread.so.0

    #2  0x0060842e in clone () from /lib/libc.so.6

    于是,我们一眼就看出来了:程序是在第707行使用指针时出的问题。

  • 相关阅读:
    安装Windows Live Writer
    CSS实现鼠标滑过表格变色
    简单实用TAB选项卡,支持单页面多个调用
    在asp:Repeater中的label中分类绑定值时用asp:Repeater的ItemDataBound方法
    在asp:Repeater中的asp:LinkButton中按Id删除对应行的数据时用asp:Repeater的ItemCommand方法
    密码请设为616位字母或数字的检查
    List 和 IList的区别
    取得前九条之后的数据
    对List(IList)集合作求和,最大(小)值操作
    验证码验证
  • 原文地址:https://www.cnblogs.com/SZxiaochun/p/7570916.html
Copyright © 2011-2022 走看看