1)ulimit+gcc+gdb如下:
test.c文件如下
- #include <stdio.h>
- int main()
- {
- int *a=NULL;
- *a=0x11;
-
- return 0;
- }
#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;
阅读(517) | 评论(0) | 转发(0) |