1-
21.. _debugger :
32
43:mod: `pdb ` --- The Python Debugger
@@ -50,7 +49,16 @@ after normal exit of the program), pdb will restart the program. Automatic
5049restarting preserves pdb's state (such as breakpoints) and in most cases is more
5150useful than quitting the debugger upon program's exit.
5251
53- Typical usage to inspect a crashed program is::
52+ The typical usage to break into the debugger from a running program is to
53+ insert ::
54+
55+ import pdb; pdb.set_trace()
56+
57+ at the location you want to break into the debugger. You can then step through
58+ the code following this statement, and continue running without debugger using
59+ the ``c `` command.
60+
61+ The typical usage to inspect a crashed program is::
5462
5563 >>> import pdb
5664 >>> import mymodule
@@ -67,10 +75,10 @@ Typical usage to inspect a crashed program is::
6775 -> print(spam)
6876 (Pdb)
6977
78+
7079The module defines the following functions; each enters the debugger in a
7180slightly different way:
7281
73-
7482.. function :: run(statement[, globals[, locals]])
7583
7684 Execute the *statement * (given as a string) under debugger control. The
@@ -113,7 +121,38 @@ slightly different way:
113121
114122.. function :: pm()
115123
116- Enter post-mortem debugging of the traceback found in ``sys.last_traceback ``.
124+ Enter post-mortem debugging of the traceback found in
125+ :data: `sys.last_traceback `.
126+
127+
128+ The ``run_* `` functions and :func: `set_trace ` are aliases for instantiating the
129+ :class: `Pdb ` class and calling the method of the same name. If you want to
130+ access further features, you have to do this yourself:
131+
132+ .. class :: Pdb(completekey='tab', stdin=None, stdout=None, skip=None)
133+
134+ :class: `Pdb ` is the debugger class.
135+
136+ The *completekey *, *stdin * and *stdout * arguments are passed to the
137+ underlying :class: `cmd.Cmd ` class; see the description there.
138+
139+ The *skip * argument, if given, must be an iterable of glob-style module name
140+ patterns. The debugger will not step into frames that originate in a module
141+ that matches one of these patterns. [1 ]_
142+
143+ Example call to enable tracing with *skip *::
144+
145+ import pdb; pdb.Pdb(skip=['django.*']).set_trace()
146+
147+ .. versionadded :: 2.7
148+ The *skip * argument.
149+
150+ .. method :: run(statement[, globals[, locals]])
151+ runeval(expression[, globals[, locals]])
152+ runcall(function[, argument, ...])
153+ set_trace()
154+
155+ See the documentation for the functions explained above.
117156
118157
119158.. _debugger-commands :
@@ -336,3 +375,9 @@ run [*args* ...]
336375
337376q(uit)
338377 Quit from the debugger. The program being executed is aborted.
378+
379+
380+ .. rubric :: Footnotes
381+
382+ .. [1 ] Whether a frame is considered to originate in a certain module
383+ is determined by the ``__name__ `` in the frame globals.
0 commit comments