ubuntu core文件

一.相關知識

1)何爲core文件?

        核心文件(core file),也稱核心轉儲(core dump),是操作系統在進程收到某些信號而終止運行時,將此時進程地址空間的內容以及有關進程狀態的其他信息寫出的一個磁盤文件。這種信息往往用於調試。[摘自百度百科]

        A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information. The name comes from the once-standard memory technology core memory. Core dumps are often used to diagnose or debug errors in computer programs.

On many operating systems, a fatal error in a program automatically triggers a core dump, and by extension the phrase "to dump core" has come to mean, in many cases, any fatal error, regardless of whether a record of the program memory is created.[摘自維基百科]    


二.示例 ubuntu下core文件的產生

1)查看相關環境,如下圖中

查看相關環境

注:core file size 爲 0,core file產生還沒打開

2)寫一個簡單的存在問題的c++程序並運行

運行出錯

注:運行出錯,提示段錯誤(訪問空指針),由於沒有打開core文件的開關,故沒有產生core文件的信息

3)打開core文件產生的”開關“

打開core文件產生的開關

注:設置core file size來開否core文件的產生,這裏的1024是喜好值,可以根據實值情況調整

4)運生程序出錯並生成core文件

查看產生的core文件

注:默認在當前工作目錄產生core文件,而文件名爲core

[更改core文件產生的格式]

更新core文件的名稱

注:修改/proc/sys/kernel/core_pattern的內容爲core-%p-%e-%t,原來的內容爲core

5)使用gdb調試core文件

使用gdb

三.有關core文件相關的知識彙總


四.參考文章

1)http://hi.baidu.com/donghaozheng/blog/item/1ef1ebdda53a38e376c63898.html

2)http://blog.csdn.net/shaovey/article/details/2744487
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章