2010年11月9日 星期二

Linux process crashed debug 範例

Linux process crashed debug 範例
[root@HTS099 ~]# cat crashed.c
#include
int main(int argc, char* argv[])
{
int *a=0;
printf("start...\n");
*a= 1;

return 0;
}

[root@HTS099 ~]# gcc -o crashed crashed.c -g
[root@HTS099 ~]# ./crashed
start...
Segmentation fault

[root@HTS099 ~]# ulimit -c
0
[root@HTS099 ~]# ulimit -c unlimited
[root@HTS099 ~]# ulimit -c
unlimited
[root@HTS099 ~]# ./crashed
start...
Segmentation fault (core dumped)

[root@HTS099 ~]# ls -l core.*
-rw------- 1 root root 143360 Nov 9 10:06 core.31393

[root@HTS099 ~]# gdb ./crashed core.31393
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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 "i386-redhat-linux-gnu"...

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./crashed'.
Program terminated with signal 11, Segmentation fault.
[New process 31393]
#0 0x080483ab in main () at crashed.c:6
6 *a= 1;
(gdb) bt
#0 0x080483ab in main () at crashed.c:6
(gdb) list *0x080483ab
0x80483ab is in main (crashed.c:6).
1 #include
2 int main(int argc, char* argv[])
3 {
4 int *a=0;
5 printf("start...\n");
6 *a= 1;
7
8 return 0;
9 }

沒有留言:

張貼留言

文章分類