• 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行使用指针时出的问题。

  • 相关阅读:
    AOD.net
    C# Eval()和Bind()
    .Net使用微軟自帶的用戶驗證和登錄授權
    .Net面試4套
    .Net面試題
    MVC开发模式
    .Net自帶Ajax和GridView
    HTML系列(HTMl+CSS+JavaScript+Jquery)--un
    .Net母版页
    .NetDOM操作--un
  • 原文地址:https://www.cnblogs.com/SZxiaochun/p/7570916.html
Copyright © 2020-2023  润新知