gdb的用法:
This is the GNU debugger. Usage:
gdb [options] [executable-file [core-file or process-id]]
gdb [options] --args executable-file [inferior-arguments ...]
假设有个会core的小程序makecore.c:
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc >= 2)
printf("argv: %s\n", argv[1]);
char *str = "";
str[100] = 'a';
printf("hello world\n");
return 0;
}
编译加上 -g参数,用于调试:
gcc makecore.c -g
检查是否允许生成core file:
ulimit -a
设置允许生成core file: