pdb — The Python Debugger(Python调试器)

在Spyder中进行python开发时,调试是必不可少的。它主要依赖了pdb模块,pdb模块为Python开发者提供一个交互式的代码调试器。

发现该调试器和gdb有很多相似之处,这里罗列出几条常用的调试命令。


h(elp) [ command] Without argument, print the list of available commands. With a command as argument, print help about that command. helppdb 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, helpexec 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.  b(reak) [[ filename:] lineno | function[, condition]]

With a lineno argument, set a break there in the current file. With afunction 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 onsys.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.

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.  s(tep) Execute the current line, stop at the first possible occasion (either in a function that is called or on the next line in the current function). n(ext) Continue execution until the next line in the current function is reached or it returns. (The difference between  next and step is that  step stops inside a called function, while next executes called functions at (nearly) full speed, only stopping at the next line in the current function.)unt(il)

Continue execution until the line with the line number greater than the current one is reached or when returning from current frame.

New in version 2.6.

r(eturn) Continue execution until the current function returns. c(ont(inue)) Continue execution, only stop when a breakpoint is encountered.a(rgs) Print the argument list of the current function. run [ args ...]

Restart the debugged Python program. If an argument is supplied, it is split with “shlex” and the result is used as the new sys.argv. History, breakpoints, actions and debugger options are preserved. “restart” is an alias for “run”.

New in version 2.6.

q(uit)

Quit from the debugger. The program being executed is aborted. 


和gdb类似的是,pdb状态下连续回车,则重复执行最近的一次debug命令

pdb — The Python Debugger(Python调试器)_第1张图片


你可能感兴趣的:(工具,python)