출처:
권진호 2008.08.06 09:36
#Apollo77's 주석
#주의사항
#core를 분석하기 위해서는 컴파일 옵션에 -g를 추가해야 한다
#.c파일을 컴파일할때 -g를 사용해야 함
#
#core 파일 생성을 위한 옵션
#ulimit -c unlimited
#core 파일 생성하지 않게 하는 옵션
#ulimit -c (현재 상태보기)
#
#core 파일 생성을 위한 옵션
#ulimit -c unlimited
#core 파일 생성하지 않게 하는 옵션
#ulimit -c (현재 상태보기)
[root@linux temp]# gdb ./main ./core.2876
GNU gdb Red Hat Linux (6.6-45.fc8rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
Using host libthread_db library "/lib64/libthread_db.so.1".
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib64/libc.so.6...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libgcc_s.so.1...done.
Loaded symbols for /lib64/libgcc_s.so.1
Core was generated by `./main'.
Program terminated with signal 6, Aborted.
#0 0x0000003cd3430ec5 in raise () from /lib64/libc.so.6
(gdb) backtrace --> backtrace 명령어를 사용해서 죽기 직전까지 호출되었던 스택 정보 확인
#0 0x0000003cd3430ec5 in raise () from /lib64/libc.so.6
#1 0x0000003cd3432970 in abort () from /lib64/libc.so.6
#2 0x0000003cd346b0db in __libc_message () from /lib64/libc.so.6
#3 0x0000003cd3472832 in _int_free () from /lib64/libc.so.6
#4 0x0000003cd3475f2c in free () from /lib64/libc.so.6
#5 0x0000000000400577 in Abnormal () at main.c:10
#6 0x0000000000400587 in AbnormalContainer () at main.c:15
#7 0x00000000004005b2 in main (argc=1, argv=0x7fffc8077798) at main.c:25
Missing separate debuginfos, use: debuginfo-install gcc.x86_64 glibc.x86_64
(gdb) break Abnormal --> 마지막으로 호출된 함수에 break point 설정
Breakpoint 1 at 0x400550: file main.c, line 6.
(gdb) r --> 실행후 차례대로 디버깅
Starting program: /root/temp/main
Reading symbols from /lib64/libc.so.6...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libgcc_s.so.1...done.
Loaded symbols for /lib64/libgcc_s.so.1
Core was generated by `./main'.
Program terminated with signal 6, Aborted.
#0 0x0000003cd3430ec5 in raise () from /lib64/libc.so.6
(gdb) backtrace --> backtrace 명령어를 사용해서 죽기 직전까지 호출되었던 스택 정보 확인
#0 0x0000003cd3430ec5 in raise () from /lib64/libc.so.6
#1 0x0000003cd3432970 in abort () from /lib64/libc.so.6
#2 0x0000003cd346b0db in __libc_message () from /lib64/libc.so.6
#3 0x0000003cd3472832 in _int_free () from /lib64/libc.so.6
#4 0x0000003cd3475f2c in free () from /lib64/libc.so.6
#5 0x0000000000400577 in Abnormal () at main.c:10
#6 0x0000000000400587 in AbnormalContainer () at main.c:15
#7 0x00000000004005b2 in main (argc=1, argv=0x7fffc8077798) at main.c:25
Missing separate debuginfos, use: debuginfo-install gcc.x86_64 glibc.x86_64
(gdb) break Abnormal --> 마지막으로 호출된 함수에 break point 설정
Breakpoint 1 at 0x400550: file main.c, line 6.
(gdb) r --> 실행후 차례대로 디버깅
Starting program: /root/temp/main
Breakpoint 1, Abnormal () at main.c:6
6 int n = 1024;
(gdb) s
7 char *p = (char *)malloc(sizeof(char) * 1);
(gdb) s
9 free(p);
(gdb) s
10 free(p); /* double free */
(gdb) s
*** glibc detected *** /root/temp/main: double free or corruption (fasttop): 0x0000000000601010 ***
6 int n = 1024;
(gdb) s
7 char *p = (char *)malloc(sizeof(char) * 1);
(gdb) s
9 free(p);
(gdb) s
10 free(p); /* double free */
(gdb) s
*** glibc detected *** /root/temp/main: double free or corruption (fasttop): 0x0000000000601010 ***
댓글 없음:
댓글 쓰기