Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
pdb.html1263 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="pdb — The Python Debugger" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/pdb.html" />10<meta property="og:site_name" content="Python documentation" />11<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..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_pdb_10cddfce.png" />15<meta property="og:image:alt" 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..." />16<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..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>pdb — The Python Debugger &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="profiling — Python profilers" href="profiling.html" />43    <link rel="prev" title="faulthandler — Dump the Python traceback" href="faulthandler.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/pdb.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <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>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<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>108<li><a class="reference internal" href="#command-line-interface">Command-line interface</a></li>109<li><a class="reference internal" href="#debugger-commands">Debugger commands</a></li>110</ul>111</li>112</ul>113 114  </div>115  <div>116    <h4>Previous topic</h4>117    <p class="topless"><a href="faulthandler.html"118                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>119  </div>120  <div>121    <h4>Next topic</h4>122    <p class="topless"><a href="profiling.html"123                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling</span></code> — Python profilers</a></p>124  </div>125  <script>126    document.addEventListener('DOMContentLoaded', () => {127        const title = document.querySelector('meta[property="og:title"]').content;128        const elements = document.querySelectorAll('.improvepage');129        const pageurl = window.location.href.split('?')[0];130        elements.forEach(element => {131            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));132            url.searchParams.set('pagetitle', title);133            url.searchParams.set('pageurl', pageurl);134            url.searchParams.set('pagesource', "library/pdb.rst");135            element.href = url.toString();136        });137    });138  </script>139  <div role="note" aria-label="source link">140    <h3>This page</h3>141    <ul class="this-page-menu">142      <li><a href="../bugs.html">Report a bug</a></li>143      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>144      <li>145        <a href="https://github.com/python/cpython/blob/main/Doc/library/pdb.rst?plain=1"146            rel="nofollow">Show source147        </a>148      </li>149      150    </ul>151  </div>152        </nav>153    </div>154</div>155 156  157    <div class="related" role="navigation" aria-label="Related">158      <h3>Navigation</h3>159      <ul>160        <li class="right" style="margin-right: 10px">161          <a href="../genindex.html" title="General Index"162             accesskey="I">index</a></li>163        <li class="right" >164          <a href="../py-modindex.html" title="Python Module Index"165             >modules</a> |</li>166        <li class="right" >167          <a href="profiling.html" title="profiling — Python profilers"168             accesskey="N">next</a> |</li>169        <li class="right" >170          <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"171             accesskey="P">previous</a> |</li>172 173          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>174          <li><a href="https://www.python.org/">Python</a> &#187;</li>175          <li class="switchers">176            <div class="language_switcher_placeholder"></div>177            <div class="version_switcher_placeholder"></div>178          </li>179          <li>180              181          </li>182    <li id="cpython-language-and-version">183      <a href="../index.html">3.15.0a6 Documentation</a> &#187;184    </li>185 186          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>187          <li class="nav-item nav-item-2"><a href="debug.html" accesskey="U">Debugging and profiling</a> &#187;</li>188        <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>189                <li class="right">190                    191 192    <div class="inline-search" role="search">193        <form class="inline-search" action="../search.html" method="get">194          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">195          <input type="submit" value="Go">196        </form>197    </div>198                     |199                </li>200            <li class="right">201<label class="theme-selector-label">202    Theme203    <select class="theme-selector" oninput="activateTheme(this.value)">204        <option value="auto" selected>Auto</option>205        <option value="light">Light</option>206        <option value="dark">Dark</option>207    </select>208</label> |</li>209            210      </ul>211    </div>    212 213    <div class="document">214      <div class="documentwrapper">215        <div class="bodywrapper">216          <div class="body" role="main">217            218  <section id="module-pdb">219<span id="pdb-the-python-debugger"></span><span id="debugger"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> — The Python Debugger<a class="headerlink" href="#module-pdb" title="Link to this heading">¶</a></h1>220<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/pdb.py">Lib/pdb.py</a></p>221<hr class="docutils" id="index-0" />222<p>The module <code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> defines an interactive source code debugger for Python223programs.  It supports setting (conditional) breakpoints and single stepping at224the source line level, inspection of stack frames, source code listing, and225evaluation of arbitrary Python code in the context of any stack frame.  It also226supports post-mortem debugging and can be called under program control.</p>227<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>.228This is currently undocumented but easily understood by reading the source.  The229extension 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>230<div class="admonition seealso">231<p class="admonition-title">See also</p>232<dl class="simple">233<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,234or on a user signal.</p>235</dd>236<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>237</dd>238</dl>239</div>240<p>The typical usage to break into the debugger is to insert:</p>241<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </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>242</pre></div>243</div>244<p>Or:</p>245<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">breakpoint</span><span class="p">()</span>246</pre></div>247</div>248<p>at the location you want to break into the debugger, and then run the program.249You can then step through the code following this statement, and continue250running 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>251<div class="versionchanged">252<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 used253instead 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>254</div>255<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">double</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>256   <span class="nb">breakpoint</span><span class="p">()</span>257   <span class="k">return</span> <span class="n">x</span> <span class="o">*</span> <span class="mi">2</span>258<span class="n">val</span> <span class="o">=</span> <span class="mi">3</span>259<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>260</pre></div>261</div>262<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>263<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">2</span><span class="p">)</span><span class="n">double</span><span class="p">()</span>264<span class="o">-&gt;</span> <span class="nb">breakpoint</span><span class="p">()</span>265<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">p</span> <span class="n">x</span>266<span class="mi">3</span>267<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="k">continue</span>268<span class="mi">3</span> <span class="o">*</span> <span class="mi">2</span> <span class="ow">is</span> <span class="mi">6</span>269</pre></div>270</div>271<div class="versionchanged">272<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."><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a> module is available for commands and273command arguments, e.g. the current global and local names are offered as274arguments of the <code class="docutils literal notranslate"><span class="pre">p</span></code> command.</p>275</div>276<section id="command-line-interface">277<span id="pdb-cli"></span><h2>Command-line interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2>278<p>You can also invoke <code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> from the command line to debug other scripts.  For279example:</p>280<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="p">[</span><span class="o">-</span><span class="n">c</span> <span class="n">command</span><span class="p">]</span> <span class="p">(</span><span class="o">-</span><span class="n">m</span> <span class="n">module</span> <span class="o">|</span> <span class="o">-</span><span class="n">p</span> <span class="n">pid</span> <span class="o">|</span> <span class="n">pyfile</span><span class="p">)</span> <span class="p">[</span><span class="n">args</span> <span class="o">...</span><span class="p">]</span>281</pre></div>282</div>283<p>When invoked as a module, pdb will automatically enter post-mortem debugging if284the program being debugged exits abnormally.  After post-mortem debugging (or285after normal exit of the program), pdb will restart the program.  Automatic286restarting preserves pdb’s state (such as breakpoints) and in most cases is more287useful than quitting the debugger upon program’s exit.</p>288<dl class="std option">289<dt class="sig sig-object std" id="cmdoption-pdb-c">290<span id="cmdoption-pdb-command"></span><span class="sig-name descname"><span class="pre">-c</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--command</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;command&gt;</span></span><a class="headerlink" href="#cmdoption-pdb-c" title="Link to this definition">¶</a></dt>291<dd><p>To execute commands as if given in a <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> file; see292<a class="reference internal" href="#debugger-commands"><span class="std std-ref">Debugger commands</span></a>.</p>293<div class="versionchanged">294<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.</p>295</div>296</dd></dl>297 298<dl class="std option">299<dt class="sig sig-object std" id="cmdoption-pdb-m">300<span class="sig-name descname"><span class="pre">-m</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;module&gt;</span></span><a class="headerlink" href="#cmdoption-pdb-m" title="Link to this definition">¶</a></dt>301<dd><p>To execute modules similar to the way <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> does. As with a script,302the debugger will pause execution just before the first line of the module.</p>303<div class="versionchanged">304<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.</p>305</div>306</dd></dl>307 308<dl class="std option">309<dt class="sig sig-object std" id="cmdoption-pdb-p">310<span id="cmdoption-pdb-pid"></span><span class="sig-name descname"><span class="pre">-p</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--pid</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;pid&gt;</span></span><a class="headerlink" href="#cmdoption-pdb-p" title="Link to this definition">¶</a></dt>311<dd><p>Attach to the process with the specified PID.</p>312<div class="versionadded">313<p><span class="versionmodified added">Added in version 3.14.</span></p>314</div>315</dd></dl>316 317<p>To attach to a running Python process for remote debugging, use the <code class="docutils literal notranslate"><span class="pre">-p</span></code> or318<code class="docutils literal notranslate"><span class="pre">--pid</span></code> option with the target process’s PID:</p>319<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="o">-</span><span class="n">p</span> <span class="mi">1234</span>320</pre></div>321</div>322<div class="admonition note">323<p class="admonition-title">Note</p>324<p>Attaching to a process that is blocked in a system call or waiting for I/O325will only work once the next bytecode instruction is executed or when the326process receives a signal.</p>327</div>328<p>Typical usage to execute a statement under control of the debugger is:</p>329<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="w"> </span><span class="nn">pdb</span>330<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>331<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>332<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>333<span class="go">&gt; &lt;string&gt;(1)&lt;module&gt;()</span>334<span class="go">(Pdb) continue</span>335<span class="go">0.5</span>336<span class="gp">&gt;&gt;&gt;</span>337</pre></div>338</div>339<p>The typical usage to inspect a crashed program is:</p>340<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="w"> </span><span class="nn">pdb</span>341<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>342<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>343<span class="gp">...</span>344<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>345<span class="gt">Traceback (most recent call last):</span>346  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>347  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">2</span>, in <span class="n">f</span>348<span class="gr">ZeroDivisionError</span>: <span class="n">division by zero</span>349<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>350<span class="go">&gt; &lt;stdin&gt;(2)f()</span>351<span class="go">(Pdb) p x</span>352<span class="go">0</span>353<span class="go">(Pdb)</span>354</pre></div>355</div>356<div class="versionchanged">357<p><span class="versionmodified changed">Changed in version 3.13: </span>The implementation of <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a> means that name assignments made via <code class="docutils literal notranslate"><span class="pre">pdb</span></code>358will immediately affect the active scope, even when running inside an359<a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scope</span></a>.</p>360</div>361<p>The module defines the following functions; each enters the debugger in a362slightly different way:</p>363<dl class="py function">364<dt class="sig sig-object py" id="pdb.run">365<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>366<dd><p>Execute the <em>statement</em> (given as a string or a code object) under debugger367control.  The debugger prompt appears before any code is executed; you can368set 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 the369statement 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 are370explained below).  The optional <em>globals</em> and <em>locals</em> arguments specify the371environment in which the code is executed; by default the dictionary of the372module <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-in373<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>374</dd></dl>375 376<dl class="py function">377<dt class="sig sig-object py" id="pdb.runeval">378<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>379<dd><p>Evaluate the <em>expression</em> (given as a string or a code object) under debugger380control.  When <code class="xref py py-func docutils literal notranslate"><span class="pre">runeval()</span></code> returns, it returns the value of the381<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>382</dd></dl>383 384<dl class="py function">385<dt class="sig sig-object py" id="pdb.runcall">386<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>387<dd><p>Call the <em>function</em> (a function or method object, not a string) with the388given arguments.  When <code class="xref py py-func docutils literal notranslate"><span class="pre">runcall()</span></code> returns, it returns whatever the389function call returned.  The debugger prompt appears as soon as the function390is entered.</p>391</dd></dl>392 393<dl class="py function">394<dt class="sig sig-object py" id="pdb.set_trace">395<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="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></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>, <em class="sig-param"><span class="n"><span class="pre">commands</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>396<dd><p>Enter the debugger at the calling stack frame.  This is useful to hard-code397a breakpoint at a given point in a program, even if the code is not398otherwise being debugged (e.g. when an assertion fails).  If given,399<em>header</em> is printed to the console just before debugging begins.400The <em>commands</em> argument, if given, is a list of commands to execute401when the debugger starts.</p>402<div class="versionchanged">403<p><span class="versionmodified changed">Changed in version 3.7: </span>The keyword-only argument <em>header</em>.</p>404</div>405<div class="versionchanged">406<p><span class="versionmodified changed">Changed in version 3.13: </span><code class="xref py py-func docutils literal notranslate"><span class="pre">set_trace()</span></code> will enter the debugger immediately, rather than407on the next line of code to be executed.</p>408</div>409<div class="versionadded">410<p><span class="versionmodified added">Added in version 3.14: </span>The <em>commands</em> argument.</p>411</div>412</dd></dl>413 414<dl class="py function">415<dt class="sig sig-object py" id="pdb.set_trace_async">416<em class="property"><span class="pre">awaitable</span> </em><span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">set_trace_async</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></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>, <em class="sig-param"><span class="n"><span class="pre">commands</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_async" title="Link to this definition">¶</a></dt>417<dd><p>async version of <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>. This function should be used inside an418async function with <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a>.</p>419<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">():</span>420    <span class="k">await</span> <span class="n">pdb</span><span class="o">.</span><span class="n">set_trace_async</span><span class="p">()</span>421</pre></div>422</div>423<p><a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> statements are supported if the debugger is invoked by this function.</p>424<div class="versionadded">425<p><span class="versionmodified added">Added in version 3.14.</span></p>426</div>427</dd></dl>428 429<dl class="py function">430<dt class="sig sig-object py" id="pdb.post_mortem">431<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">t</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>432<dd><p>Enter post-mortem debugging of the given exception or433<a class="reference internal" href="../reference/datamodel.html#traceback-objects"><span class="std std-ref">traceback object</span></a>. If no value is given, it uses434the exception that is currently being handled, or raises <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> if435there isn’t one.</p>436<div class="versionchanged">437<p><span class="versionmodified changed">Changed in version 3.13: </span>Support for exception objects was added.</p>438</div>439</dd></dl>440 441<dl class="py function">442<dt class="sig sig-object py" id="pdb.pm">443<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>444<dd><p>Enter post-mortem debugging of the exception found in445<a class="reference internal" href="sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a>.</p>446</dd></dl>447 448<dl class="py function">449<dt class="sig sig-object py" id="pdb.set_default_backend">450<span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">set_default_backend</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">backend</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.set_default_backend" title="Link to this definition">¶</a></dt>451<dd><p>There are two supported backends for pdb: <code class="docutils literal notranslate"><span class="pre">'settrace'</span></code> and <code class="docutils literal notranslate"><span class="pre">'monitoring'</span></code>.452See <a class="reference internal" href="bdb.html#bdb.Bdb" title="bdb.Bdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">bdb.Bdb</span></code></a> for details. The user can set the default backend to453use if none is specified when instantiating <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>. If no backend is454specified, the default is <code class="docutils literal notranslate"><span class="pre">'settrace'</span></code>.</p>455<div class="admonition note">456<p class="admonition-title">Note</p>457<p><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> 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> will not be affected by this458function. They always use <code class="docutils literal notranslate"><span class="pre">'monitoring'</span></code> backend.</p>459</div>460<div class="versionadded">461<p><span class="versionmodified added">Added in version 3.14.</span></p>462</div>463</dd></dl>464 465<dl class="py function">466<dt class="sig sig-object py" id="pdb.get_default_backend">467<span class="sig-prename descclassname"><span class="pre">pdb.</span></span><span class="sig-name descname"><span class="pre">get_default_backend</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pdb.get_default_backend" title="Link to this definition">¶</a></dt>468<dd><p>Returns the default backend for pdb.</p>469<div class="versionadded">470<p><span class="versionmodified added">Added in version 3.14.</span></p>471</div>472</dd></dl>473 474<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 the475<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 to476access further features, you have to do this yourself:</p>477<dl class="py class">478<dt class="sig sig-object py" id="pdb.Pdb">479<em class="property"><span class="k"><span class="pre">class</span></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>, <em class="sig-param"><span class="n"><span class="pre">mode</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">backend</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">colorize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdb.Pdb" title="Link to this definition">¶</a></dt>480<dd><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code> is the debugger class.</p>481<p>The <em>completekey</em>, <em>stdin</em> and <em>stdout</em> arguments are passed to the482underlying <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>483<p>The <em>skip</em> argument, if given, must be an iterable of glob-style module name484patterns.  The debugger will not step into frames that originate in a module485that 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>486<p>By default, Pdb sets a handler for the SIGINT signal (which is sent when the487user presses <kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">C</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.488This allows you to break into the debugger again by pressing <kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">C</kbd>.  If you489want Pdb not to touch the SIGINT handler, set <em>nosigint</em> to true.</p>490<p>The <em>readrc</em> argument defaults to true and controls whether Pdb will load491.pdbrc files from the filesystem.</p>492<p>The <em>mode</em> argument specifies how the debugger was invoked.493It impacts the workings of some debugger commands.494Valid values are <code class="docutils literal notranslate"><span class="pre">'inline'</span></code> (used by the breakpoint() builtin),495<code class="docutils literal notranslate"><span class="pre">'cli'</span></code> (used by the command line invocation)496or <code class="docutils literal notranslate"><span class="pre">None</span></code> (for backwards compatible behaviour, as before the <em>mode</em>497argument was added).</p>498<p>The <em>backend</em> argument specifies the backend to use for the debugger. If <code class="docutils literal notranslate"><span class="pre">None</span></code>499is passed, the default backend will be used. See <a class="reference internal" href="#pdb.set_default_backend" title="pdb.set_default_backend"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_default_backend()</span></code></a>.500Otherwise the supported backends are <code class="docutils literal notranslate"><span class="pre">'settrace'</span></code> and <code class="docutils literal notranslate"><span class="pre">'monitoring'</span></code>.</p>501<p>The <em>colorize</em> argument, if set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, will enable colorized output in the502debugger, if color is supported. This will highlight source code displayed in pdb.</p>503<p>Example call to enable tracing with <em>skip</em>:</p>504<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </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>505</pre></div>506</div>507<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>508<div class="versionchanged">509<p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <em>skip</em> parameter.</p>510</div>511<div class="versionchanged">512<p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <em>nosigint</em> parameter.513Previously, a SIGINT handler was never set by Pdb.</p>514</div>515<div class="versionchanged">516<p><span class="versionmodified changed">Changed in version 3.6: </span>The <em>readrc</em> argument.</p>517</div>518<div class="versionadded">519<p><span class="versionmodified added">Added in version 3.14: </span>Added the <em>mode</em> argument.</p>520</div>521<div class="versionadded">522<p><span class="versionmodified added">Added in version 3.14: </span>Added the <em>backend</em> argument.</p>523</div>524<div class="versionadded">525<p><span class="versionmodified added">Added in version 3.14: </span>Added the <em>colorize</em> argument.</p>526</div>527<div class="versionchanged">528<p><span class="versionmodified changed">Changed in version 3.14: </span>Inline breakpoints like <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> or <a class="reference internal" href="#pdb.set_trace" title="pdb.set_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code></a> will529always stop the program at calling frame, ignoring the <em>skip</em> pattern (if any).</p>530</div>531<dl class="py method">532<dt class="sig sig-object py" id="pdb.Pdb.run">533<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>534<dt class="sig sig-object py" id="pdb.Pdb.runeval">535<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>536<dt class="sig sig-object py" id="pdb.Pdb.runcall">537<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>538<dt class="sig sig-object py" id="pdb.Pdb.set_trace">539<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>540<dd><p>See the documentation for the functions explained above.</p>541</dd></dl>542 543</dd></dl>544 545</section>546<section id="debugger-commands">547<span id="id2"></span><h2>Debugger commands<a class="headerlink" href="#debugger-commands" title="Link to this heading">¶</a></h2>548<p>The commands recognized by the debugger are listed below.  Most commands can be549abbreviated to one or two letters as indicated; e.g. <code class="docutils literal notranslate"><span class="pre">h(elp)</span></code> means that550either <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>551or <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 be552separated by whitespace (spaces or tabs).  Optional arguments are enclosed in553square brackets (<code class="docutils literal notranslate"><span class="pre">[]</span></code>) in the command syntax; the square brackets must not be554typed.  Alternatives in the command syntax are separated by a vertical bar555(<code class="docutils literal notranslate"><span class="pre">|</span></code>).</p>556<p>Entering a blank line repeats the last command entered.  Exception: if the last557command 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>558<p>Commands that the debugger doesn’t recognize are assumed to be Python statements559and are executed in the context of the program being debugged.  Python560statements can also be prefixed with an exclamation point (<code class="docutils literal notranslate"><span class="pre">!</span></code>).  This is a561powerful way to inspect the program being debugged; it is even possible to562change a variable or call a function.  When an exception occurs in such a563statement, the exception name is printed but the debugger’s state is not564changed.</p>565<div class="versionchanged">566<p><span class="versionmodified changed">Changed in version 3.13: </span>Expressions/Statements whose prefix is a pdb command are now correctly567identified and executed.</p>568</div>569<p>The debugger supports <a class="reference internal" href="#debugger-aliases"><span class="std std-ref">aliases</span></a>.  Aliases can have570parameters which allows one a certain level of adaptability to the context under571examination.</p>572<p>Multiple commands may be entered on a single line, separated by <code class="docutils literal notranslate"><span class="pre">;;</span></code>.  (A573single <code class="docutils literal notranslate"><span class="pre">;</span></code> is not used as it is the separator for multiple commands in a line574that is passed to the Python parser.)  No intelligence is applied to separating575the commands; the input is split at the first <code class="docutils literal notranslate"><span class="pre">;;</span></code> pair, even if it is in the576middle of a quoted string. A workaround for strings with double semicolons577is 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>578<p>To set a temporary global variable, use a <em>convenience variable</em>. A <em>convenience579variable</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>580sets a global variable <code class="docutils literal notranslate"><span class="pre">$foo</span></code> which you can use in the debugger session.  The581<em>convenience variables</em> are cleared when the program resumes execution so it’s582less likely to interfere with your program compared to using normal variables583like <code class="docutils literal notranslate"><span class="pre">foo</span> <span class="pre">=</span> <span class="pre">1</span></code>.</p>584<p>There are four preset <em>convenience variables</em>:</p>585<ul class="simple">586<li><p><code class="docutils literal notranslate"><span class="pre">$_frame</span></code>: the current frame you are debugging</p></li>587<li><p><code class="docutils literal notranslate"><span class="pre">$_retval</span></code>: the return value if the frame is returning</p></li>588<li><p><code class="docutils literal notranslate"><span class="pre">$_exception</span></code>: the exception if the frame is raising an exception</p></li>589<li><p><code class="docutils literal notranslate"><span class="pre">$_asynctask</span></code>: the asyncio task if pdb stops in an async function</p></li>590</ul>591<div class="versionadded">592<p><span class="versionmodified added">Added in version 3.12: </span>Added the <em>convenience variable</em> feature.</p>593</div>594<div class="versionadded">595<p><span class="versionmodified added">Added in version 3.14: </span>Added the <code class="docutils literal notranslate"><span class="pre">$_asynctask</span></code> convenience variable.</p>596</div>597<p id="index-3">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 current598directory, it is read with <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> encoding and executed as if it had been599typed at the debugger prompt, with the exception that empty lines and lines600starting with <code class="docutils literal notranslate"><span class="pre">#</span></code> are ignored.  This is particularly useful for aliases.  If both601files exist, the one in the home directory is read first and aliases defined there602can be overridden by the local file.</p>603<div class="versionchanged">604<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 as605<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 no606effect.</p>607</div>608<div class="versionchanged">609<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 read610with the system locale encoding.</p>611</div>612<dl class="std pdbcommand">613<dt class="sig sig-object std" id="pdbcommand-help">614<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>615<dd><p>Without argument, print the list of available commands.  With a <em>command</em> as616argument, print help about that command.  <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">pdb</span></code> displays the full617documentation (the docstring of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code> module).  Since the <em>command</em>618argument 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 on619the <code class="docutils literal notranslate"><span class="pre">!</span></code> command.</p>620</dd></dl>621 622<dl class="std pdbcommand">623<dt class="sig sig-object std" id="pdbcommand-where">624<span class="sig-name descname"><span class="pre">w(here)</span></span><span class="sig-prename descclassname"> <span class="pre">[count]</span></span><a class="headerlink" href="#pdbcommand-where" title="Link to this definition">¶</a></dt>625<dd><p>Print a stack trace, with the most recent frame at the bottom.  if <em>count</em>626is 0, print the current frame entry. If <em>count</em> is negative, print the least627recent - <em>count</em> frames. If <em>count</em> is positive, print the most recent628<em>count</em> frames.  An arrow (<code class="docutils literal notranslate"><span class="pre">&gt;</span></code>)629indicates the current frame, which determines the context of most commands.</p>630<div class="versionchanged">631<p><span class="versionmodified changed">Changed in version 3.14: </span><em>count</em> argument is added.</p>632</div>633</dd></dl>634 635<dl class="std pdbcommand">636<dt class="sig sig-object std" id="pdbcommand-down">637<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>638<dd><p>Move the current frame <em>count</em> (default one) levels down in the stack trace639(to a newer frame).</p>640</dd></dl>641 642<dl class="std pdbcommand">643<dt class="sig sig-object std" id="pdbcommand-up">644<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>645<dd><p>Move the current frame <em>count</em> (default one) levels up in the stack trace (to646an older frame).</p>647</dd></dl>648 649<dl class="std pdbcommand">650<dt class="sig sig-object std" id="pdbcommand-break">651<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>652<dd><p>With a <em>lineno</em> argument, set a break at line <em>lineno</em> in the current file.653The line number may be prefixed with a <em>filename</em> and a colon,654to specify a breakpoint in another file (possibly one that hasn’t been loaded655yet).  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>.  Acceptable forms of <em>filename</em>656are <code class="docutils literal notranslate"><span class="pre">/abspath/to/file.py</span></code>, <code class="docutils literal notranslate"><span class="pre">relpath/file.py</span></code>, <code class="docutils literal notranslate"><span class="pre">module</span></code> and657<code class="docutils literal notranslate"><span class="pre">package.module</span></code>.</p>658<p>With a <em>function</em> argument, set a break at the first executable statement within659that function. <em>function</em> can be any expression that evaluates to a function660in the current namespace.</p>661<p>If a second argument is present, it is an expression which must evaluate to662true before the breakpoint is honored.</p>663<p>Without argument, list all breaks, including for each breakpoint, the number664of times that breakpoint has been hit, the current ignore count, and the665associated condition if any.</p>666<p>Each breakpoint is assigned a number to which all the other667breakpoint commands refer.</p>668</dd></dl>669 670<dl class="std pdbcommand">671<dt class="sig sig-object std" id="pdbcommand-tbreak">672<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>673<dd><p>Temporary breakpoint, which is removed automatically when it is first hit.674The 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>675</dd></dl>676 677<dl class="std pdbcommand">678<dt class="sig sig-object std" id="pdbcommand-clear">679<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>680<dd><p>With a <em>filename:lineno</em> argument, clear all the breakpoints at this line.681With a space separated list of breakpoint numbers, clear those breakpoints.682Without argument, clear all breaks (but first ask confirmation).</p>683</dd></dl>684 685<dl class="std pdbcommand">686<dt class="sig sig-object std" id="pdbcommand-disable">687<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>688<dd><p>Disable the breakpoints given as a space separated list of breakpoint689numbers.  Disabling a breakpoint means it cannot cause the program to stop690execution, but unlike clearing a breakpoint, it remains in the list of691breakpoints and can be (re-)enabled.</p>692</dd></dl>693 694<dl class="std pdbcommand">695<dt class="sig sig-object std" id="pdbcommand-enable">696<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>697<dd><p>Enable the breakpoints specified.</p>698</dd></dl>699 700<dl class="std pdbcommand">701<dt class="sig sig-object std" id="pdbcommand-ignore">702<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>703<dd><p>Set the ignore count for the given breakpoint number.  If <em>count</em> is omitted,704the ignore count is set to 0.  A breakpoint becomes active when the ignore705count is zero.  When non-zero, the <em>count</em> is decremented each time the706breakpoint is reached and the breakpoint is not disabled and any associated707condition evaluates to true.</p>708</dd></dl>709 710<dl class="std pdbcommand">711<dt class="sig sig-object std" id="pdbcommand-condition">712<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>713<dd><p>Set a new <em>condition</em> for the breakpoint, an expression which must evaluate714to true before the breakpoint is honored.  If <em>condition</em> is absent, any715existing condition is removed; i.e., the breakpoint is made unconditional.</p>716</dd></dl>717 718<dl class="std pdbcommand">719<dt class="sig sig-object std" id="pdbcommand-commands">720<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>721<dd><p>Specify a list of commands for breakpoint number <em>bpnumber</em>.  The commands722themselves appear on the following lines.  Type a line containing just723<code class="docutils literal notranslate"><span class="pre">end</span></code> to terminate the commands. An example:</p>724<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>725<span class="p">(</span><span class="n">com</span><span class="p">)</span> <span class="n">p</span> <span class="n">some_variable</span>726<span class="p">(</span><span class="n">com</span><span class="p">)</span> <span class="n">end</span>727<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>728</pre></div>729</div>730<p>To remove all commands from a breakpoint, type <code class="docutils literal notranslate"><span class="pre">commands</span></code> and follow it731immediately with <code class="docutils literal notranslate"><span class="pre">end</span></code>; that is, give no commands.</p>732<p>With no <em>bpnumber</em> argument, <code class="docutils literal notranslate"><span class="pre">commands</span></code> refers to the most recently set733breakpoint that still exists.</p>734<p>You can use breakpoint commands to start your program up again.  Simply use735the <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>,736or any other command that resumes execution.</p>737<p>Specifying any command resuming execution738(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>,739<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-until"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">until</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)740terminates the command list (as if741that command was immediately followed by end). This is because any time you742resume execution (even with a simple next or step), you may encounter another743breakpoint—which could have its own command list, leading to ambiguities about744which list to execute.</p>745<p>If the list of commands contains the <code class="docutils literal notranslate"><span class="pre">silent</span></code> command, or a command that746resumes execution, then the breakpoint message containing information about747the frame is not displayed.</p>748<div class="versionchanged">749<p><span class="versionmodified changed">Changed in version 3.14: </span>Frame information will not be displayed if a command that resumes execution750is present in the command list.</p>751</div>752</dd></dl>753 754<dl class="std pdbcommand">755<dt class="sig sig-object std" id="pdbcommand-step">756<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>757<dd><p>Execute the current line, stop at the first possible occasion (either in a758function that is called or on the next line in the current function).</p>759</dd></dl>760 761<dl class="std pdbcommand">762<dt class="sig sig-object std" id="pdbcommand-next">763<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>764<dd><p>Continue execution until the next line in the current function is reached or765it 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> is766that <code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">step</span></code> stops inside a called function, while <code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">next</span></code>767executes called functions at (nearly) full speed, only stopping at the next768line in the current function.)</p>769</dd></dl>770 771<dl class="std pdbcommand">772<dt class="sig sig-object std" id="pdbcommand-until">773<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>774<dd><p>Without argument, continue execution until the line with a number greater775than the current one is reached.</p>776<p>With <em>lineno</em>, continue execution until a line with a number greater or777equal to <em>lineno</em> is reached.  In both cases, also stop when the current frame778returns.</p>779<div class="versionchanged">780<p><span class="versionmodified changed">Changed in version 3.2: </span>Allow giving an explicit line number.</p>781</div>782</dd></dl>783 784<dl class="std pdbcommand">785<dt class="sig sig-object std" id="pdbcommand-return">786<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>787<dd><p>Continue execution until the current function returns.</p>788</dd></dl>789 790<dl class="std pdbcommand">791<dt class="sig sig-object std" id="pdbcommand-continue">792<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>793<dd><p>Continue execution, only stop when a breakpoint is encountered.</p>794</dd></dl>795 796<dl class="std pdbcommand">797<dt class="sig sig-object std" id="pdbcommand-jump">798<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>799<dd><p>Set the next line that will be executed.  Only available in the bottom-most800frame.  This lets you jump back and execute code again, or jump forward to801skip code that you don’t want to run.</p>802<p>It should be noted that not all jumps are allowed – for instance it is not803possible 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 a804<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>805</dd></dl>806 807<dl class="std pdbcommand">808<dt class="sig sig-object std" id="pdbcommand-list">809<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>810<dd><p>List source code for the current file.  Without arguments, list 11 lines811around the current line or continue the previous listing.  With <code class="docutils literal notranslate"><span class="pre">.</span></code> as812argument, list 11 lines around the current line.  With one argument,813list 11 lines around at that line.  With two arguments, list the given range;814if the second argument is less than the first, it is interpreted as a count.</p>815<p>The current line in the current frame is indicated by <code class="docutils literal notranslate"><span class="pre">-&gt;</span></code>.  If an816exception is being debugged, the line where the exception was originally817raised or propagated is indicated by <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code>, if it differs from the current818line.</p>819<div class="versionchanged">820<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>821</div>822</dd></dl>823 824<dl class="std pdbcommand">825<dt class="sig sig-object std" id="pdbcommand-ll">826<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>827<dd><p>List all source code for the current function or frame.  Interesting lines828are 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>829<div class="versionadded">830<p><span class="versionmodified added">Added in version 3.2.</span></p>831</div>832</dd></dl>833 834<dl class="std pdbcommand">835<dt class="sig sig-object std" id="pdbcommand-args">836<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>837<dd><p>Print the arguments of the current function and their current values.</p>838</dd></dl>839 840<dl class="std pdbcommand">841<dt class="sig sig-object std" id="pdbcommand-p">842<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>843<dd><p>Evaluate <em>expression</em> in the current context and print its value.</p>844<div class="admonition note">845<p class="admonition-title">Note</p>846<p><code class="docutils literal notranslate"><span class="pre">print()</span></code> can also be used, but is not a debugger command — this executes the847Python <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>848</div>849</dd></dl>850 851<dl class="std pdbcommand">852<dt class="sig sig-object std" id="pdbcommand-pp">853<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>854<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> is855pretty-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>856</dd></dl>857 858<dl class="std pdbcommand">859<dt class="sig sig-object std" id="pdbcommand-whatis">860<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>861<dd><p>Print the type of <em>expression</em>.</p>862</dd></dl>863 864<dl class="std pdbcommand">865<dt class="sig sig-object std" id="pdbcommand-source">866<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>867<dd><p>Try to get source code of <em>expression</em> and display it.</p>868<div class="versionadded">869<p><span class="versionmodified added">Added in version 3.2.</span></p>870</div>871</dd></dl>872 873<dl class="std pdbcommand">874<dt class="sig sig-object std" id="pdbcommand-display">875<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>876<dd><p>Display the value of <em>expression</em> if it changed, each time execution stops877in the current frame.</p>878<p>Without <em>expression</em>, list all display expressions for the current frame.</p>879<div class="admonition note">880<p class="admonition-title">Note</p>881<p>Display evaluates <em>expression</em> and compares to the result of the previous882evaluation of <em>expression</em>, so when the result is mutable, display may not883be able to pick up the changes.</p>884</div>885<p>Example:</p>886<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">lst</span> <span class="o">=</span> <span class="p">[]</span>887<span class="nb">breakpoint</span><span class="p">()</span>888<span class="k">pass</span>889<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>890<span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>891</pre></div>892</div>893<p>Display won’t realize <code class="docutils literal notranslate"><span class="pre">lst</span></code> has been changed because the result of evaluation894is modified in place by <code class="docutils literal notranslate"><span class="pre">lst.append(1)</span></code> before being compared:</p>895<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>896<span class="o">-&gt;</span> <span class="k">pass</span>897<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">display</span> <span class="n">lst</span>898<span class="n">display</span> <span class="n">lst</span><span class="p">:</span> <span class="p">[]</span>899<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>900<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>901<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>902<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>903<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>904<span class="o">-&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>905<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>906</pre></div>907</div>908<p>You can do some tricks with copy mechanism to make it work:</p>909<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>910<span class="o">-&gt;</span> <span class="k">pass</span>911<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>912<span class="n">display</span> <span class="n">lst</span><span class="p">[:]:</span> <span class="p">[]</span>913<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>914<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>915<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>916<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">n</span>917<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>918<span class="o">-&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span>919<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>920<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span>921</pre></div>922</div>923<div class="versionadded">924<p><span class="versionmodified added">Added in version 3.2.</span></p>925</div>926</dd></dl>927 928<dl class="std pdbcommand">929<dt class="sig sig-object std" id="pdbcommand-undisplay">930<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>931<dd><p>Do not display <em>expression</em> anymore in the current frame.  Without932<em>expression</em>, clear all display expressions for the current frame.</p>933<div class="versionadded">934<p><span class="versionmodified added">Added in version 3.2.</span></p>935</div>936</dd></dl>937 938<dl class="std pdbcommand">939<dt class="sig sig-object std" id="pdbcommand-interact">940<span class="sig-name descname"><span class="pre">interact</span></span><a class="headerlink" href="#pdbcommand-interact" title="Link to this definition">¶</a></dt>941<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) in a new942global namespace initialised from the local and global namespaces for the943current scope. Use <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">quit()</span></code> to exit the interpreter and944return to the debugger.</p>945<div class="admonition note">946<p class="admonition-title">Note</p>947<p>As <code class="docutils literal notranslate"><span class="pre">interact</span></code> creates a new dedicated namespace for code execution,948assignments to variables will not affect the original namespaces.949However, modifications to any referenced mutable objects will be reflected950in the original namespaces as usual.</p>951</div>952<div class="versionadded">953<p><span class="versionmodified added">Added in version 3.2.</span></p>954</div>955<div class="versionchanged">956<p><span class="versionmodified changed">Changed in version 3.13: </span><code class="docutils literal notranslate"><span class="pre">exit()</span></code> and <code class="docutils literal notranslate"><span class="pre">quit()</span></code> can be used to exit the <a class="reference internal" href="#pdbcommand-interact"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">interact</span></code></a>957command.</p>958</div>959<div class="versionchanged">960<p><span class="versionmodified changed">Changed in version 3.13: </span><a class="reference internal" href="#pdbcommand-interact"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">interact</span></code></a> directs its output to the debugger’s961output channel rather than <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a>.</p>962</div>963</dd></dl>964 965<dl class="std pdbcommand" id="debugger-aliases">966<dt class="sig sig-object std" id="pdbcommand-alias">967<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>968<dd><p>Create an alias called <em>name</em> that executes <em>command</em>.  The <em>command</em> must969<em>not</em> be enclosed in quotes.  Replaceable parameters can be indicated by970<code class="docutils literal notranslate"><span class="pre">%1</span></code>, <code class="docutils literal notranslate"><span class="pre">%2</span></code>, … and <code class="docutils literal notranslate"><span class="pre">%9</span></code>, while <code class="docutils literal notranslate"><span class="pre">%*</span></code> is replaced by all the parameters.971If <em>command</em> is omitted, the current alias for <em>name</em> is shown. If no972arguments are given, all aliases are listed.</p>973<p>Aliases may be nested and can contain anything that can be legally typed at974the pdb prompt.  Note that internal pdb commands <em>can</em> be overridden by975aliases.  Such a command is then hidden until the alias is removed.  Aliasing976is recursively applied to the first word of the command line; all other words977in the line are left alone.</p>978<p>As an example, here are two useful aliases (especially when placed in the979<code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> file):</p>980<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Print instance variables (usage &quot;pi classInst&quot;)</span>981<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>982<span class="c1"># Print instance variables in self</span>983<span class="n">alias</span> <span class="n">ps</span> <span class="n">pi</span> <span class="bp">self</span>984</pre></div>985</div>986</dd></dl>987 988<dl class="std pdbcommand">989<dt class="sig sig-object std" id="pdbcommand-unalias">990<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>991<dd><p>Delete the specified alias <em>name</em>.</p>992</dd></dl>993 994<dl class="std pdbcommand">995<dt class="sig sig-object std" id="pdbcommand-0">996<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>997<dd><p>Execute the (one-line) <em>statement</em> in the context of the current stack frame.998The exclamation point can be omitted unless the first word of the statement999resembles a debugger command, e.g.:</p>1000<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(Pdb) ! n=421001(Pdb)1002</pre></div>1003</div>1004<p>To set a global variable, you can prefix the assignment command with a1005<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>1006<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(Pdb) global list_options; list_options = [&#39;-l&#39;]1007(Pdb)1008</pre></div>1009</div>1010</dd></dl>1011 1012<dl class="std pdbcommand">1013<dt class="sig sig-object std" id="pdbcommand-run">1014<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>1015<dt class="sig sig-object std" id="pdbcommand-restart">1016<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>1017<dd><p>Restart the debugged Python program.  If <em>args</em> is supplied, it is split1018with <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>.1019History, breakpoints, actions and debugger options are preserved.1020<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>1021<div class="versionchanged">1022<p><span class="versionmodified changed">Changed in version 3.14: </span><a class="reference internal" href="#pdbcommand-run"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">run</span></code></a> and <a class="reference internal" href="#pdbcommand-restart"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">restart</span></code></a> commands are disabled when the1023debugger is invoked in <code class="docutils literal notranslate"><span class="pre">'inline'</span></code> mode.</p>1024</div>1025</dd></dl>1026 1027<dl class="std pdbcommand">1028<dt class="sig sig-object std" id="pdbcommand-quit">1029<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>1030<dd><p>Quit from the debugger.  The program being executed is aborted.1031An end-of-file input is equivalent to <a class="reference internal" href="#pdbcommand-quit"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">quit</span></code></a>.</p>1032<p>A confirmation prompt will be shown if the debugger is invoked in1033<code class="docutils literal notranslate"><span class="pre">'inline'</span></code> mode. Either <code class="docutils literal notranslate"><span class="pre">y</span></code>, <code class="docutils literal notranslate"><span class="pre">Y</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;Enter&gt;</span></code> or <code class="docutils literal notranslate"><span class="pre">EOF</span></code>1034will confirm the quit.</p>1035<div class="versionchanged">1036<p><span class="versionmodified changed">Changed in version 3.14: </span>A confirmation prompt will be shown if the debugger is invoked in1037<code class="docutils literal notranslate"><span class="pre">'inline'</span></code> mode. After the confirmation, the debugger will call1038<a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> immediately, instead of raising <a class="reference internal" href="bdb.html#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">bdb.BdbQuit</span></code></a>1039in the next trace event.</p>1040</div>1041</dd></dl>1042 1043<dl class="std pdbcommand">1044<dt class="sig sig-object std" id="pdbcommand-debug">1045<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>1046<dd><p>Enter a recursive debugger that steps through <em>code</em>1047(which is an arbitrary expression or statement to be1048executed in the current environment).</p>1049</dd></dl>1050 1051<dl class="std pdbcommand">1052<dt class="sig sig-object std" id="pdbcommand-retval">1053<span class="sig-name descname"><span class="pre">retval</span></span><a class="headerlink" href="#pdbcommand-retval" title="Link to this definition">¶</a></dt>1054<dd><p>Print the return value for the last return of the current function.</p>1055</dd></dl>1056 1057<dl class="std pdbcommand">1058<dt class="sig sig-object std" id="pdbcommand-exceptions">1059<span class="sig-name descname"><span class="pre">exceptions</span></span><span class="sig-prename descclassname"> <span class="pre">[excnumber]</span></span><a class="headerlink" href="#pdbcommand-exceptions" title="Link to this definition">¶</a></dt>1060<dd><p>List or jump between chained exceptions.</p>1061<p>When using <code class="docutils literal notranslate"><span class="pre">pdb.pm()</span></code>  or <code class="docutils literal notranslate"><span class="pre">Pdb.post_mortem(...)</span></code> with a chained exception1062instead of a traceback, it allows the user to move between the1063chained exceptions using <code class="docutils literal notranslate"><span class="pre">exceptions</span></code> command to list exceptions, and1064<code class="docutils literal notranslate"><span class="pre">exceptions</span> <span class="pre">&lt;number&gt;</span></code> to switch to that exception.</p>1065<p>Example:</p>1066<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">out</span><span class="p">():</span>1067    <span class="k">try</span><span class="p">:</span>1068        <span class="n">middle</span><span class="p">()</span>1069    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>1070        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;reraise middle() error&quot;</span><span class="p">)</span> <span class="kn">from</span><span class="w"> </span><span class="nn">e</span>1071 1072<span class="k">def</span><span class="w"> </span><span class="nf">middle</span><span class="p">():</span>1073    <span class="k">try</span><span class="p">:</span>1074        <span class="k">return</span> <span class="n">inner</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>1075    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>1076        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Middle fail&quot;</span><span class="p">)</span>1077 1078<span class="k">def</span><span class="w"> </span><span class="nf">inner</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>1079    <span class="mi">1</span> <span class="o">/</span> <span class="n">x</span>1080 1081 <span class="n">out</span><span class="p">()</span>1082</pre></div>1083</div>1084<p>calling <code class="docutils literal notranslate"><span class="pre">pdb.pm()</span></code> will allow to move between exceptions:</p>1085<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">5</span><span class="p">)</span><span class="n">out</span><span class="p">()</span>1086<span class="o">-&gt;</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;reraise middle() error&quot;</span><span class="p">)</span> <span class="kn">from</span><span class="w"> </span><span class="nn">e</span>1087 1088<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">exceptions</span>1089  <span class="mi">0</span> <span class="ne">ZeroDivisionError</span><span class="p">(</span><span class="s1">&#39;division by zero&#39;</span><span class="p">)</span>1090  <span class="mi">1</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Middle fail&#39;</span><span class="p">)</span>1091<span class="o">&gt;</span> <span class="mi">2</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;reraise middle() error&#39;</span><span class="p">)</span>1092 1093<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">exceptions</span> <span class="mi">0</span>1094<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">16</span><span class="p">)</span><span class="n">inner</span><span class="p">()</span>1095<span class="o">-&gt;</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">x</span>1096 1097<span class="p">(</span><span class="n">Pdb</span><span class="p">)</span> <span class="n">up</span>1098<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">10</span><span class="p">)</span><span class="n">middle</span><span class="p">()</span>1099<span class="o">-&gt;</span> <span class="k">return</span> <span class="n">inner</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>1100</pre></div>1101</div>1102<div class="versionadded">1103<p><span class="versionmodified added">Added in version 3.13.</span></p>1104</div>1105</dd></dl>1106 1107<p class="rubric">Footnotes</p>1108<aside class="footnote-list brackets">1109<aside class="footnote brackets" id="id3" role="doc-footnote">1110<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>1111<p>Whether a frame is considered to originate in a certain module1112is determined by the <code class="docutils literal notranslate"><span class="pre">__name__</span></code> in the frame globals.</p>1113</aside>1114</aside>1115</section>1116</section>1117 1118 1119            <div class="clearer"></div>1120          </div>1121        </div>1122      </div>1123      <div class="sphinxsidebar" role="navigation" aria-label="Main">1124        <div class="sphinxsidebarwrapper">1125  <div>1126    <h3><a href="../contents.html">Table of Contents</a></h3>1127    <ul>1128<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>1129<li><a class="reference internal" href="#command-line-interface">Command-line interface</a></li>1130<li><a class="reference internal" href="#debugger-commands">Debugger commands</a></li>1131</ul>1132</li>1133</ul>1134 1135  </div>1136  <div>1137    <h4>Previous topic</h4>1138    <p class="topless"><a href="faulthandler.html"1139                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>1140  </div>1141  <div>1142    <h4>Next topic</h4>1143    <p class="topless"><a href="profiling.html"1144                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling</span></code> — Python profilers</a></p>1145  </div>1146  <script>1147    document.addEventListener('DOMContentLoaded', () => {1148        const title = document.querySelector('meta[property="og:title"]').content;1149        const elements = document.querySelectorAll('.improvepage');1150        const pageurl = window.location.href.split('?')[0];1151        elements.forEach(element => {1152            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));1153            url.searchParams.set('pagetitle', title);1154            url.searchParams.set('pageurl', pageurl);1155            url.searchParams.set('pagesource', "library/pdb.rst");1156            element.href = url.toString();1157        });1158    });1159  </script>1160  <div role="note" aria-label="source link">1161    <h3>This page</h3>1162    <ul class="this-page-menu">1163      <li><a href="../bugs.html">Report a bug</a></li>1164      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>1165      <li>1166        <a href="https://github.com/python/cpython/blob/main/Doc/library/pdb.rst?plain=1"1167            rel="nofollow">Show source1168        </a>1169      </li>1170      1171    </ul>1172  </div>1173        </div>1174<div id="sidebarbutton" title="Collapse sidebar">1175<span>«</span>1176</div>1177 1178      </div>1179      <div class="clearer"></div>1180    </div>  1181    <div class="related" role="navigation" aria-label="Related">1182      <h3>Navigation</h3>1183      <ul>1184        <li class="right" style="margin-right: 10px">1185          <a href="../genindex.html" title="General Index"1186             >index</a></li>1187        <li class="right" >1188          <a href="../py-modindex.html" title="Python Module Index"1189             >modules</a> |</li>1190        <li class="right" >1191          <a href="profiling.html" title="profiling — Python profilers"1192             >next</a> |</li>1193        <li class="right" >1194          <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"1195             >previous</a> |</li>1196 1197          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>1198          <li><a href="https://www.python.org/">Python</a> &#187;</li>1199          <li class="switchers">1200            <div class="language_switcher_placeholder"></div>

Showing the first 1,200 of 1263 lines. Download the file for the rest.