Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92130
  • 博文数量: 24
  • 博客积分: 150
  • 博客等级: 入伍新兵
  • 技术积分: 167
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-30 01:34
个人简介

微言博命

文章分类

全部博文(24)

文章存档

2013年(7)

2012年(17)

我的朋友

分类:

2012-09-01 23:48:44

原文地址:linux 调试工具使用 作者:fly123456789

1)ulimit+gcc+gdb
如下:
test.c文件如下
  1. #include <stdio.h>

  2. int main()
  3. {

  4.     int *a=NULL;
  5.     *a=0x11;
  6.     
  7.     return 0;
  8. }

#ulimit -c 1073741824 (设置1GB的内核转储文件)

#gcc -O0 -g test.c (添加编译参数,编译文件,注意优化级别及提示信息参数。如果使用默认,不添加参数,定位不清)

#rm core
#./a.out 必先删除已经存在的core文件,否则gdb时候,定位不清。会生成core*文件,这个就是内核转储文件)
Segmentation fault (core dumped)

#gdb -c core ./a.out (这样通过gdb调试跟踪,可以大致看到有问题的位置)
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<
Reading symbols from /tmp/a.out...done.

warning: exec file is newer than core file.
[New LWP 6302]

warning: Can't read pathname for load map: Input/output error.
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x00000000004004c4 in main () at main.c:7
7 *a=0x11;

阅读(494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~