码迷,mamicode.com
首页 > 数据库 > 详细

gdb core

时间:2015-04-03 18:45:26      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

程序运行发生异常退出,比如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;
}
  1. gcc -g -o segment segment.c  

Core文件:

 

    1. 查看系统是否允许生成core文件   

[plain] view plaincopy
 
  1. #ulimit -a  
  2. core file size          (blocks, -c) 0  

core文件大小限制为0,不能生成core文件。

    2. 使用如下命令取消限制,使系统能生成core文件

 

[plain] view plaincopy
 
  1. ulimit -c unlimited  
或者指定core文件大小,如1K

 

[plain] view plaincopy
 
  1. ulimit -c 1024  

执行程序:        

  1. # ./segment  
  2. 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: Cant 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

 

gdb core

标签:

原文地址:http://www.cnblogs.com/youxin/p/4390484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!