Debugging
디버그(영어: debug), 디버깅 (debugging) 혹은 수정은 컴퓨터 프로그램의 정확성이나 논리적인 오류(버그)를 찾아내는 테스트 과정을 뜻한다. 디버깅(debugging), 수정이라고도 한다. 일반적으로 디버깅을 하는 방법으로 테스트 상의 체크, 기계를 사용하는 테스트, 실제 데이터를 사용해 테스트하는 법이 있다.
Binary Tools
바이너리 디버깅을 위한 도구 집합:
- strings
- file
- objdump
- strace - 시스템 명령을 감시
- ltrace - 라이브러리 호출 감시
- gdb
- sysdig
- ldd
- size
- readelf
- nm
- pmap - 으로 메모리 할당 내역 보기
GUI Disassembler
Tip/Trick
Python gdb debugging
Gdb#Python gdb debugging 항목 참조.
Crash 위치 파악하기
크래시가 발생된 위치의 주소를 파악한 후 addr2line를 사용하여 해당 위치를 파악한다.
Example:
Segfault debugging
- How to get a core dump for a segfault on Linux
- (기초만 있다) How to find Segmentation Error in C & C++ ? (Using GDB)
- (기초만 있다) 7.2 Example Debugging Session: Segmentation Fault Example
-
Obtaining a stack trace in C upon SIGSEGV(중국 사이트, 내용은 좋음. 가급적 PDF로 참고: Obtaining_a_stack_trace_in_C_upon_SIGSEGV.pdf) - How to debug a GCC segmentation fault - GNU Project - Free Software Foundation (FSF)
Configure GCC with --enable-checking
. Compile it with -g -O0
so that you can use gdb.
Compile your test case with -v -da -Q
.
-
-Q
: will show which function in the test case is causing it to crash. -
-v
: shows how cc1 was invoked (useful for invoking cc1 manually in gdb). -
-da
: dumps the RTL to a file after each stage.
Next, use gdb to get a stack trace:
Print out the values of interesting variables, e.g., the ones in the statement which got the segmentation fault. You can use the pt and pr macros from the gdbinit.in file to display GCC data. For example, if there is a value of type tree named t, and a value of type rtx named r, you can use these commands:
See also
Favorite site
Tip & Guide
- segmentation fault가 발생할 때 디버깅 방법
- Segmentation Fault 발생했을때 디버깅 하기
- 디버깅 팁: 리눅스에서 프로그램 crash 위치 파악하기
- Segmentation fault발생 시 address를 가지고 디버깅하는 방법
- GEF – GDB Enhanced Features 소개
- Linux Exploit을 손쉽게 – peda 디버거 활용
- GDB 및 관련 Tool을 이용한 B2G 디버깅