GCC如何产生core dump
生活随笔
收集整理的這篇文章主要介紹了
GCC如何产生core dump
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先決條件
1.安裝apport(automatically generate crash reports for debugging)
2.修改/etc/security/limits.conf文件,使允許core dump,或者用ulimit -c unlimited設(shè)置core dump文件的大小為unlimited
3.C/C++的編譯開(kāi)關(guān)-g(產(chǎn)生調(diào)試符號(hào))
######運(yùn)行編譯好的程序testc(我的程序)
kimi@kimi-desktop:~/testc/bin/Debug$ ./testc
######下面一行顯示了core dumped表示成功,core文件在/var/crash或者在當(dāng)前目錄
段錯(cuò)誤 (core dumped)
kimi@kimi-desktop:~/testc/bin/Debug$ ls
######果然在當(dāng)前目錄
core testc
######gdb一下
kimi@kimi-desktop:~/testc/bin/Debug$ gdb testc core
GNU gdb 6.8-debian
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 "i486-linux-gnu"...
warning: Can't read pathname for load map: Input/output error.
Reading symbols from /usr/lib/libstdc++.so.6...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/tls/i686/cmov/libm.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./testc'.
######程序是由于段錯(cuò)誤退出的
Program terminated with signal 11, Segmentation fault.
[New process 13072]
######段錯(cuò)誤的地方在dummy_function - main.c的第5行
#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5
5 *ptr = 0x00;
######打印一下調(diào)用堆棧
(gdb) bt
#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5
#1 0x080483bc in main () at /home/kimi/testc/main.c:12
(gdb)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
1.安裝apport(automatically generate crash reports for debugging)
2.修改/etc/security/limits.conf文件,使允許core dump,或者用ulimit -c unlimited設(shè)置core dump文件的大小為unlimited
3.C/C++的編譯開(kāi)關(guān)-g(產(chǎn)生調(diào)試符號(hào))
######運(yùn)行編譯好的程序testc(我的程序)
kimi@kimi-desktop:~/testc/bin/Debug$ ./testc
######下面一行顯示了core dumped表示成功,core文件在/var/crash或者在當(dāng)前目錄
段錯(cuò)誤 (core dumped)
kimi@kimi-desktop:~/testc/bin/Debug$ ls
######果然在當(dāng)前目錄
core testc
######gdb一下
kimi@kimi-desktop:~/testc/bin/Debug$ gdb testc core
GNU gdb 6.8-debian
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 "i486-linux-gnu"...
warning: Can't read pathname for load map: Input/output error.
Reading symbols from /usr/lib/libstdc++.so.6...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/tls/i686/cmov/libm.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./testc'.
######程序是由于段錯(cuò)誤退出的
Program terminated with signal 11, Segmentation fault.
[New process 13072]
######段錯(cuò)誤的地方在dummy_function - main.c的第5行
#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5
5 *ptr = 0x00;
######打印一下調(diào)用堆棧
(gdb) bt
#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5
#1 0x080483bc in main () at /home/kimi/testc/main.c:12
(gdb)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
總結(jié)
以上是生活随笔為你收集整理的GCC如何产生core dump的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 关于wParam和lParam
- 下一篇: rabbitmq技术的一些感悟(一)