❑ pdb: The Python debugger. 파이썬 디버거.
❑ How to debug.
01. Command line style. 커맨드 라인 방식.
python -m pdb [program.py]
02. Python code style. 파이썬 코드 방식.
import pdb
pdb.set_trace()
# Place this code in the position you want to stop. But it is not recognized as a breakpoint.
# 중단하고 싶은 위치에 이코드를 넣는다. 하지만 브레이크포인트로 인정되지는 않는다.
pdb.set_trace()
# Place this code in the position you want to stop. But it is not recognized as a breakpoint.
# 중단하고 싶은 위치에 이코드를 넣는다. 하지만 브레이크포인트로 인정되지는 않는다.
❑ Usage. 사용법.
Command | Description |
? h(help) | Print help. 도움말 출력. |
n(next) | Step over. 스탭 오버. |
s(step) | Step into. 스탭 인투. |
c(continue) | Execute continuously until a breakpoint is encountered. 다음 중단점까지 실행. |
r(return) | Execute continuously until the current function returns. 현재 함수가 값을 반환할 때까지 실행. |
l(list) [line], [line] | Print the 11 lines around the current line, If no line is specified. 라인을 지정하지 않으면 현재 위치 주위의 11개 라인 출력. * list 15, 19 Print 15~19 lines. 15~19라인 출력. |
b(break) [line | function], [condition] | Set a breakpoint. 브레이크포인트 설정. * b Print all breakpoints set up to now. 현재까지 설정된 브레이크포인트 출력. * b 9 Set a breakpoint at the line 9. 9라인에 breakpoint 설정. * b main Set a breakpoint at the main() function. main() 함수에 브레이크포인트 설정. * b 9, var1>0 Set a breakpoint that stops if the value of var1 is greater than zero. var1의 값이 0보다 크면 정지하는 브레이크포인트 설정. |
enable [number] | Enable a breakpoint. 브레이크포인트를 활성화. * enable 1 Enable the breakpoint #1. 1번 브레이크포인트를 활성화. |
disable [number] | Disable a breakpoint. 브레이크포인트를 비활성화. * disable 1 Disable the breakpoint #1. 1번 브레이크포인트를 비활성화. |
cl(clear) [number] | Delete a breakpoint. 브레이크포인트 제거 * cl 1 Delete the breakpoint #1. 1번 브레이크포인트 제거. |
bt w(where) | Print a stack trace(function call). 스택 추적 결과 출력(함수 호출). |
u(up) | Based on stack trace results, move to the higher(older) stack frame. 스택 추적 결과를 기준으로, 상위(오래된) 스택 프레임으로 이동. |
d(down) | Based on stack trace results, move to lower(newer) stack frame. 스택 추적 결과를 기준으로, 하위(최신의) 스택 프레임으로 이동. |
a(args) | Print the arguments of the current function. 현재 위치의 함수에 입력된 아규먼트 값들을 출력. |
[Python code] | Execute Python code. 파이썬 코드 실행. |