gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1007 行
80KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="pdb — The Python Debugger" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/pdb.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/pdb.py The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, i..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/pdb.py The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, i..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>pdb — The Python Debugger &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="The Python Profilers" href="profile.html" />
  33. <link rel="prev" title="faulthandler — Dump the Python traceback" href="faulthandler.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/pdb.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> — The Python Debugger</a><ul>
  86. <li><a class="reference internal" href="#debugger-commands">Debugger Commands</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="faulthandler.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="profile.html"
  99. title="next chapter">The Python Profilers</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/pdb.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="profile.html" title="The Python Profilers"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="debug.html" accesskey="U">Debugging and Profiling</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> — The Python Debugger</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-pdb">
  169. <span id="pdb-the-python-debugger"></span><span id="debugger"></span><h1><a class="reference internal" href="#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> — The Python Debugger<a class="headerlink" href="#module-pdb" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/pdb.py">Lib/pdb.py</a></p>
  171. <hr class="docutils" id="index-0" />
  172. <p>The module <a class="reference internal" href="#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> defines an interactive source code debugger for Python
  173. programs. It supports setting (conditional) breakpoints and single stepping at
  174. the source line level, inspection of stack frames, source code listing, and
  175. evaluation of arbitrary Python code in the context of any stack frame. It also
  176. supports post-mortem debugging and can be called under program control.</p>
  177. <p id="index-1">The debugger is extensible – it is actually defined as the class <a class="reference internal" href="#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a>.
  178. This is currently undocumented but easily understood by reading the source. The
  179. extension interface uses the modules <a class="reference internal" href="bdb.html#module-bdb" title="bdb: Debugger framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code></a> and <a class="reference internal" href="cmd.html#module-cmd" title="cmd: Build line-oriented command interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmd</span></code></a>.</p>
  180. <div class="admonition seealso">
  181. <p class="admonition-title">See also</p>
  182. <dl class="simple">
  183. <dt>Module <a class="reference internal" href="faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a></dt><dd><p>Used to dump Python tracebacks explicitly, on a fault, after a timeout,
  184. or on a user signal.</p>
  185. </dd>
  186. <dt>Module <a class="reference internal" href="traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a></dt><dd><p>Standard interface to extract, format and print stack traces of Python programs.</p>
  187. </dd>
  188. </dl>
  189. </div>
  190. <p>The typical usage to break into the debugger is to insert:</p>
  191. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pdb</span><span class="p">;</span> <span class="n">pdb</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>
  192. </pre></div>
  193. </div>
  194. <p>Or:</p>
  195. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">breakpoint</span><span class="p">()</span>
  196. </pre></div>
  197. </div>
  198. <p>at the location you want to break into the debugger, and then run the program.
  199. You can then step through the code following this statement, and continue
  200. running without the debugger using the <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a> command.</p>
  201. <div class="versionchanged">
  202. <p><span class="versionmodified changed">Changed in version 3.7: </span>The built-in <a class="reference internal" href="functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a>, when called with defaults, can be used
  203. instead of <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">pdb;</span> <span class="pre">pdb.set_trace()</span></code>.</p>
  204. </div>
  205. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">double</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  206. <span class="nb">breakpoint</span><span class="p">()</span>
  207. <span class="k">return</span> <span class="n">x</span> <span class="o">*</span> <span class="mi">2</span>
  208. <span class="n">val</span> <span class="o">=</span> <span class="mi">3</span>
  209. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">val</span><span class="si">}</span><span class="s2"> * 2 is </span><span class="si">{</span><span class="n">double</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  210. </pre></div>
  211. </div>
  212. <p>The debugger’s prompt is <code class="docutils literal notranslate"><span class="pre">(Pdb)</span></code>, which is the indicator that you are in debug mode:</p>
  213. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="o">...</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="n">double</span><span class="p">()</span>
  214. <span class="o">-&gt;</span> <span class="k">return</span> <span class="n">x</span> <span class="o">*</span> <span class="mi">2</span>
  215. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">p</span> <span class="n">x</span>
  216. <span class="mi">3</span>
  217. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="k">continue</span>
  218. <span class="mi">3</span> <span class="o">*</span> <span class="mi">2</span> <span class="ow">is</span> <span class="mi">6</span>
  219. </pre></div>
  220. </div>
  221. <div class="versionchanged">
  222. <p><span class="versionmodified changed">Changed in version 3.3: </span>Tab-completion via the <a class="reference internal" href="readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a> module is available for commands and
  223. command arguments, e.g. the current global and local names are offered as
  224. arguments of the <code class="docutils literal notranslate"><span class="pre">p</span></code> command.</p>
  225. </div>
  226. <p>You can also invoke <a class="reference internal" href="#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> from the command line to debug other scripts. For
  227. example:</p>
  228. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pdb</span> <span class="n">myscript</span><span class="o">.</span><span class="n">py</span>
  229. </pre></div>
  230. </div>
  231. <p>When invoked as a module, pdb will automatically enter post-mortem debugging if
  232. the program being debugged exits abnormally. After post-mortem debugging (or
  233. after normal exit of the program), pdb will restart the program. Automatic
  234. restarting preserves pdb’s state (such as breakpoints) and in most cases is more
  235. useful than quitting the debugger upon program’s exit.</p>
  236. <div class="versionchanged">
  237. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <code class="docutils literal notranslate"><span class="pre">-c</span></code> option to execute commands as if given
  238. in a <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> file; see <a class="reference internal" href="#debugger-commands"><span class="std std-ref">Debugger Commands</span></a>.</p>
  239. </div>
  240. <div class="versionchanged">
  241. <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code class="docutils literal notranslate"><span class="pre">-m</span></code> option to execute modules similar to the way
  242. <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> does. As with a script, the debugger will pause execution just
  243. before the first line of the module.</p>
  244. </div>
  245. <p>Typical usage to execute a statement under control of the debugger is:</p>
  246. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pdb</span>
  247. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  248. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="n">x</span><span class="p">)</span>
  249. <span class="gp">&gt;&gt;&gt; </span><span class="n">pdb</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;f(2)&quot;</span><span class="p">)</span>
  250. <span class="go">&gt; &lt;string&gt;(1)&lt;module&gt;()</span>
  251. <span class="go">(Pdb) continue</span>
  252. <span class="go">0.5</span>
  253. <span class="gp">&gt;&gt;&gt;</span>
  254. </pre></div>
  255. </div>
  256. <p>The typical usage to inspect a crashed program is:</p>
  257. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pdb</span>
  258. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  259. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="n">x</span><span class="p">)</span>
  260. <span class="gp">...</span>
  261. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
  262. <span class="gt">Traceback (most recent call last):</span>
  263. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  264. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">2</span>, in <span class="n">f</span>
  265. <span class="gr">ZeroDivisionError</span>: <span class="n">division by zero</span>
  266. <span class="gp">&gt;&gt;&gt; </span><span class="n">pdb</span><span class="o">.</span><span class="n">pm</span><span class="p">()</span>
  267. <span class="go">&gt; &lt;stdin&gt;(2)f()</span>
  268. <span class="go">(Pdb) p x</span>
  269. <span class="go">0</span>
  270. <span class="go">(Pdb)</span>
  271. </pre></div>
  272. </div>
  273. <p>The module defines the following functions; each enters the debugger in a
  274. slightly different way:</p>
  275. <dl class="py function">
  276. <dt class="sig sig-object py" id="pdb.run">
  277. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">statement</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.run" title="Link to this definition">¶</a></dt>
  278. <dd><p>Execute the <em>statement</em> (given as a string or a code object) under debugger
  279. control. The debugger prompt appears before any code is executed; you can
  280. set breakpoints and type <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a>, or you can step through the
  281. statement using <a class="reference internal" href="#pdbcommand-step"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code></a> or <a class="reference internal" href="#pdbcommand-next"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code></a> (all these commands are
  282. explained below). The optional <em>globals</em> and <em>locals</em> arguments specify the
  283. environment in which the code is executed; by default the dictionary of the
  284. module <a class="reference internal" href="__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> is used. (See the explanation of the built-in
  285. <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> or <a class="reference internal" href="functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a> functions.)</p>
  286. </dd></dl>
  287. <dl class="py function">
  288. <dt class="sig sig-object py" id="pdb.runeval">
  289. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">runeval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expression</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.runeval" title="Link to this definition">¶</a></dt>
  290. <dd><p>Evaluate the <em>expression</em> (given as a string or a code object) under debugger
  291. control. When <a class="reference internal" href="#pdb.runeval" title="pdb.runeval"><code class="xref py py-func docutils literal notranslate"><span class="pre">runeval()</span></code></a> returns, it returns the value of the
  292. <em>expression</em>. Otherwise this function is similar to <a class="reference internal" href="#pdb.run" title="pdb.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a>.</p>
  293. </dd></dl>
  294. <dl class="py function">
  295. <dt class="sig sig-object py" id="pdb.runcall">
  296. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">runcall</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwds</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.runcall" title="Link to this definition">¶</a></dt>
  297. <dd><p>Call the <em>function</em> (a function or method object, not a string) with the
  298. given arguments. When <a class="reference internal" href="#pdb.runcall" title="pdb.runcall"><code class="xref py py-func docutils literal notranslate"><span class="pre">runcall()</span></code></a> returns, it returns whatever the
  299. function call returned. The debugger prompt appears as soon as the function
  300. is entered.</p>
  301. </dd></dl>
  302. <dl class="py function">
  303. <dt class="sig sig-object py" id="pdb.set_trace">
  304. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">set_trace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">header</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.set_trace" title="Link to this definition">¶</a></dt>
  305. <dd><p>Enter the debugger at the calling stack frame. This is useful to hard-code
  306. a breakpoint at a given point in a program, even if the code is not
  307. otherwise being debugged (e.g. when an assertion fails). If given,
  308. <em>header</em> is printed to the console just before debugging begins.</p>
  309. <div class="versionchanged">
  310. <p><span class="versionmodified changed">Changed in version 3.7: </span>The keyword-only argument <em>header</em>.</p>
  311. </div>
  312. </dd></dl>
  313. <dl class="py function">
  314. <dt class="sig sig-object py" id="pdb.post_mortem">
  315. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">post_mortem</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">traceback</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.post_mortem" title="Link to this definition">¶</a></dt>
  316. <dd><p>Enter post-mortem debugging of the given <em>traceback</em> object. If no
  317. <em>traceback</em> is given, it uses the one of the exception that is currently
  318. being handled (an exception must be being handled if the default is to be
  319. used).</p>
  320. </dd></dl>
  321. <dl class="py function">
  322. <dt class="sig sig-object py" id="pdb.pm">
  323. <span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">pm</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pdb.pm" title="Link to this definition">¶</a></dt>
  324. <dd><p>Enter post-mortem debugging of the traceback found in
  325. <a class="reference internal" href="sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a>.</p>
  326. </dd></dl>
  327. <p>The <code class="docutils literal notranslate"><span class="pre">run*</span></code> functions and <a class="reference internal" href="#pdb.set_trace" title="pdb.set_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_trace()</span></code></a> are aliases for instantiating the
  328. <a class="reference internal" href="#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> class and calling the method of the same name. If you want to
  329. access further features, you have to do this yourself:</p>
  330. <dl class="py class">
  331. <dt class="sig sig-object py" id="pdb.Pdb">
  332. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">Pdb</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">completekey</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'tab'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stdin</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stdout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">skip</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nosigint</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">readrc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb" title="Link to this definition">¶</a></dt>
  333. <dd><p><a class="reference internal" href="#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> is the debugger class.</p>
  334. <p>The <em>completekey</em>, <em>stdin</em> and <em>stdout</em> arguments are passed to the
  335. underlying <a class="reference internal" href="cmd.html#cmd.Cmd" title="cmd.Cmd"><code class="xref py py-class docutils literal notranslate"><span class="pre">cmd.Cmd</span></code></a> class; see the description there.</p>
  336. <p>The <em>skip</em> argument, if given, must be an iterable of glob-style module name
  337. patterns. The debugger will not step into frames that originate in a module
  338. that matches one of these patterns. <a class="footnote-reference brackets" href="#id3" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p>
  339. <p>By default, Pdb sets a handler for the SIGINT signal (which is sent when the
  340. user presses <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">C</kbd></kbd> on the console) when you give a <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a> command.
  341. This allows you to break into the debugger again by pressing <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">C</kbd></kbd>. If you
  342. want Pdb not to touch the SIGINT handler, set <em>nosigint</em> to true.</p>
  343. <p>The <em>readrc</em> argument defaults to true and controls whether Pdb will load
  344. .pdbrc files from the filesystem.</p>
  345. <p>Example call to enable tracing with <em>skip</em>:</p>
  346. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pdb</span><span class="p">;</span> <span class="n">pdb</span><span class="o">.</span><span class="n">Pdb</span><span class="p">(</span><span class="n">skip</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;django.*&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>
  347. </pre></div>
  348. </div>
  349. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">pdb.Pdb</span></code> with no arguments.</p>
  350. <div class="versionchanged">
  351. <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <em>skip</em> parameter.</p>
  352. </div>
  353. <div class="versionchanged">
  354. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <em>nosigint</em> parameter.
  355. Previously, a SIGINT handler was never set by Pdb.</p>
  356. </div>
  357. <div class="versionchanged">
  358. <p><span class="versionmodified changed">Changed in version 3.6: </span>The <em>readrc</em> argument.</p>
  359. </div>
  360. <dl class="py method">
  361. <dt class="sig sig-object py" id="pdb.Pdb.run">
  362. <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">statement</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb.run" title="Link to this definition">¶</a></dt>
  363. <dt class="sig sig-object py" id="pdb.Pdb.runeval">
  364. <span class="sig-name descname"><span class="pre">runeval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expression</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb.runeval" title="Link to this definition">¶</a></dt>
  365. <dt class="sig sig-object py" id="pdb.Pdb.runcall">
  366. <span class="sig-name descname"><span class="pre">runcall</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwds</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb.runcall" title="Link to this definition">¶</a></dt>
  367. <dt class="sig sig-object py" id="pdb.Pdb.set_trace">
  368. <span class="sig-name descname"><span class="pre">set_trace</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb.set_trace" title="Link to this definition">¶</a></dt>
  369. <dd><p>See the documentation for the functions explained above.</p>
  370. </dd></dl>
  371. </dd></dl>
  372. <section id="debugger-commands">
  373. <span id="id2"></span><h2>Debugger Commands<a class="headerlink" href="#debugger-commands" title="Link to this heading">¶</a></h2>
  374. <p>The commands recognized by the debugger are listed below. Most commands can be
  375. abbreviated to one or two letters as indicated; e.g. <code class="docutils literal notranslate"><span class="pre">h(elp)</span></code> means that
  376. either <code class="docutils literal notranslate"><span class="pre">h</span></code> or <code class="docutils literal notranslate"><span class="pre">help</span></code> can be used to enter the help command (but not <code class="docutils literal notranslate"><span class="pre">he</span></code>
  377. or <code class="docutils literal notranslate"><span class="pre">hel</span></code>, nor <code class="docutils literal notranslate"><span class="pre">H</span></code> or <code class="docutils literal notranslate"><span class="pre">Help</span></code> or <code class="docutils literal notranslate"><span class="pre">HELP</span></code>). Arguments to commands must be
  378. separated by whitespace (spaces or tabs). Optional arguments are enclosed in
  379. square brackets (<code class="docutils literal notranslate"><span class="pre">[]</span></code>) in the command syntax; the square brackets must not be
  380. typed. Alternatives in the command syntax are separated by a vertical bar
  381. (<code class="docutils literal notranslate"><span class="pre">|</span></code>).</p>
  382. <p>Entering a blank line repeats the last command entered. Exception: if the last
  383. command was a <a class="reference internal" href="#pdbcommand-list"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">list</span></code></a> command, the next 11 lines are listed.</p>
  384. <p>Commands that the debugger doesn’t recognize are assumed to be Python statements
  385. and are executed in the context of the program being debugged. Python
  386. statements can also be prefixed with an exclamation point (<code class="docutils literal notranslate"><span class="pre">!</span></code>). This is a
  387. powerful way to inspect the program being debugged; it is even possible to
  388. change a variable or call a function. When an exception occurs in such a
  389. statement, the exception name is printed but the debugger’s state is not
  390. changed.</p>
  391. <p>The debugger supports <a class="reference internal" href="#debugger-aliases"><span class="std std-ref">aliases</span></a>. Aliases can have
  392. parameters which allows one a certain level of adaptability to the context under
  393. examination.</p>
  394. <p>Multiple commands may be entered on a single line, separated by <code class="docutils literal notranslate"><span class="pre">;;</span></code>. (A
  395. single <code class="docutils literal notranslate"><span class="pre">;</span></code> is not used as it is the separator for multiple commands in a line
  396. that is passed to the Python parser.) No intelligence is applied to separating
  397. the commands; the input is split at the first <code class="docutils literal notranslate"><span class="pre">;;</span></code> pair, even if it is in the
  398. middle of a quoted string. A workaround for strings with double semicolons
  399. is to use implicit string concatenation <code class="docutils literal notranslate"><span class="pre">';'';'</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;;&quot;&quot;;&quot;</span></code>.</p>
  400. <p>To set a temporary global variable, use a <em>convenience variable</em>. A <em>convenience
  401. variable</em> is a variable whose name starts with <code class="docutils literal notranslate"><span class="pre">$</span></code>. For example, <code class="docutils literal notranslate"><span class="pre">$foo</span> <span class="pre">=</span> <span class="pre">1</span></code>
  402. sets a global variable <code class="docutils literal notranslate"><span class="pre">$foo</span></code> which you can use in the debugger session. The
  403. <em>convenience variables</em> are cleared when the program resumes execution so it’s
  404. less likely to interfere with your program compared to using normal variables
  405. like <code class="docutils literal notranslate"><span class="pre">foo</span> <span class="pre">=</span> <span class="pre">1</span></code>.</p>
  406. <p>There are three preset <em>convenience variables</em>:</p>
  407. <ul class="simple">
  408. <li><p><code class="docutils literal notranslate"><span class="pre">$_frame</span></code>: the current frame you are debugging</p></li>
  409. <li><p><code class="docutils literal notranslate"><span class="pre">$_retval</span></code>: the return value if the frame is returning</p></li>
  410. <li><p><code class="docutils literal notranslate"><span class="pre">$_exception</span></code>: the exception if the frame is raising an exception</p></li>
  411. </ul>
  412. <div class="versionadded">
  413. <p><span class="versionmodified added">New in version 3.12.</span></p>
  414. </div>
  415. <p id="index-2">If a file <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> exists in the user’s home directory or in the current
  416. directory, it is read with <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> encoding and executed as if it had been
  417. typed at the debugger prompt, with the exception that empty lines and lines
  418. starting with <code class="docutils literal notranslate"><span class="pre">#</span></code> are ignored. This is particularly useful for aliases. If both
  419. files exist, the one in the home directory is read first and aliases defined there
  420. can be overridden by the local file.</p>
  421. <div class="versionchanged">
  422. <p><span class="versionmodified changed">Changed in version 3.2: </span><code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> can now contain commands that continue debugging, such as
  423. <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a> or <a class="reference internal" href="#pdbcommand-next"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code></a>. Previously, these commands had no
  424. effect.</p>
  425. </div>
  426. <div class="versionchanged">
  427. <p><span class="versionmodified changed">Changed in version 3.11: </span><code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> is now read with <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> encoding. Previously, it was read
  428. with the system locale encoding.</p>
  429. </div>
  430. <dl class="std pdbcommand">
  431. <dt class="sig sig-object std" id="pdbcommand-help">
  432. <span class="sig-name descname"><span class="pre">h(elp)</span></span><span class="sig-prename descclassname"> <span class="pre">[command]</span></span><a class="headerlink" href="#pdbcommand-help" title="Link to this definition">¶</a></dt>
  433. <dd><p>Without argument, print the list of available commands. With a <em>command</em> as
  434. argument, print help about that command. <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">pdb</span></code> displays the full
  435. documentation (the docstring of the <a class="reference internal" href="#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> module). Since the <em>command</em>
  436. argument must be an identifier, <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">exec</span></code> must be entered to get help on
  437. the <code class="docutils literal notranslate"><span class="pre">!</span></code> command.</p>
  438. </dd></dl>
  439. <dl class="std pdbcommand">
  440. <dt class="sig sig-object std" id="pdbcommand-where">
  441. <span class="sig-name descname"><span class="pre">w(here)</span></span><a class="headerlink" href="#pdbcommand-where" title="Link to this definition">¶</a></dt>
  442. <dd><p>Print a stack trace, with the most recent frame at the bottom. An arrow (<code class="docutils literal notranslate"><span class="pre">&gt;</span></code>)
  443. indicates the current frame, which determines the context of most commands.</p>
  444. </dd></dl>
  445. <dl class="std pdbcommand">
  446. <dt class="sig sig-object std" id="pdbcommand-down">
  447. <span class="sig-name descname"><span class="pre">d(own)</span></span><span class="sig-prename descclassname"> <span class="pre">[count]</span></span><a class="headerlink" href="#pdbcommand-down" title="Link to this definition">¶</a></dt>
  448. <dd><p>Move the current frame <em>count</em> (default one) levels down in the stack trace
  449. (to a newer frame).</p>
  450. </dd></dl>
  451. <dl class="std pdbcommand">
  452. <dt class="sig sig-object std" id="pdbcommand-up">
  453. <span class="sig-name descname"><span class="pre">u(p)</span></span><span class="sig-prename descclassname"> <span class="pre">[count]</span></span><a class="headerlink" href="#pdbcommand-up" title="Link to this definition">¶</a></dt>
  454. <dd><p>Move the current frame <em>count</em> (default one) levels up in the stack trace (to
  455. an older frame).</p>
  456. </dd></dl>
  457. <dl class="std pdbcommand">
  458. <dt class="sig sig-object std" id="pdbcommand-break">
  459. <span class="sig-name descname"><span class="pre">b(reak)</span></span><span class="sig-prename descclassname"> <span class="pre">[([filename:]lineno</span> <span class="pre">|</span> <span class="pre">function)</span> <span class="pre">[,</span> <span class="pre">condition]]</span></span><a class="headerlink" href="#pdbcommand-break" title="Link to this definition">¶</a></dt>
  460. <dd><p>With a <em>lineno</em> argument, set a break there in the current file. With a
  461. <em>function</em> argument, set a break at the first executable statement within
  462. that function. The line number may be prefixed with a filename and a colon,
  463. to specify a breakpoint in another file (probably one that hasn’t been loaded
  464. yet). The file is searched on <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Note that each breakpoint
  465. is assigned a number to which all the other breakpoint commands refer.</p>
  466. <p>If a second argument is present, it is an expression which must evaluate to
  467. true before the breakpoint is honored.</p>
  468. <p>Without argument, list all breaks, including for each breakpoint, the number
  469. of times that breakpoint has been hit, the current ignore count, and the
  470. associated condition if any.</p>
  471. </dd></dl>
  472. <dl class="std pdbcommand">
  473. <dt class="sig sig-object std" id="pdbcommand-tbreak">
  474. <span class="sig-name descname"><span class="pre">tbreak</span></span><span class="sig-prename descclassname"> <span class="pre">[([filename:]lineno</span> <span class="pre">|</span> <span class="pre">function)</span> <span class="pre">[,</span> <span class="pre">condition]]</span></span><a class="headerlink" href="#pdbcommand-tbreak" title="Link to this definition">¶</a></dt>
  475. <dd><p>Temporary breakpoint, which is removed automatically when it is first hit.
  476. The arguments are the same as for <a class="reference internal" href="#pdbcommand-break"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">break</span></code></a>.</p>
  477. </dd></dl>
  478. <dl class="std pdbcommand">
  479. <dt class="sig sig-object std" id="pdbcommand-clear">
  480. <span class="sig-name descname"><span class="pre">cl(ear)</span></span><span class="sig-prename descclassname"> <span class="pre">[filename:lineno</span> <span class="pre">|</span> <span class="pre">bpnumber</span> <span class="pre">...]</span></span><a class="headerlink" href="#pdbcommand-clear" title="Link to this definition">¶</a></dt>
  481. <dd><p>With a <em>filename:lineno</em> argument, clear all the breakpoints at this line.
  482. With a space separated list of breakpoint numbers, clear those breakpoints.
  483. Without argument, clear all breaks (but first ask confirmation).</p>
  484. </dd></dl>
  485. <dl class="std pdbcommand">
  486. <dt class="sig sig-object std" id="pdbcommand-disable">
  487. <span class="sig-name descname"><span class="pre">disable</span></span><span class="sig-prename descclassname"> <span class="pre">bpnumber</span> <span class="pre">[bpnumber</span> <span class="pre">...]</span></span><a class="headerlink" href="#pdbcommand-disable" title="Link to this definition">¶</a></dt>
  488. <dd><p>Disable the breakpoints given as a space separated list of breakpoint
  489. numbers. Disabling a breakpoint means it cannot cause the program to stop
  490. execution, but unlike clearing a breakpoint, it remains in the list of
  491. breakpoints and can be (re-)enabled.</p>
  492. </dd></dl>
  493. <dl class="std pdbcommand">
  494. <dt class="sig sig-object std" id="pdbcommand-enable">
  495. <span class="sig-name descname"><span class="pre">enable</span></span><span class="sig-prename descclassname"> <span class="pre">bpnumber</span> <span class="pre">[bpnumber</span> <span class="pre">...]</span></span><a class="headerlink" href="#pdbcommand-enable" title="Link to this definition">¶</a></dt>
  496. <dd><p>Enable the breakpoints specified.</p>
  497. </dd></dl>
  498. <dl class="std pdbcommand">
  499. <dt class="sig sig-object std" id="pdbcommand-ignore">
  500. <span class="sig-name descname"><span class="pre">ignore</span></span><span class="sig-prename descclassname"> <span class="pre">bpnumber</span> <span class="pre">[count]</span></span><a class="headerlink" href="#pdbcommand-ignore" title="Link to this definition">¶</a></dt>
  501. <dd><p>Set the ignore count for the given breakpoint number. If <em>count</em> is omitted,
  502. the ignore count is set to 0. A breakpoint becomes active when the ignore
  503. count is zero. When non-zero, the <em>count</em> is decremented each time the
  504. breakpoint is reached and the breakpoint is not disabled and any associated
  505. condition evaluates to true.</p>
  506. </dd></dl>
  507. <dl class="std pdbcommand">
  508. <dt class="sig sig-object std" id="pdbcommand-condition">
  509. <span class="sig-name descname"><span class="pre">condition</span></span><span class="sig-prename descclassname"> <span class="pre">bpnumber</span> <span class="pre">[condition]</span></span><a class="headerlink" href="#pdbcommand-condition" title="Link to this definition">¶</a></dt>
  510. <dd><p>Set a new <em>condition</em> for the breakpoint, an expression which must evaluate
  511. to true before the breakpoint is honored. If <em>condition</em> is absent, any
  512. existing condition is removed; i.e., the breakpoint is made unconditional.</p>
  513. </dd></dl>
  514. <dl class="std pdbcommand">
  515. <dt class="sig sig-object std" id="pdbcommand-commands">
  516. <span class="sig-name descname"><span class="pre">commands</span></span><span class="sig-prename descclassname"> <span class="pre">[bpnumber]</span></span><a class="headerlink" href="#pdbcommand-commands" title="Link to this definition">¶</a></dt>
  517. <dd><p>Specify a list of commands for breakpoint number <em>bpnumber</em>. The commands
  518. themselves appear on the following lines. Type a line containing just
  519. <code class="docutils literal notranslate"><span class="pre">end</span></code> to terminate the commands. An example:</p>
  520. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">commands</span> <span class="mi">1</span>
  521. <span class="p">(</span><span class="n">com</span><span class="p">)</span> <span class="n">p</span> <span class="n">some_variable</span>
  522. <span class="p">(</span><span class="n">com</span><span class="p">)</span> <span class="n">end</span>
  523. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>
  524. </pre></div>
  525. </div>
  526. <p>To remove all commands from a breakpoint, type <code class="docutils literal notranslate"><span class="pre">commands</span></code> and follow it
  527. immediately with <code class="docutils literal notranslate"><span class="pre">end</span></code>; that is, give no commands.</p>
  528. <p>With no <em>bpnumber</em> argument, <code class="docutils literal notranslate"><span class="pre">commands</span></code> refers to the last breakpoint set.</p>
  529. <p>You can use breakpoint commands to start your program up again. Simply use
  530. the <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a> command, or <a class="reference internal" href="#pdbcommand-step"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code></a>,
  531. or any other command that resumes execution.</p>
  532. <p>Specifying any command resuming execution
  533. (currently <a class="reference internal" href="#pdbcommand-continue"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">continue</span></code></a>, <a class="reference internal" href="#pdbcommand-step"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code></a>, <a class="reference internal" href="#pdbcommand-next"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code></a>,
  534. <a class="reference internal" href="#pdbcommand-return"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">return</span></code></a>, <a class="reference internal" href="#pdbcommand-jump"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">jump</span></code></a>, <a class="reference internal" href="#pdbcommand-quit"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">quit</span></code></a> and their abbreviations)
  535. terminates the command list (as if
  536. that command was immediately followed by end). This is because any time you
  537. resume execution (even with a simple next or step), you may encounter another
  538. breakpoint—which could have its own command list, leading to ambiguities about
  539. which list to execute.</p>
  540. <p>If you use the <code class="docutils literal notranslate"><span class="pre">silent</span></code> command in the command list, the usual message about
  541. stopping at a breakpoint is not printed. This may be desirable for breakpoints
  542. that are to print a specific message and then continue. If none of the other
  543. commands print anything, you see no sign that the breakpoint was reached.</p>
  544. </dd></dl>
  545. <dl class="std pdbcommand">
  546. <dt class="sig sig-object std" id="pdbcommand-step">
  547. <span class="sig-name descname"><span class="pre">s(tep)</span></span><a class="headerlink" href="#pdbcommand-step" title="Link to this definition">¶</a></dt>
  548. <dd><p>Execute the current line, stop at the first possible occasion (either in a
  549. function that is called or on the next line in the current function).</p>
  550. </dd></dl>
  551. <dl class="std pdbcommand">
  552. <dt class="sig sig-object std" id="pdbcommand-next">
  553. <span class="sig-name descname"><span class="pre">n(ext)</span></span><a class="headerlink" href="#pdbcommand-next" title="Link to this definition">¶</a></dt>
  554. <dd><p>Continue execution until the next line in the current function is reached or
  555. it returns. (The difference between <a class="reference internal" href="#pdbcommand-next"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code></a> and <a class="reference internal" href="#pdbcommand-step"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code></a> is
  556. that <a class="reference internal" href="#pdbcommand-step"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code></a> stops inside a called function, while <a class="reference internal" href="#pdbcommand-next"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code></a>
  557. executes called functions at (nearly) full speed, only stopping at the next
  558. line in the current function.)</p>
  559. </dd></dl>
  560. <dl class="std pdbcommand">
  561. <dt class="sig sig-object std" id="pdbcommand-until">
  562. <span class="sig-name descname"><span class="pre">unt(il)</span></span><span class="sig-prename descclassname"> <span class="pre">[lineno]</span></span><a class="headerlink" href="#pdbcommand-until" title="Link to this definition">¶</a></dt>
  563. <dd><p>Without argument, continue execution until the line with a number greater
  564. than the current one is reached.</p>
  565. <p>With <em>lineno</em>, continue execution until a line with a number greater or
  566. equal to <em>lineno</em> is reached. In both cases, also stop when the current frame
  567. returns.</p>
  568. <div class="versionchanged">
  569. <p><span class="versionmodified changed">Changed in version 3.2: </span>Allow giving an explicit line number.</p>
  570. </div>
  571. </dd></dl>
  572. <dl class="std pdbcommand">
  573. <dt class="sig sig-object std" id="pdbcommand-return">
  574. <span class="sig-name descname"><span class="pre">r(eturn)</span></span><a class="headerlink" href="#pdbcommand-return" title="Link to this definition">¶</a></dt>
  575. <dd><p>Continue execution until the current function returns.</p>
  576. </dd></dl>
  577. <dl class="std pdbcommand">
  578. <dt class="sig sig-object std" id="pdbcommand-continue">
  579. <span class="sig-name descname"><span class="pre">c(ont(inue))</span></span><a class="headerlink" href="#pdbcommand-continue" title="Link to this definition">¶</a></dt>
  580. <dd><p>Continue execution, only stop when a breakpoint is encountered.</p>
  581. </dd></dl>
  582. <dl class="std pdbcommand">
  583. <dt class="sig sig-object std" id="pdbcommand-jump">
  584. <span class="sig-name descname"><span class="pre">j(ump)</span></span><span class="sig-prename descclassname"> <span class="pre">lineno</span></span><a class="headerlink" href="#pdbcommand-jump" title="Link to this definition">¶</a></dt>
  585. <dd><p>Set the next line that will be executed. Only available in the bottom-most
  586. frame. This lets you jump back and execute code again, or jump forward to
  587. skip code that you don’t want to run.</p>
  588. <p>It should be noted that not all jumps are allowed – for instance it is not
  589. possible to jump into the middle of a <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a> loop or out of a
  590. <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause.</p>
  591. </dd></dl>
  592. <dl class="std pdbcommand">
  593. <dt class="sig sig-object std" id="pdbcommand-list">
  594. <span class="sig-name descname"><span class="pre">l(ist)</span></span><span class="sig-prename descclassname"> <span class="pre">[first[,</span> <span class="pre">last]]</span></span><a class="headerlink" href="#pdbcommand-list" title="Link to this definition">¶</a></dt>
  595. <dd><p>List source code for the current file. Without arguments, list 11 lines
  596. around the current line or continue the previous listing. With <code class="docutils literal notranslate"><span class="pre">.</span></code> as
  597. argument, list 11 lines around the current line. With one argument,
  598. list 11 lines around at that line. With two arguments, list the given range;
  599. if the second argument is less than the first, it is interpreted as a count.</p>
  600. <p>The current line in the current frame is indicated by <code class="docutils literal notranslate"><span class="pre">-&gt;</span></code>. If an
  601. exception is being debugged, the line where the exception was originally
  602. raised or propagated is indicated by <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code>, if it differs from the current
  603. line.</p>
  604. <div class="versionchanged">
  605. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code> marker.</p>
  606. </div>
  607. </dd></dl>
  608. <dl class="std pdbcommand">
  609. <dt class="sig sig-object std" id="pdbcommand-ll">
  610. <span class="sig-name descname"><span class="pre">ll</span></span><span class="sig-prename descclassname"> <span class="pre">|</span> <span class="pre">longlist</span></span><a class="headerlink" href="#pdbcommand-ll" title="Link to this definition">¶</a></dt>
  611. <dd><p>List all source code for the current function or frame. Interesting lines
  612. are marked as for <a class="reference internal" href="#pdbcommand-list"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">list</span></code></a>.</p>
  613. <div class="versionadded">
  614. <p><span class="versionmodified added">New in version 3.2.</span></p>
  615. </div>
  616. </dd></dl>
  617. <dl class="std pdbcommand">
  618. <dt class="sig sig-object std" id="pdbcommand-args">
  619. <span class="sig-name descname"><span class="pre">a(rgs)</span></span><a class="headerlink" href="#pdbcommand-args" title="Link to this definition">¶</a></dt>
  620. <dd><p>Print the arguments of the current function and their current values.</p>
  621. </dd></dl>
  622. <dl class="std pdbcommand">
  623. <dt class="sig sig-object std" id="pdbcommand-p">
  624. <span class="sig-name descname"><span class="pre">p</span></span><span class="sig-prename descclassname"> <span class="pre">expression</span></span><a class="headerlink" href="#pdbcommand-p" title="Link to this definition">¶</a></dt>
  625. <dd><p>Evaluate <em>expression</em> in the current context and print its value.</p>
  626. <div class="admonition note">
  627. <p class="admonition-title">Note</p>
  628. <p><code class="docutils literal notranslate"><span class="pre">print()</span></code> can also be used, but is not a debugger command — this executes the
  629. Python <a class="reference internal" href="functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> function.</p>
  630. </div>
  631. </dd></dl>
  632. <dl class="std pdbcommand">
  633. <dt class="sig sig-object std" id="pdbcommand-pp">
  634. <span class="sig-name descname"><span class="pre">pp</span></span><span class="sig-prename descclassname"> <span class="pre">expression</span></span><a class="headerlink" href="#pdbcommand-pp" title="Link to this definition">¶</a></dt>
  635. <dd><p>Like the <a class="reference internal" href="#pdbcommand-p"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">p</span></code></a> command, except the value of <em>expression</em> is
  636. pretty-printed using the <a class="reference internal" href="pprint.html#module-pprint" title="pprint: Data pretty printer."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code></a> module.</p>
  637. </dd></dl>
  638. <dl class="std pdbcommand">
  639. <dt class="sig sig-object std" id="pdbcommand-whatis">
  640. <span class="sig-name descname"><span class="pre">whatis</span></span><span class="sig-prename descclassname"> <span class="pre">expression</span></span><a class="headerlink" href="#pdbcommand-whatis" title="Link to this definition">¶</a></dt>
  641. <dd><p>Print the type of <em>expression</em>.</p>
  642. </dd></dl>
  643. <dl class="std pdbcommand">
  644. <dt class="sig sig-object std" id="pdbcommand-source">
  645. <span class="sig-name descname"><span class="pre">source</span></span><span class="sig-prename descclassname"> <span class="pre">expression</span></span><a class="headerlink" href="#pdbcommand-source" title="Link to this definition">¶</a></dt>
  646. <dd><p>Try to get source code of <em>expression</em> and display it.</p>
  647. <div class="versionadded">
  648. <p><span class="versionmodified added">New in version 3.2.</span></p>
  649. </div>
  650. </dd></dl>
  651. <dl class="std pdbcommand">
  652. <dt class="sig sig-object std" id="pdbcommand-display">
  653. <span class="sig-name descname"><span class="pre">display</span></span><span class="sig-prename descclassname"> <span class="pre">[expression]</span></span><a class="headerlink" href="#pdbcommand-display" title="Link to this definition">¶</a></dt>
  654. <dd><p>Display the value of <em>expression</em> if it changed, each time execution stops
  655. in the current frame.</p>
  656. <p>Without <em>expression</em>, list all display expressions for the current frame.</p>
  657. <div class="admonition note">
  658. <p class="admonition-title">Note</p>
  659. <p>Display evaluates <em>expression</em> and compares to the result of the previous
  660. evaluation of <em>expression</em>, so when the result is mutable, display may not
  661. be able to pick up the changes.</p>
  662. </div>
  663. <p>Example:</p>
  664. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">lst</span> <span class="o">=</span> <span class="p">[]</span>
  665. <span class="nb">breakpoint</span><span class="p">()</span>
  666. <span class="k">pass</span>
  667. <span class="n">lst</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  668. <span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>
  669. </pre></div>
  670. </div>
  671. <p>Display won’t realize <code class="docutils literal notranslate"><span class="pre">lst</span></code> has been changed because the result of evaluation
  672. is modified in place by <code class="docutils literal notranslate"><span class="pre">lst.append(1)</span></code> before being compared:</p>
  673. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  674. <span class="o">-&gt;</span> <span class="k">pass</span>
  675. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">display</span> <span class="n">lst</span>
  676. <span class="n">display</span> <span class="n">lst</span><span class="p">:</span> <span class="p">[]</span>
  677. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>
  678. <span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  679. <span class="o">-&gt;</span> <span class="n">lst</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  680. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>
  681. <span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  682. <span class="o">-&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>
  683. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>
  684. </pre></div>
  685. </div>
  686. <p>You can do some tricks with copy mechanism to make it work:</p>
  687. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  688. <span class="o">-&gt;</span> <span class="k">pass</span>
  689. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">display</span> <span class="n">lst</span><span class="p">[:]</span>
  690. <span class="n">display</span> <span class="n">lst</span><span class="p">[:]:</span> <span class="p">[]</span>
  691. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>
  692. <span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  693. <span class="o">-&gt;</span> <span class="n">lst</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  694. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>
  695. <span class="o">&gt;</span> <span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">()</span>
  696. <span class="o">-&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>
  697. <span class="n">display</span> <span class="n">lst</span><span class="p">[:]:</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="p">[</span><span class="n">old</span><span class="p">:</span> <span class="p">[]]</span>
  698. <span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>
  699. </pre></div>
  700. </div>
  701. <div class="versionadded">
  702. <p><span class="versionmodified added">New in version 3.2.</span></p>
  703. </div>
  704. </dd></dl>
  705. <dl class="std pdbcommand">
  706. <dt class="sig sig-object std" id="pdbcommand-undisplay">
  707. <span class="sig-name descname"><span class="pre">undisplay</span></span><span class="sig-prename descclassname"> <span class="pre">[expression]</span></span><a class="headerlink" href="#pdbcommand-undisplay" title="Link to this definition">¶</a></dt>
  708. <dd><p>Do not display <em>expression</em> anymore in the current frame. Without
  709. <em>expression</em>, clear all display expressions for the current frame.</p>
  710. <div class="versionadded">
  711. <p><span class="versionmodified added">New in version 3.2.</span></p>
  712. </div>
  713. </dd></dl>
  714. <dl class="std pdbcommand">
  715. <dt class="sig sig-object std" id="pdbcommand-interact">
  716. <span class="sig-name descname"><span class="pre">interact</span></span><a class="headerlink" href="#pdbcommand-interact" title="Link to this definition">¶</a></dt>
  717. <dd><p>Start an interactive interpreter (using the <a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-mod docutils literal notranslate"><span class="pre">code</span></code></a> module) whose global
  718. namespace contains all the (global and local) names found in the current
  719. scope.</p>
  720. <div class="versionadded">
  721. <p><span class="versionmodified added">New in version 3.2.</span></p>
  722. </div>
  723. </dd></dl>
  724. <dl class="std pdbcommand" id="debugger-aliases">
  725. <dt class="sig sig-object std" id="pdbcommand-alias">
  726. <span class="sig-name descname"><span class="pre">alias</span></span><span class="sig-prename descclassname"> <span class="pre">[name</span> <span class="pre">[command]]</span></span><a class="headerlink" href="#pdbcommand-alias" title="Link to this definition">¶</a></dt>
  727. <dd><p>Create an alias called <em>name</em> that executes <em>command</em>. The <em>command</em> must
  728. <em>not</em> be enclosed in quotes. Replaceable parameters can be indicated by
  729. <code class="docutils literal notranslate"><span class="pre">%1</span></code>, <code class="docutils literal notranslate"><span class="pre">%2</span></code>, and so on, while <code class="docutils literal notranslate"><span class="pre">%*</span></code> is replaced by all the parameters.
  730. If <em>command</em> is omitted, the current alias for <em>name</em> is shown. If no
  731. arguments are given, all aliases are listed.</p>
  732. <p>Aliases may be nested and can contain anything that can be legally typed at
  733. the pdb prompt. Note that internal pdb commands <em>can</em> be overridden by
  734. aliases. Such a command is then hidden until the alias is removed. Aliasing
  735. is recursively applied to the first word of the command line; all other words
  736. in the line are left alone.</p>
  737. <p>As an example, here are two useful aliases (especially when placed in the
  738. <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> file):</p>
  739. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Print instance variables (usage &quot;pi classInst&quot;)</span>
  740. <span class="n">alias</span> <span class="n">pi</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="o">%</span><span class="mf">1.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;%1.</span><span class="si">{</span><span class="n">k</span><span class="si">}</span><span class="s2"> = </span><span class="si">{</span><span class="o">%</span><span class="mf">1.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  741. <span class="c1"># Print instance variables in self</span>
  742. <span class="n">alias</span> <span class="n">ps</span> <span class="n">pi</span> <span class="bp">self</span>
  743. </pre></div>
  744. </div>
  745. </dd></dl>
  746. <dl class="std pdbcommand">
  747. <dt class="sig sig-object std" id="pdbcommand-unalias">
  748. <span class="sig-name descname"><span class="pre">unalias</span></span><span class="sig-prename descclassname"> <span class="pre">name</span></span><a class="headerlink" href="#pdbcommand-unalias" title="Link to this definition">¶</a></dt>
  749. <dd><p>Delete the specified alias <em>name</em>.</p>
  750. </dd></dl>
  751. <dl class="std pdbcommand">
  752. <dt class="sig sig-object std" id="pdbcommand-0">
  753. <span class="sig-name descname"><span class="pre">!</span></span><span class="sig-prename descclassname"> <span class="pre">statement</span></span><a class="headerlink" href="#pdbcommand-0" title="Link to this definition">¶</a></dt>
  754. <dd><p>Execute the (one-line) <em>statement</em> in the context of the current stack frame.
  755. The exclamation point can be omitted unless the first word of the statement
  756. resembles a debugger command, e.g.:</p>
  757. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(Pdb) ! n=42
  758. (Pdb)
  759. </pre></div>
  760. </div>
  761. <p>To set a global variable, you can prefix the assignment command with a
  762. <a class="reference internal" href="../reference/simple_stmts.html#global"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">global</span></code></a> statement on the same line, e.g.:</p>
  763. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(Pdb) global list_options; list_options = [&#39;-l&#39;]
  764. (Pdb)
  765. </pre></div>
  766. </div>
  767. </dd></dl>
  768. <dl class="std pdbcommand">
  769. <dt class="sig sig-object std" id="pdbcommand-run">
  770. <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-prename descclassname"> <span class="pre">[args</span> <span class="pre">...]</span></span><a class="headerlink" href="#pdbcommand-run" title="Link to this definition">¶</a></dt>
  771. <dt class="sig sig-object std" id="pdbcommand-restart">
  772. <span class="sig-name descname"><span class="pre">restart</span></span><span class="sig-prename descclassname"> <span class="pre">[args</span> <span class="pre">...]</span></span><a class="headerlink" href="#pdbcommand-restart" title="Link to this definition">¶</a></dt>
  773. <dd><p>Restart the debugged Python program. If <em>args</em> is supplied, it is split
  774. with <a class="reference internal" href="shlex.html#module-shlex" title="shlex: Simple lexical analysis for Unix shell-like languages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shlex</span></code></a> and the result is used as the new <a class="reference internal" href="sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a>.
  775. History, breakpoints, actions and debugger options are preserved.
  776. <a class="reference internal" href="#pdbcommand-restart"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">restart</span></code></a> is an alias for <a class="reference internal" href="#pdbcommand-run"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">run</span></code></a>.</p>
  777. </dd></dl>
  778. <dl class="std pdbcommand">
  779. <dt class="sig sig-object std" id="pdbcommand-quit">
  780. <span class="sig-name descname"><span class="pre">q(uit)</span></span><a class="headerlink" href="#pdbcommand-quit" title="Link to this definition">¶</a></dt>
  781. <dd><p>Quit from the debugger. The program being executed is aborted.</p>
  782. </dd></dl>
  783. <dl class="std pdbcommand">
  784. <dt class="sig sig-object std" id="pdbcommand-debug">
  785. <span class="sig-name descname"><span class="pre">debug</span></span><span class="sig-prename descclassname"> <span class="pre">code</span></span><a class="headerlink" href="#pdbcommand-debug" title="Link to this definition">¶</a></dt>
  786. <dd><p>Enter a recursive debugger that steps through <em>code</em>
  787. (which is an arbitrary expression or statement to be
  788. executed in the current environment).</p>
  789. </dd></dl>
  790. <dl class="std pdbcommand">
  791. <dt class="sig sig-object std" id="pdbcommand-retval">
  792. <span class="sig-name descname"><span class="pre">retval</span></span><a class="headerlink" href="#pdbcommand-retval" title="Link to this definition">¶</a></dt>
  793. <dd><p>Print the return value for the last return of the current function.</p>
  794. </dd></dl>
  795. <p class="rubric">Footnotes</p>
  796. <aside class="footnote-list brackets">
  797. <aside class="footnote brackets" id="id3" role="doc-footnote">
  798. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
  799. <p>Whether a frame is considered to originate in a certain module
  800. is determined by the <code class="docutils literal notranslate"><span class="pre">__name__</span></code> in the frame globals.</p>
  801. </aside>
  802. </aside>
  803. </section>
  804. </section>
  805. <div class="clearer"></div>
  806. </div>
  807. </div>
  808. </div>
  809. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  810. <div class="sphinxsidebarwrapper">
  811. <div>
  812. <h3><a href="../contents.html">Table of Contents</a></h3>
  813. <ul>
  814. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> — The Python Debugger</a><ul>
  815. <li><a class="reference internal" href="#debugger-commands">Debugger Commands</a></li>
  816. </ul>
  817. </li>
  818. </ul>
  819. </div>
  820. <div>
  821. <h4>Previous topic</h4>
  822. <p class="topless"><a href="faulthandler.html"
  823. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>
  824. </div>
  825. <div>
  826. <h4>Next topic</h4>
  827. <p class="topless"><a href="profile.html"
  828. title="next chapter">The Python Profilers</a></p>
  829. </div>
  830. <div role="note" aria-label="source link">
  831. <h3>This Page</h3>
  832. <ul class="this-page-menu">
  833. <li><a href="../bugs.html">Report a Bug</a></li>
  834. <li>
  835. <a href="https://github.com/python/cpython/blob/main/Doc/library/pdb.rst"
  836. rel="nofollow">Show Source
  837. </a>
  838. </li>
  839. </ul>
  840. </div>
  841. </div>
  842. <div id="sidebarbutton" title="Collapse sidebar">
  843. <span>«</span>
  844. </div>
  845. </div>
  846. <div class="clearer"></div>
  847. </div>
  848. <div class="related" role="navigation" aria-label="related navigation">
  849. <h3>Navigation</h3>
  850. <ul>
  851. <li class="right" style="margin-right: 10px">
  852. <a href="../genindex.html" title="General Index"
  853. >index</a></li>
  854. <li class="right" >
  855. <a href="../py-modindex.html" title="Python Module Index"
  856. >modules</a> |</li>
  857. <li class="right" >
  858. <a href="profile.html" title="The Python Profilers"
  859. >next</a> |</li>
  860. <li class="right" >
  861. <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"
  862. >previous</a> |</li>
  863. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  864. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  865. <li class="switchers">
  866. <div class="language_switcher_placeholder"></div>
  867. <div class="version_switcher_placeholder"></div>
  868. </li>
  869. <li>
  870. </li>
  871. <li id="cpython-language-and-version">
  872. <a href="../index.html">3.12.3 Documentation</a> &#187;
  873. </li>
  874. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  875. <li class="nav-item nav-item-2"><a href="debug.html" >Debugging and Profiling</a> &#187;</li>
  876. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> — The Python Debugger</a></li>
  877. <li class="right">
  878. <div class="inline-search" role="search">
  879. <form class="inline-search" action="../search.html" method="get">
  880. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  881. <input type="submit" value="Go" />
  882. </form>
  883. </div>
  884. |
  885. </li>
  886. <li class="right">
  887. <label class="theme-selector-label">
  888. Theme
  889. <select class="theme-selector" oninput="activateTheme(this.value)">
  890. <option value="auto" selected>Auto</option>
  891. <option value="light">Light</option>
  892. <option value="dark">Dark</option>
  893. </select>
  894. </label> |</li>
  895. </ul>
  896. </div>
  897. <div class="footer">
  898. &copy;
  899. <a href="../copyright.html">
  900. Copyright
  901. </a>
  902. 2001-2024, Python Software Foundation.
  903. <br />
  904. This page is licensed under the Python Software Foundation License Version 2.
  905. <br />
  906. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  907. <br />
  908. See <a href="/license.html">History and License</a> for more information.<br />
  909. <br />
  910. The Python Software Foundation is a non-profit corporation.
  911. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  912. <br />
  913. <br />
  914. Last updated on Apr 09, 2024 (13:47 UTC).
  915. <a href="/bugs.html">Found a bug</a>?
  916. <br />
  917. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  918. </div>
  919. </body>
  920. </html>
上海开阖软件有限公司 沪ICP备12045867号-1