[Python-checkins] r72323 - in python/branches/py3k: Doc/library/pdb.rst Lib/bdb.py Lib/pdb.py Lib/test/test_pdb.py Misc/NEWS
georg.brandl
python-checkins at python.org
Tue May 5 11:00:20 CEST 2009
Author: georg.brandl
Date: Tue May 5 11:00:19 2009
New Revision: 72323
Log:
Merged revisions 72322 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72322 | georg.brandl | 2009-05-05 10:54:11 +0200 (Di, 05 Mai 2009) | 1 line
#5142: add module skipping feature to pdb.
........
Added:
python/branches/py3k/Lib/test/test_pdb.py
- copied, changed from r72322, /python/trunk/Lib/test/test_pdb.py
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/library/pdb.rst
python/branches/py3k/Lib/bdb.py
python/branches/py3k/Lib/pdb.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Doc/library/pdb.rst
==============================================================================
--- python/branches/py3k/Doc/library/pdb.rst (original)
+++ python/branches/py3k/Doc/library/pdb.rst Tue May 5 11:00:19 2009
@@ -1,4 +1,3 @@
-
.. _debugger:
:mod:`pdb` --- The Python Debugger
@@ -50,7 +49,16 @@
restarting preserves pdb's state (such as breakpoints) and in most cases is more
useful than quitting the debugger upon program's exit.
-Typical usage to inspect a crashed program is::
+The typical usage to break into the debugger from a running program is to
+insert ::
+
+ import pdb; pdb.set_trace()
+
+at the location you want to break into the debugger. You can then step through
+the code following this statement, and continue running without debugger using
+the ``c`` command.
+
+The typical usage to inspect a crashed program is::
>>> import pdb
>>> import mymodule
@@ -67,10 +75,10 @@
-> print(spam)
(Pdb)
+
The module defines the following functions; each enters the debugger in a
slightly different way:
-
.. function:: run(statement[, globals[, locals]])
Execute the *statement* (given as a string) under debugger control. The
@@ -113,7 +121,38 @@
.. function:: pm()
- Enter post-mortem debugging of the traceback found in ``sys.last_traceback``.
+ Enter post-mortem debugging of the traceback found in
+ :data:`sys.last_traceback`.
+
+
+The ``run_*`` functions and :func:`set_trace` are aliases for instantiating the
+:class:`Pdb` class and calling the method of the same name. If you want to
+access further features, you have to do this yourself:
+
+.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None)
+
+ :class:`Pdb` is the debugger class.
+
+ The *completekey*, *stdin* and *stdout* arguments are passed to the
+ underlying :class:`cmd.Cmd` class; see the description there.
+
+ The *skip* argument, if given, must be an iterable of glob-style module name
+ patterns. The debugger will not step into frames that originate in a module
+ that matches one of these patterns. [1]_
+
+ Example call to enable tracing with *skip*::
+
+ import pdb; pdb.Pdb(skip=['django.*']).set_trace()
+
+ .. versionadded:: 2.7
+ The *skip* argument.
+
+ .. method:: run(statement[, globals[, locals]])
+ runeval(expression[, globals[, locals]])
+ runcall(function[, argument, ...])
+ set_trace()
+
+ See the documentation for the functions explained above.
.. _debugger-commands:
@@ -336,3 +375,9 @@
q(uit)
Quit from the debugger. The program being executed is aborted.
+
+
+.. rubric:: Footnotes
+
+.. [1] Whether a frame is considered to originate in a certain module
+ is determined by the ``__name__`` in the frame globals.
Modified: python/branches/py3k/Lib/bdb.py
==============================================================================
--- python/branches/py3k/Lib/bdb.py (original)
+++ python/branches/py3k/Lib/bdb.py Tue May 5 11:00:19 2009
@@ -1,5 +1,6 @@
"""Debugger basics"""
+import fnmatch
import sys
import os
import types
@@ -19,7 +20,8 @@
The standard debugger class (pdb.Pdb) is an example.
"""
- def __init__(self):
+ def __init__(self, skip=None):
+ self.skip = set(skip) if skip else None
self.breaks = {}
self.fncache = {}
@@ -94,9 +96,18 @@
# methods, but they may if they want to redefine the
# definition of stopping and breakpoints.
+ def is_skipped_module(self, module_name):
+ for pattern in self.skip:
+ if fnmatch.fnmatch(module_name, pattern):
+ return True
+ return False
+
def stop_here(self, frame):
# (CT) stopframe may now also be None, see dispatch_call.
# (CT) the former test for None is therefore removed from here.
+ if self.skip and \
+ self.is_skipped_module(frame.f_globals.get('__name__')):
+ return False
if frame is self.stopframe:
return frame.f_lineno >= self.stoplineno
while frame is not None and frame is not self.stopframe:
Modified: python/branches/py3k/Lib/pdb.py
==============================================================================
--- python/branches/py3k/Lib/pdb.py (original)
+++ python/branches/py3k/Lib/pdb.py Tue May 5 11:00:19 2009
@@ -58,8 +58,8 @@
class Pdb(bdb.Bdb, cmd.Cmd):
- def __init__(self, completekey='tab', stdin=None, stdout=None):
- bdb.Bdb.__init__(self)
+ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None):
+ bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
if stdout:
self.use_rawinput = 0
Copied: python/branches/py3k/Lib/test/test_pdb.py (from r72322, /python/trunk/Lib/test/test_pdb.py)
==============================================================================
--- /python/trunk/Lib/test/test_pdb.py (original)
+++ python/branches/py3k/Lib/test/test_pdb.py Tue May 5 11:00:19 2009
@@ -7,9 +7,9 @@
import doctest
import tempfile
-from test import test_support
+from test import support
# This little helper class is essential for testing pdb under doctest.
-from test_doctest import _FakeInput
+from test.test_doctest import _FakeInput
def test_pdb_skip_modules():
@@ -17,8 +17,8 @@
>>> def skip_module():
... import string
- ... import pdb;pdb.Pdb(skip=['string*']).set_trace()
- ... string.lower('FOO')
+ ... import pdb; pdb.Pdb(skip=['stri*']).set_trace()
+ ... string.capwords('FOO')
>>> real_stdin = sys.stdin
>>> sys.stdin = _FakeInput([
... 'step',
@@ -30,18 +30,18 @@
... finally:
... sys.stdin = real_stdin
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
- -> string.lower('FOO')
+ -> string.capwords('FOO')
(Pdb) step
--Return--
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
- -> string.lower('FOO')
+ -> string.capwords('FOO')
(Pdb) continue
"""
# Module for testing skipping of module that makes a callback
mod = imp.new_module('module_to_skip')
-exec 'def foo_pony(callback): x = 1; callback(); return None' in mod.__dict__
+exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
def test_pdb_skip_modules_with_callback():
@@ -92,7 +92,7 @@
def test_main():
from test import test_pdb
- test_support.run_doctest(test_pdb, verbosity=True)
+ support.run_doctest(test_pdb, verbosity=True)
if __name__ == '__main__':
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Tue May 5 11:00:19 2009
@@ -118,6 +118,8 @@
Library
-------
+- Issue #5142: Add the ability to skip modules while stepping to pdb.
+
- Issue #1309567: Fix linecache behavior of stripping subdirectories when
looking for files given by a relative filename.
More information about the Python-checkins
mailing list