前面讲了gdb调试core dump的入门, 下面来趁热打铁, 熟练一下。 某次, 在某代码中, 一个除数为零的概率事件, 弄得两个入职不久的同事耗费数天, 为什么搞这儿久呢? 因为不太熟悉gdb调试core.
看程序和调试过程:
[taoge@localhost test]$ cat main.c -n
1 #include <stdio.h>
2
3 int main()
4 {
5 int a = 1;
6 int b = 0;
7 int c = a / b;
8
9 printf("bad\n");
10 return 0;
11 }
12
[taoge@localhost test]$ gcc -g main.c
[taoge@localhost test]$ ls
a.out main.c
[taoge@localhost test]$ ./a.out
Floating point exception (core dumped)
[taoge@localhost test]$ ls
a.out core.2441 main.c
[taoge@localhost test]$
[taoge@localhost test]$
[taoge@localhost test]$
[taoge@localhost test]$ gdb a.out core.2441
GNU gdb (GDB) Red Hat Enterprise Linux (7.1-29.el6)
Copyright (C) 2010 Free Software Foundation, I