?? pdb.py
字號:
# Print a traceback starting at the top stack frame. # The most recently entered frame is printed last; # this is different from dbx and gdb, but consistent with # the Python interpreter's stack trace. # It is also consistent with the up/down commands (which are # compatible with dbx and gdb: up moves towards 'main()' # and down moves towards the most recent stack frame). def print_stack_trace(self): try: for frame_lineno in self.stack: self.print_stack_entry(frame_lineno) except KeyboardInterrupt: pass def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix): frame, lineno = frame_lineno if frame is self.curframe: print '>', else: print ' ', print self.format_stack_entry(frame_lineno, prompt_prefix) # Help methods (derived from pdb.doc) def help_help(self): self.help_h() def help_h(self): print """h(elp)Without argument, print the list of available commands.With a command name as argument, print help about that command"help pdb" pipes the full documentation file to the $PAGER"help exec" gives help on the ! command""" def help_where(self): self.help_w() def help_w(self): print """w(here)Print a stack trace, with the most recent frame at the bottom.An arrow indicates the "current frame", which determines thecontext of most commands. 'bt' is an alias for this command.""" help_bt = help_w def help_down(self): self.help_d() def help_d(self): print """d(own)Move the current frame one level down in the stack trace(to an older frame).""" def help_up(self): self.help_u() def help_u(self): print """u(p)Move the current frame one level up in the stack trace(to a newer frame).""" def help_break(self): self.help_b() def help_b(self): print """b(reak) ([file:]lineno | function) [, condition]With a line number argument, set a break there in the currentfile. With a function name, set a break at first executable lineof that function. Without argument, list all breaks. If a secondargument is present, it is a string specifying an expressionwhich must evaluate to true before the breakpoint is honored.The line number may be prefixed with a filename and a colon,to specify a breakpoint in another file (probably one thathasn't been loaded yet). The file is searched for on sys.path;the .py suffix may be omitted.""" def help_clear(self): self.help_cl() def help_cl(self): print "cl(ear) filename:lineno" print """cl(ear) [bpnumber [bpnumber...]]With a space separated list of breakpoint numbers, clearthose breakpoints. Without argument, clear all breaks (butfirst ask confirmation). With a filename:lineno argument,clear all breaks at that line in that file.Note that the argument is different from previous versions ofthe debugger (in python distributions 1.5.1 and before) wherea linenumber was used instead of either filename:lineno orbreakpoint numbers.""" def help_tbreak(self): print """tbreak same arguments as break, but breakpoint isremoved when first hit.""" def help_enable(self): print """enable bpnumber [bpnumber ...]Enables the breakpoints given as a space separated list ofbp numbers.""" def help_disable(self): print """disable bpnumber [bpnumber ...]Disables the breakpoints given as a space separated list ofbp numbers.""" def help_ignore(self): print """ignore bpnumber countSets the ignore count for the given breakpoint number. A breakpointbecomes active when the ignore count is zero. When non-zero, thecount is decremented each time the breakpoint is reached and thebreakpoint is not disabled and any associated condition evaluatesto true.""" def help_condition(self): print """condition bpnumber str_conditionstr_condition is a string specifying an expression whichmust evaluate to true before the breakpoint is honored.If str_condition is absent, any existing condition is removed;i.e., the breakpoint is made unconditional.""" def help_step(self): self.help_s() def help_s(self): print """s(tep)Execute the current line, stop at the first possible occasion(either in a function that is called or in the current function).""" def help_next(self): self.help_n() def help_n(self): print """n(ext)Continue execution until the next line in the current functionis reached or it returns.""" def help_return(self): self.help_r() def help_r(self): print """r(eturn)Continue execution until the current function returns.""" def help_continue(self): self.help_c() def help_cont(self): self.help_c() def help_c(self): print """c(ont(inue))Continue execution, only stop when a breakpoint is encountered.""" def help_list(self): self.help_l() def help_l(self): print """l(ist) [first [,last]]List source code for the current file.Without arguments, list 11 lines around the current lineor continue the previous listing.With one argument, list 11 lines starting at that line.With two arguments, list the given range;if the second argument is less than the first, it is a count.""" def help_args(self): self.help_a() def help_a(self): print """a(rgs)Print the arguments of the current function.""" def help_p(self): print """p expressionPrint the value of the expression.""" def help_exec(self): print """(!) statementExecute the (one-line) statement in the context ofthe current stack frame.The exclamation point can be omitted unless the first wordof the statement resembles a debugger command.To assign to a global variable you must always prefix thecommand with a 'global' command, e.g.:(Pdb) global list_options; list_options = ['-l'](Pdb)""" def help_quit(self): self.help_q() def help_q(self): print """q(uit) or exit - Quit from the debugger.The program being executed is aborted.""" help_exit = help_q def help_whatis(self): print """whatis argPrints the type of the argument.""" def help_EOF(self): print """EOFHandles the receipt of EOF as a command.""" def help_alias(self): print """alias [name [command [parameter parameter ...] ]]Creates an alias called 'name' the executes 'command'. The commandmust *not* be enclosed in quotes. Replaceable parameters areindicated by %1, %2, and so on, while %* is replaced by all theparameters. If no command is given, the current alias for nameis shown. If no name is given, all aliases are listed.Aliases may be nested and can contain anything that can belegally typed at the pdb prompt. Note! You *can* overrideinternal pdb commands with aliases! Those internal commandsare then hidden until the alias is removed. Aliasing is recursivelyapplied to the first word of the command line; all other wordsin the line are left alone.Some useful aliases (especially when placed in the .pdbrc file) are:#Print instance variables (usage "pi classInst")alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]#Print instance variables in selfalias ps pi self""" def help_unalias(self): print """unalias nameDeletes the specified alias.""" def help_pdb(self): help() def lookupmodule(self, filename): """Helper function for break/clear parsing -- may be overridden.""" root, ext = os.path.splitext(filename) if ext == '': filename = filename + '.py' if os.path.isabs(filename): return filename for dirname in sys.path: while os.path.islink(dirname): dirname = os.readlink(dirname) fullname = os.path.join(dirname, filename) if os.path.exists(fullname): return fullname return None# Simplified interfacedef run(statement, globals=None, locals=None): Pdb().run(statement, globals, locals)def runeval(expression, globals=None, locals=None): return Pdb().runeval(expression, globals, locals)def runctx(statement, globals, locals): # B/W compatibility run(statement, globals, locals)def runcall(*args): return apply(Pdb().runcall, args)def set_trace(): Pdb().set_trace()# Post-Mortem interfacedef post_mortem(t): p = Pdb() p.reset() while t.tb_next is not None: t = t.tb_next p.interaction(t.tb_frame, t)def pm(): post_mortem(sys.last_traceback)# Main program for testingTESTCMD = 'import x; x.main()'def test(): run(TESTCMD)# print helpdef help(): for dirname in sys.path: fullname = os.path.join(dirname, 'pdb.doc') if os.path.exists(fullname): sts = os.system('${PAGER-more} '+fullname) if sts: print '*** Pager exit status:', sts break else: print 'Sorry, can\'t find the help file "pdb.doc"', print 'along the Python search path'mainmodule = ''mainpyfile = ''# When invoked as main program, invoke the debugger on a scriptif __name__=='__main__': if not sys.argv[1:]: print "usage: pdb.py scriptfile [arg] ..." sys.exit(2) mainpyfile = filename = sys.argv[1] # Get script filename if not os.path.exists(filename): print 'Error:', `filename`, 'does not exist' sys.exit(1) mainmodule = os.path.basename(filename) del sys.argv[0] # Hide "pdb.py" from argument list # Insert script directory in front of module search path sys.path.insert(0, os.path.dirname(filename)) run('execfile(' + `filename` + ')')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -