Post

GDB 간단 사용법 (GDB Cheat Sheet)

GDB 사용법 한눈에 보기

PDF 버전도 준비되어 있습니다. 여기를 클릭해서 확인해 보세요.

분류명령어설명예시
시작gcc -g -o <output> <src>디버깅 심볼 포함 컴파일gcc -g -o main main.c
 gdb [program]GDB 실행gdb main
실행run (r)프로그램 실행 (인수 전달 가능)run arg1 arg2
중단점break (b) <location>중단점 설정
(함수명, 파일:라인, 주소 등)
break main
b file.c:42
 info break (i b)중단점 정보 확인 
 delete (d) [num]중단점 삭제
(num 생략 시 전체 삭제)
delete 1
 disable (dis) [num]중단점 비활성
(num 생략 시 전체 비활성)
disable 2
 enable (en) [num]중단점 활성
(num 생략 시 전체 활성)
disable 2
제어next (n)다음 소스라인 실행
(함수 안으로 들어가지 않음)
next
 step (s)다음 소스라인 실행
(함수 내부로 진입)
step
 continue (c)중단점 또는 프로그램 종료
지점까지 계속 실행
continue
 finish (fin)현재 함수 끝까지 실행 후 복귀finish
 until [location]지정 위치(라인)까지 계속 실행until 100
 return [value]현재 함수 실행을 중단하고 빠져나감return -1
조사print (p) <expr>변수나 표현식 값 출력print i
p arr[0]
 display <expr>매 스텝마다 지정 식의 값을
자동 출력
display x
 info locals현재 스코프 지역 변수 목록 및 값info locals
 info args현재 함수 인수 정보info args
 list [location]소스 코드 출력
(location 생략 시 현위치 코드 출력)
list 100
list function
스택backtrace (bt)콜 스택(함수 호출 흐름) 출력 
 frame [num]특정 스택 프레임
(호출 레벨)으로 이동
frame 2
메모리x/<count><format> <addr>메모리 내용 검사
(b:byte, h:halfword, w:word, x:hex)
x/4xb &buffer
 set {<type>}<addr> = <value>메모리 또는 변수 값 직접 변경set {int} &i = 5
기타help [command]GDB 내장 도움말 보기help break
 quit (q)GDB 종료quit
This post is licensed under CC BY 4.0 by the author.