gdb core
程序运行发生异常退出,比如segment错误,此时可以利用系统生成的core文件,配合GDB来定位问题。
问题程序:
segment.c
#include <stdio.h> #include <signal.h> #include <unistd.h> #include <stdlib.h> void func() { char *p = NULL; *p = 3; } main() { func(); return; }
- gcc -g -o segment segment.c
Core文件:
1. 查看系统是否允许生成core文件
- #ulimit -a
- core file size (blocks, -c) 0
core文件大小限制为0,不能生成core文件。
2. 使用如下命令取消限制,使系统能生成core文件
或者指定core文件大小,如1K
- ulimit -c unlimited
- ulimit -c 1024
执行程序:
- # ./segment
- egmentation fault (core dumped)
在程序当前目录下生成了core文件
gdb调试:
# gdb ./segment core GNU gdb (GDB) 7.1-ubuntu Copyright (C) 2010 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". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/duanbb/test/segment/segment...done. [New Thread 3655] warning: Can‘t read pathname for load map: Input/output error. Reading symbols from /lib/tls/i686/cmov/libc.so.6...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libc-2.11.1.so...done. done. Loaded symbols for /lib/tls/i686/cmov/libc.so.6 Reading symbols from /lib/ld-linux.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done. done. Loaded symbols for /lib/ld-linux.so.2 Core was generated by `./segment‘. Program terminated with signal 11, Segmentation fault. #0 0x080483c4 in func () at segment.c:10 10 *p = 3;
release版如何调试看:http://blog.csdn.net/duanbeibei/article/details/6923716
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。