1。在程序编译的时候加上选项
gcc -g -rdynamic main.c
然后调试 #gdb ./a.out
(gdb) r 运行
2。产生core 文件进行gdb调试
#ulimit -c 1000 设置产生的core文件限制
#./a.out 运行程序之后会产生core文件
#ls
1.txt a.out core.1071 main.c
#gdb a.out core.1071
GNU gdb (GDB) Fedora (7.0-3.fc12)
Copyright (C) 2009 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/djy/mytest/a.out...done.
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x08048559 in main () at main.c:7
7 *ptr = 0x00;
Missing separate debuginfos, use: debuginfo-install glibc-2.11-2.i686
输出出错的地方