Debugging method for Linux segment errors
Related blog posts:
Http://blog.csdn.net/htianlong/article/details/7439030
Http://www.cnblogs.com/panfeng412/archive/2011/11/06/2237857.html
Http://www.cnblogs.com/panfeng412/archive/2011/10/24/2222413.html
Http://hi.baidu.com/zmohadnaadbfntr/item/5732180d816c1d813c42e211
The following program will generate a segment error.
CS. c
#include <stdio.h>int main(void){ int *p = NULL; *p = 10; return 0;}
Makefile
CFLAGS=-WallCC=gcccs:cs.o$(CC) cs.o -o cs cs.o:cs.c$(CC) -c -o cs.o cs.cclean:$(RM) *.o.PHONY:clean
Execute Command
Make
./CS
Output result
Debugging method:
- Switch to root user su Root
- Run ulimit-
- Run ulimit-C unlimited.
- Change the MAKEFILE file to add-g after-wall.
- Execute make
- Execute./CS to generate a Core File
- Execute GDB./CS Core
- Run quit to exit GDB.
- Ctrl d switch back to normal user