내용으로 건너뛰기
LinDol's 실험실
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
gdb
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== gdb ====== 리눅스 환경에서 C언어로 작성 중인 프로그램이 segment falut를 출력하며 종료 되어 버릴 때 GDB를 이용한 디버깅 방법 1. 소스 파일 빌드시 디버깅 정보 포함 시키기 아래의 예에서 처럼 **-g -ggdb** 옵션을 포함 시킨다. <code bash> $ gcc -Wall -W -Werror -g -ggdb p33_my_deque.c -o p33_my_deque </code> 2. core dump 파일 생성 옵션 변경 ulimit -c 명령을 사용하여 core dump 파일 생성 크기 제한을 늘려준다. 기본적으로 core dump 파일 크기 제한이 0으로 설정되어 있다. <code bash> ulimit -c unlimited </code> 3. 프로그램 실행 segment fault가 발생한 상황과 동일하게 프로그램을 실행하여 core dump 파일이 생성되도록 한다. 4. gdb 실행 생성된 core dump 파일을 사용해 gdb를 실행하면 segment fault가 발생한 지점을 바로 확인 할 수 있다. **-c** 옵션의 값으로 core dump 파일 이름을 지정한다. <code bash> gdb ./p33_my_deque -c core </code> 정상적으로 실행된 경우의 gdb 출력 결과는 다음과 같다. <code bash> GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9 Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./p33_my_deque...done. warning: exec file is newer than core file. [New LWP 2655] Core was generated by `./p33_my_deque'. ---Type <return> to continue, or q <return> to quit--- </code> Enter 키를 누르면 다음과 같이 segment fault가 발생한 위치에 대한 정보가 출력된다. <code bash> Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00000000004007d3 in pop_front () at p33_my_deque.c:83 83 queue.front_ = poped_data->next_; (gdb) </code> 이 경우 gdb 출력 결과에서 힌트를 얻어 소스 파일의 83번째 라인에서 NULL 값의 사용으로 인해 segment fault가 발생한 것을 알 수 있었다. ====== 참고 자료 ====== [[http://www.morenice.kr/66|[gdb] core 파일을 통해 디버깅하자]]
gdb.txt
· 마지막으로 수정됨: 2015/06/06 21:44 저자
lindol
문서 도구
문서 보기
이전 판
역링크
맨 위로