PDB 사용법 및 Debugger 옵션에 관한 내용입니다.
PDB 사용 방법(Usage)
n: 현재 라인 실행(step next) s: 현재 라인의 함수 안으로 이동(step in) run: 현재 지점에서 계속 실행(다음 set_trace가 없으면 디버깅이 끝나는 셈)
/usr/lib/python2.7/lib-tk/Tkconstants.py(70)() -> NORMAL=‘normal’ (Pdb) s /usr/lib/python2.7/lib-tk/Tkconstants.py(71)() -> DISABLED=‘disabled’ (Pdb) s /usr/lib/python2.7/lib-tk/Tkconstants.py(72)() -> ACTIVE=‘active’ (Pdb) n /usr/lib/python2.7/lib-tk/Tkconstants.py(74)() -> HIDDEN=‘hidden’ (Pdb) n /usr/lib/python2.7/lib-tk/Tkconstants.py(77)() -> CASCADE=‘cascade’ (Pdb) n
-> """ (Pdb)
위와 같이 임의로 만든 test를 import 하고, test내 start 메소드를 실행하는 것을 pdb.run을 통해 실행하여 pdb를 사용할 수도 있습니다.
(0)?() (Pdb) continue (1)?() (Pdb) continue NameError: ‘test’ (1)?() (Pdb)
Documented commands (type help ):
EOF bt cont enable jump pp run unt
a c continue exit l q s until alias cl d h list quit step up
args clear debug help n r tbreak w
b commands disable ignore next restart u whatis break condition down j p return unalias where
Miscellaneous help topics:
h(elp) [command] Without argument, print the list of available commands. With a command as argument, print help about that command. help pdb displays the full documentation file; if the environment variable PAGER is defined, the file is piped through that command instead. Since the command argument must be an identifier, help exec must be entered to get help on the ! command. w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the current frame, which determines the context of most commands. d(own) Move the current frame one level down in the stack trace (to a newer frame). u(p) Move the current frame one level up in the stack trace (to an older frame). b(reak) [[filename:]lineno | function[, condition]] With a lineno argument, set a break there in the current file. With a function argument, set a break at the first executable statement within that function. The line number may be prefixed with a filename and a colon, to specify a breakpoint in another file (probably one that hasn’t been loaded yet). The file is searched on sys.path. Note that each breakpoint is assigned a number to which all the other breakpoint commands refer.
If a second argument is present, it is an expression which must evaluate to true before the breakpoint is honored.
Without argument, list all breaks, including for each breakpoint, the number of times that breakpoint has been hit, the current ignore count, and the associated condition if any.
tbreak [[filename:]lineno | function[, condition]] Temporary breakpoint, which is removed automatically when it is first hit. The arguments are the same as break. cl(ear) [filename:lineno | bpnumber [bpnumber …]] With a filename:lineno argument, clear all the breakpoints at this line. With a space separated list of breakpoint numbers, clear those breakpoints. Without argument, clear all breaks (but first ask confirmation). disable [bpnumber [bpnumber …]] Disables the breakpoints given as a space separated list of breakpoint numbers. Disabling a breakpoint means it cannot cause the program to stop execution, but unlike clearing a breakpoint, it remains in the list of breakpoints and can be (re-)enabled. enable [bpnumber [bpnumber …]] Enables the breakpoints specified. ignore bpnumber [count] Sets the ignore count for the given breakpoint number. If count is omitted, the ignore count is set to 0. A breakpoint becomes active when the ignore count is zero. When non-zero, the count is decremented each time the breakpoint is reached and the breakpoint is not disabled and any associated condition evaluates to true. condition bpnumber [condition] Condition is an expression which must evaluate to true before the breakpoint is honored. If condition is absent, any existing condition is removed; i.e., the breakpoint is made unconditional. commands [bpnumber] Specify a list of commands for breakpoint number bpnumber. The commands themselves appear on the following lines. Type a line containing just ‘end’ to terminate the commands.