国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C代碼的coredump

2019-11-08 20:25:35
字體:
來源:轉載
供稿:網友

要點:

程序異常終止之后會生成core代碼文件程序添加-g編譯選項,從而包含調試信息結合gdb和coredump文件定位異常點

程序異常終止之后會生成coredump文件,不同的系統、不同的設置,這個自動生成的coredump文件也不一樣。

示例代碼:

#include <stdio.h> int core_dump() {    int i;     for (i = 5; i >= 0; i--) {        PRintf("(%d, %d)/n", i, 100 / i);    }     return 0;} int main() {    core_dump();     return 0;}以上代碼存在除0異常,編譯運行:

gcc -g core_dump.c -o core_dump./core_dump運行結果:

(5, 20)(4, 25)(3, 33)(2, 50)(1, 100)[1]    9662 floating point exception (core dumped) 為了更清楚地找到代碼出錯的地方,可以使用gdb來分析coredump文件:
~/examples/cpp/core_dump % gdb ./a.out coreGNU gdb (GDB) 7.7Copyright (C) 2014 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 "i686-pc-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.out...done.[New LWP 9662] warning: Could not load shared library symbols for linux-gate.so.1.Do you need "set solib-search-path" or "set sysroot"?Core was generated by `./a.out'.Program terminated with signal SIGFPE, Arithmetic exception.#0  0x08048415 in core_dump ()(gdb) where#0  0x08048415 in core_dump ()#1  0x0804844b in main ()(gdb)可以看到上面并沒有給出具體的代碼&行號,因為需要添加-g編譯選項。為此重新編譯、運行,此時的coredumnp文件就提供了全面的信息:
~/examples/cpp/core_dump % gdb ./a.out coreGNU gdb (GDB) 7.7Copyright (C) 2014 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 "i686-pc-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.out...done.[New LWP 9758] warning: Could not load shared library symbols for linux-gate.so.1.Do you need "set solib-search-path" or "set sysroot"?Core was generated by `./a.out'.Program terminated with signal SIGFPE, Arithmetic exception.#0  0x08048415 in core_dump () at main.c:77                       printf("(%d, %d)/n", i, 100 / i);(gdb) where#0  0x08048415 in core_dump () at main.c:7#1  0x0804844b in main () at main.c:14(gdb) 補充:

當然,并不是所有的異常都會生成coredump文件,具體請參考《Unix環境高級編程(2nd)》第十章 信號。有些環境缺省設置coredump文件是0字節,為此需要ulimit -c 1024(文件大小)。ulimit -c unlimited


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新和县| 昌宁县| 绵阳市| 浦江县| 丽水市| 盐城市| 惠东县| 正镶白旗| 米脂县| 三原县| 进贤县| 黑河市| 务川| 青岛市| 泗洪县| 工布江达县| 章丘市| 金坛市| 阿勒泰市| 武隆县| 玉田县| 平遥县| 泽普县| 开远市| 盐源县| 扶余县| 沾化县| 太仓市| 铜陵市| 宁陵县| 拉萨市| 稻城县| 北安市| 买车| 富裕县| 平和县| 东光县| 南皮县| 原阳县| 潼南县| 道真|