Back to index

python3.2  3.2.2
Classes | Functions | Variables
pdb Namespace Reference

Classes

class  Restart
class  _rstr
class  Pdb

Functions

def find_function
def getsourcelines
def lasti2lineno
def run
def runeval
def runctx
def runcall
def set_trace
def post_mortem
def pm
def test
def help
def main

Variables

list __all__
string line_prefix = '\n-> '
list _help_order
string TESTCMD = 'import x; x.main()'
string _usage

Function Documentation

def pdb.find_function (   funcname,
  filename 
)

Definition at line 90 of file pdb.py.

00090 
00091 def find_function(funcname, filename):
00092     cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
00093     try:
00094         fp = open(filename)
00095     except IOError:
00096         return None
00097     # consumer of this info expects the first line to be 1
00098     lineno = 1
00099     answer = None
00100     while True:
00101         line = fp.readline()
00102         if line == '':
00103             break
00104         if cre.match(line):
00105             answer = funcname, filename, lineno
00106             break
00107         lineno += 1
00108     fp.close()
00109     return answer

Here is the call graph for this function:

Here is the caller graph for this function:

def pdb.getsourcelines (   obj)

Definition at line 110 of file pdb.py.

00110 
00111 def getsourcelines(obj):
00112     lines, lineno = inspect.findsource(obj)
00113     if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
00114         # must be a module frame: do not try to cut a block out of it
00115         return lines, 1
00116     elif inspect.ismodule(obj):
00117         return lines, 1
00118     return inspect.getblock(lines[lineno:]), lineno+1

Here is the call graph for this function:

Here is the caller graph for this function:

def pdb.help ( )

Definition at line 1504 of file pdb.py.

01504 
01505 def help():
01506     import pydoc
01507     pydoc.pager(__doc__)

Here is the call graph for this function:

Here is the caller graph for this function:

def pdb.lasti2lineno (   code,
  lasti 
)

Definition at line 119 of file pdb.py.

00119 
00120 def lasti2lineno(code, lasti):
00121     linestarts = list(dis.findlinestarts(code))
00122     linestarts.reverse()
00123     for i, lineno in linestarts:
00124         if lasti >= i:
00125             return lineno
00126     return 0
00127 

Here is the call graph for this function:

Here is the caller graph for this function:

def pdb.main ( void  )

Definition at line 1521 of file pdb.py.

01521 
01522 def main():
01523     import getopt
01524 
01525     opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['--help', '--command='])
01526 
01527     if not args:
01528         print(_usage)
01529         sys.exit(2)
01530 
01531     commands = []
01532     for opt, optarg in opts:
01533         if opt in ['-h', '--help']:
01534             print(_usage)
01535             sys.exit()
01536         elif opt in ['-c', '--command']:
01537             commands.append(optarg)
01538 
01539     mainpyfile = args[0]     # Get script filename
01540     if not os.path.exists(mainpyfile):
01541         print('Error:', mainpyfile, 'does not exist')
01542         sys.exit(1)
01543 
01544     sys.argv[:] = args      # Hide "pdb.py" and pdb options from argument list
01545 
01546     # Replace pdb's dir with script's dir in front of module search path.
01547     sys.path[0] = os.path.dirname(mainpyfile)
01548 
01549     # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
01550     # modified by the script being debugged. It's a bad idea when it was
01551     # changed by the user from the command line. There is a "restart" command
01552     # which allows explicit specification of command line arguments.
01553     pdb = Pdb()
01554     pdb.rcLines.extend(commands)
01555     while True:
01556         try:
01557             pdb._runscript(mainpyfile)
01558             if pdb._user_requested_quit:
01559                 break
01560             print("The program finished and will be restarted")
01561         except Restart:
01562             print("Restarting", mainpyfile, "with arguments:")
01563             print("\t" + " ".join(args))
01564         except SystemExit:
01565             # In most cases SystemExit does not warrant a post-mortem session.
01566             print("The program exited via sys.exit(). Exit status:", end=' ')
01567             print(sys.exc_info()[1])
01568         except:
01569             traceback.print_exc()
01570             print("Uncaught exception. Entering post mortem debugging")
01571             print("Running 'cont' or 'step' will restart the program")
01572             t = sys.exc_info()[2]
01573             pdb.interaction(None, t)
01574             print("Post mortem debugger finished. The " + mainpyfile +
01575                   " will be restarted")
01576 
01577 
# When invoked as main program, invoke the debugger on a script

Here is the call graph for this function:

Here is the caller graph for this function:

def pdb.pm ( )

Definition at line 1492 of file pdb.py.

01492 
01493 def pm():
01494     post_mortem(sys.last_traceback)
01495 
01496 
01497 # Main program for testing

Here is the call graph for this function:

def pdb.post_mortem (   t = None)

Definition at line 1478 of file pdb.py.

01478 
01479 def post_mortem(t=None):
01480     # handling the default
01481     if t is None:
01482         # sys.exc_info() returns (type, value, traceback) if an exception is
01483         # being handled, otherwise it returns None
01484         t = sys.exc_info()[2]
01485     if t is None:
01486         raise ValueError("A valid traceback must be passed if no "
01487                          "exception is being handled")
01488 
01489     p = Pdb()
01490     p.reset()
01491     p.interaction(None, t)

Here is the caller graph for this function:

def pdb.run (   statement,
  globals = None,
  locals = None 
)

Definition at line 1460 of file pdb.py.

01460 
01461 def run(statement, globals=None, locals=None):
01462     Pdb().run(statement, globals, locals)

Here is the caller graph for this function:

def pdb.runcall (   args,
  kwds 
)

Definition at line 1470 of file pdb.py.

01470 
01471 def runcall(*args, **kwds):
01472     return Pdb().runcall(*args, **kwds)

def pdb.runctx (   statement,
  globals,
  locals 
)

Definition at line 1466 of file pdb.py.

01466 
01467 def runctx(statement, globals, locals):
01468     # B/W compatibility
01469     run(statement, globals, locals)

Here is the call graph for this function:

def pdb.runeval (   expression,
  globals = None,
  locals = None 
)

Definition at line 1463 of file pdb.py.

01463 
01464 def runeval(expression, globals=None, locals=None):
01465     return Pdb().runeval(expression, globals, locals)

def pdb.set_trace ( )

Definition at line 1473 of file pdb.py.

01473 
01474 def set_trace():
01475     Pdb().set_trace(sys._getframe().f_back)
01476 
01477 # Post-Mortem interface

def pdb.test ( )

Definition at line 1500 of file pdb.py.

01500 
01501 def test():
01502     run(TESTCMD)
01503 
# print help

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace",
00002            "post_mortem", "help"]

Definition at line 87 of file pdb.py.

Initial value:
00001 [
00002         'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable',
00003         'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until',
00004         'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist',
00005         'args', 'print', 'pp', 'whatis', 'source', 'display', 'undisplay',
00006         'interact', 'alias', 'unalias', 'debug', 'quit',
00007     ]

Definition at line 1443 of file pdb.py.

Initial value:
00001 """\
00002 usage: pdb.py [-c command] ... pyfile [arg] ...
00003 
00004 Debug the Python program given by pyfile.
00005 
00006 Initial commands are read from .pdbrc files in your home directory
00007 and in the current directory, if they exist.  Commands supplied with
00008 -c are executed after commands from .pdbrc files.
00009 
00010 To let the script run until an exception occurs, use "-c continue".
00011 To let the script run up to a given line X in the debugged file, use
00012 "-c 'until X'"."""

Definition at line 1508 of file pdb.py.

Definition at line 139 of file pdb.py.

string pdb.TESTCMD = 'import x; x.main()'

Definition at line 1498 of file pdb.py.