gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

826 lines
69KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="bdb — Debugger framework" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/bdb.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/bdb.py The bdb module handles basic debugger functions, like setting breakpoints or managing execution via the debugger. The following exception is defined: The bdb module also def..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/bdb.py The bdb module handles basic debugger functions, like setting breakpoints or managing execution via the debugger. The following exception is defined: The bdb module also def..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>bdb — Debugger framework &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="faulthandler — Dump the Python traceback" href="faulthandler.html" />
  33. <link rel="prev" title="Audit events table" href="audit_events.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/bdb.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="audit_events.html"
  85. title="previous chapter">Audit events table</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="faulthandler.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/bdb.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="audit_events.html" title="Audit events table"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-2"><a href="debug.html" accesskey="U">Debugging and Profiling</a> &#187;</li>
  134. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code> — Debugger framework</a></li>
  135. <li class="right">
  136. <div class="inline-search" role="search">
  137. <form class="inline-search" action="../search.html" method="get">
  138. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  139. <input type="submit" value="Go" />
  140. </form>
  141. </div>
  142. |
  143. </li>
  144. <li class="right">
  145. <label class="theme-selector-label">
  146. Theme
  147. <select class="theme-selector" oninput="activateTheme(this.value)">
  148. <option value="auto" selected>Auto</option>
  149. <option value="light">Light</option>
  150. <option value="dark">Dark</option>
  151. </select>
  152. </label> |</li>
  153. </ul>
  154. </div>
  155. <div class="document">
  156. <div class="documentwrapper">
  157. <div class="bodywrapper">
  158. <div class="body" role="main">
  159. <section id="module-bdb">
  160. <span id="bdb-debugger-framework"></span><h1><a class="reference internal" href="#module-bdb" title="bdb: Debugger framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code></a> — Debugger framework<a class="headerlink" href="#module-bdb" title="Link to this heading">¶</a></h1>
  161. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/bdb.py">Lib/bdb.py</a></p>
  162. <hr class="docutils" />
  163. <p>The <a class="reference internal" href="#module-bdb" title="bdb: Debugger framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code></a> module handles basic debugger functions, like setting breakpoints
  164. or managing execution via the debugger.</p>
  165. <p>The following exception is defined:</p>
  166. <dl class="py exception">
  167. <dt class="sig sig-object py" id="bdb.BdbQuit">
  168. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">bdb.</span></span><span class="sig-name descname"><span class="pre">BdbQuit</span></span><a class="headerlink" href="#bdb.BdbQuit" title="Link to this definition">¶</a></dt>
  169. <dd><p>Exception raised by the <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bdb</span></code></a> class for quitting the debugger.</p>
  170. </dd></dl>
  171. <p>The <a class="reference internal" href="#module-bdb" title="bdb: Debugger framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code></a> module also defines two classes:</p>
  172. <dl class="py class">
  173. <dt class="sig sig-object py" id="bdb.Breakpoint">
  174. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">bdb.</span></span><span class="sig-name descname"><span class="pre">Breakpoint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">self</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">line</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">temporary</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">cond</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">funcname</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="#bdb.Breakpoint" title="Link to this definition">¶</a></dt>
  175. <dd><p>This class implements temporary breakpoints, ignore counts, disabling and
  176. (re-)enabling, and conditionals.</p>
  177. <p>Breakpoints are indexed by number through a list called <a class="reference internal" href="#bdb.Breakpoint.bpbynumber" title="bdb.Breakpoint.bpbynumber"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bpbynumber</span></code></a>
  178. and by <code class="docutils literal notranslate"><span class="pre">(file,</span> <span class="pre">line)</span></code> pairs through <a class="reference internal" href="#bdb.Breakpoint.bplist" title="bdb.Breakpoint.bplist"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bplist</span></code></a>. The former points to
  179. a single instance of class <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a>. The latter points to a list
  180. of such instances since there may be more than one breakpoint per line.</p>
  181. <p>When creating a breakpoint, its associated <a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span> <span class="pre">name</span></code></a> should
  182. be in canonical form. If a <a class="reference internal" href="#bdb.Breakpoint.funcname" title="bdb.Breakpoint.funcname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">funcname</span></code></a> is defined, a breakpoint
  183. <a class="reference internal" href="#bdb.Breakpoint.hits" title="bdb.Breakpoint.hits"><code class="xref py py-attr docutils literal notranslate"><span class="pre">hit</span></code></a> will be counted when the first line of that function is
  184. executed. A <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code class="xref py py-attr docutils literal notranslate"><span class="pre">conditional</span></code></a> breakpoint always counts a
  185. <a class="reference internal" href="#bdb.Breakpoint.hits" title="bdb.Breakpoint.hits"><code class="xref py py-attr docutils literal notranslate"><span class="pre">hit</span></code></a>.</p>
  186. <p><a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> instances have the following methods:</p>
  187. <dl class="py method">
  188. <dt class="sig sig-object py" id="bdb.Breakpoint.deleteMe">
  189. <span class="sig-name descname"><span class="pre">deleteMe</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Breakpoint.deleteMe" title="Link to this definition">¶</a></dt>
  190. <dd><p>Delete the breakpoint from the list associated to a file/line. If it is
  191. the last breakpoint in that position, it also deletes the entry for the
  192. file/line.</p>
  193. </dd></dl>
  194. <dl class="py method">
  195. <dt class="sig sig-object py" id="bdb.Breakpoint.enable">
  196. <span class="sig-name descname"><span class="pre">enable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Breakpoint.enable" title="Link to this definition">¶</a></dt>
  197. <dd><p>Mark the breakpoint as enabled.</p>
  198. </dd></dl>
  199. <dl class="py method">
  200. <dt class="sig sig-object py" id="bdb.Breakpoint.disable">
  201. <span class="sig-name descname"><span class="pre">disable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Breakpoint.disable" title="Link to this definition">¶</a></dt>
  202. <dd><p>Mark the breakpoint as disabled.</p>
  203. </dd></dl>
  204. <dl class="py method">
  205. <dt class="sig sig-object py" id="bdb.Breakpoint.bpformat">
  206. <span class="sig-name descname"><span class="pre">bpformat</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Breakpoint.bpformat" title="Link to this definition">¶</a></dt>
  207. <dd><p>Return a string with all the information about the breakpoint, nicely
  208. formatted:</p>
  209. <ul class="simple">
  210. <li><p>Breakpoint number.</p></li>
  211. <li><p>Temporary status (del or keep).</p></li>
  212. <li><p>File/line position.</p></li>
  213. <li><p>Break condition.</p></li>
  214. <li><p>Number of times to ignore.</p></li>
  215. <li><p>Number of times hit.</p></li>
  216. </ul>
  217. <div class="versionadded">
  218. <p><span class="versionmodified added">New in version 3.2.</span></p>
  219. </div>
  220. </dd></dl>
  221. <dl class="py method">
  222. <dt class="sig sig-object py" id="bdb.Breakpoint.bpprint">
  223. <span class="sig-name descname"><span class="pre">bpprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">out</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="#bdb.Breakpoint.bpprint" title="Link to this definition">¶</a></dt>
  224. <dd><p>Print the output of <a class="reference internal" href="#bdb.Breakpoint.bpformat" title="bdb.Breakpoint.bpformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bpformat()</span></code></a> to the file <em>out</em>, or if it is
  225. <code class="docutils literal notranslate"><span class="pre">None</span></code>, to standard output.</p>
  226. </dd></dl>
  227. <p><a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> instances have the following attributes:</p>
  228. <dl class="py attribute">
  229. <dt class="sig sig-object py" id="bdb.Breakpoint.file">
  230. <span class="sig-name descname"><span class="pre">file</span></span><a class="headerlink" href="#bdb.Breakpoint.file" title="Link to this definition">¶</a></dt>
  231. <dd><p>File name of the <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a>.</p>
  232. </dd></dl>
  233. <dl class="py attribute">
  234. <dt class="sig sig-object py" id="bdb.Breakpoint.line">
  235. <span class="sig-name descname"><span class="pre">line</span></span><a class="headerlink" href="#bdb.Breakpoint.line" title="Link to this definition">¶</a></dt>
  236. <dd><p>Line number of the <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> within <a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span></code></a>.</p>
  237. </dd></dl>
  238. <dl class="py attribute">
  239. <dt class="sig sig-object py" id="bdb.Breakpoint.temporary">
  240. <span class="sig-name descname"><span class="pre">temporary</span></span><a class="headerlink" href="#bdb.Breakpoint.temporary" title="Link to this definition">¶</a></dt>
  241. <dd><p>True if a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> at (file, line) is temporary.</p>
  242. </dd></dl>
  243. <dl class="py attribute">
  244. <dt class="sig sig-object py" id="bdb.Breakpoint.cond">
  245. <span class="sig-name descname"><span class="pre">cond</span></span><a class="headerlink" href="#bdb.Breakpoint.cond" title="Link to this definition">¶</a></dt>
  246. <dd><p>Condition for evaluating a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> at (file, line).</p>
  247. </dd></dl>
  248. <dl class="py attribute">
  249. <dt class="sig sig-object py" id="bdb.Breakpoint.funcname">
  250. <span class="sig-name descname"><span class="pre">funcname</span></span><a class="headerlink" href="#bdb.Breakpoint.funcname" title="Link to this definition">¶</a></dt>
  251. <dd><p>Function name that defines whether a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> is hit upon
  252. entering the function.</p>
  253. </dd></dl>
  254. <dl class="py attribute">
  255. <dt class="sig sig-object py" id="bdb.Breakpoint.enabled">
  256. <span class="sig-name descname"><span class="pre">enabled</span></span><a class="headerlink" href="#bdb.Breakpoint.enabled" title="Link to this definition">¶</a></dt>
  257. <dd><p>True if <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> is enabled.</p>
  258. </dd></dl>
  259. <dl class="py attribute">
  260. <dt class="sig sig-object py" id="bdb.Breakpoint.bpbynumber">
  261. <span class="sig-name descname"><span class="pre">bpbynumber</span></span><a class="headerlink" href="#bdb.Breakpoint.bpbynumber" title="Link to this definition">¶</a></dt>
  262. <dd><p>Numeric index for a single instance of a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a>.</p>
  263. </dd></dl>
  264. <dl class="py attribute">
  265. <dt class="sig sig-object py" id="bdb.Breakpoint.bplist">
  266. <span class="sig-name descname"><span class="pre">bplist</span></span><a class="headerlink" href="#bdb.Breakpoint.bplist" title="Link to this definition">¶</a></dt>
  267. <dd><p>Dictionary of <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> instances indexed by
  268. (<a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span></code></a>, <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code class="xref py py-attr docutils literal notranslate"><span class="pre">line</span></code></a>) tuples.</p>
  269. </dd></dl>
  270. <dl class="py attribute">
  271. <dt class="sig sig-object py" id="bdb.Breakpoint.ignore">
  272. <span class="sig-name descname"><span class="pre">ignore</span></span><a class="headerlink" href="#bdb.Breakpoint.ignore" title="Link to this definition">¶</a></dt>
  273. <dd><p>Number of times to ignore a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a>.</p>
  274. </dd></dl>
  275. <dl class="py attribute">
  276. <dt class="sig sig-object py" id="bdb.Breakpoint.hits">
  277. <span class="sig-name descname"><span class="pre">hits</span></span><a class="headerlink" href="#bdb.Breakpoint.hits" title="Link to this definition">¶</a></dt>
  278. <dd><p>Count of the number of times a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> has been hit.</p>
  279. </dd></dl>
  280. </dd></dl>
  281. <dl class="py class">
  282. <dt class="sig sig-object py" id="bdb.Bdb">
  283. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">bdb.</span></span><span class="sig-name descname"><span class="pre">Bdb</span></span><span class="sig-paren">(</span><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><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb" title="Link to this definition">¶</a></dt>
  284. <dd><p>The <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bdb</span></code></a> class acts as a generic Python debugger base class.</p>
  285. <p>This class takes care of the details of the trace facility; a derived class
  286. should implement user interaction. The standard debugger class
  287. (<a class="reference internal" href="pdb.html#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">pdb.Pdb</span></code></a>) is an example.</p>
  288. <p>The <em>skip</em> argument, if given, must be an iterable of glob-style
  289. module name patterns. The debugger will not step into frames that
  290. originate in a module that matches one of these patterns. Whether a
  291. frame is considered to originate in a certain module is determined
  292. by the <code class="docutils literal notranslate"><span class="pre">__name__</span></code> in the frame globals.</p>
  293. <div class="versionchanged">
  294. <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <em>skip</em> parameter.</p>
  295. </div>
  296. <p>The following methods of <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bdb</span></code></a> normally don’t need to be overridden.</p>
  297. <dl class="py method">
  298. <dt class="sig sig-object py" id="bdb.Bdb.canonic">
  299. <span class="sig-name descname"><span class="pre">canonic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.canonic" title="Link to this definition">¶</a></dt>
  300. <dd><p>Return canonical form of <em>filename</em>.</p>
  301. <p>For real file names, the canonical form is an operating-system-dependent,
  302. <a class="reference internal" href="os.path.html#os.path.normcase" title="os.path.normcase"><code class="xref py py-func docutils literal notranslate"><span class="pre">case-normalized</span></code></a> <a class="reference internal" href="os.path.html#os.path.abspath" title="os.path.abspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">absolute</span> <span class="pre">path</span></code></a>. A <em>filename</em> with angle brackets, such as <code class="docutils literal notranslate"><span class="pre">&quot;&lt;stdin&gt;&quot;</span></code>
  303. generated in interactive mode, is returned unchanged.</p>
  304. </dd></dl>
  305. <dl class="py method">
  306. <dt class="sig sig-object py" id="bdb.Bdb.reset">
  307. <span class="sig-name descname"><span class="pre">reset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.reset" title="Link to this definition">¶</a></dt>
  308. <dd><p>Set the <code class="xref py py-attr docutils literal notranslate"><span class="pre">botframe</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">stopframe</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">returnframe</span></code> and
  309. <a class="reference internal" href="#bdb.Bdb.set_quit" title="bdb.Bdb.set_quit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code></a> attributes with values ready to start debugging.</p>
  310. </dd></dl>
  311. <dl class="py method">
  312. <dt class="sig sig-object py" id="bdb.Bdb.trace_dispatch">
  313. <span class="sig-name descname"><span class="pre">trace_dispatch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">event</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.trace_dispatch" title="Link to this definition">¶</a></dt>
  314. <dd><p>This function is installed as the trace function of debugged frames. Its
  315. return value is the new trace function (in most cases, that is, itself).</p>
  316. <p>The default implementation decides how to dispatch a frame, depending on
  317. the type of event (passed as a string) that is about to be executed.
  318. <em>event</em> can be one of the following:</p>
  319. <ul class="simple">
  320. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;line&quot;</span></code>: A new line of code is going to be executed.</p></li>
  321. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;call&quot;</span></code>: A function is about to be called, or another code block
  322. entered.</p></li>
  323. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;return&quot;</span></code>: A function or other code block is about to return.</p></li>
  324. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;exception&quot;</span></code>: An exception has occurred.</p></li>
  325. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;c_call&quot;</span></code>: A C function is about to be called.</p></li>
  326. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;c_return&quot;</span></code>: A C function has returned.</p></li>
  327. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;c_exception&quot;</span></code>: A C function has raised an exception.</p></li>
  328. </ul>
  329. <p>For the Python events, specialized functions (see below) are called. For
  330. the C events, no action is taken.</p>
  331. <p>The <em>arg</em> parameter depends on the previous event.</p>
  332. <p>See the documentation for <a class="reference internal" href="sys.html#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.settrace()</span></code></a> for more information on the
  333. trace function. For more information on code and frame objects, refer to
  334. <a class="reference internal" href="../reference/datamodel.html#types"><span class="std std-ref">The standard type hierarchy</span></a>.</p>
  335. </dd></dl>
  336. <dl class="py method">
  337. <dt class="sig sig-object py" id="bdb.Bdb.dispatch_line">
  338. <span class="sig-name descname"><span class="pre">dispatch_line</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.dispatch_line" title="Link to this definition">¶</a></dt>
  339. <dd><p>If the debugger should stop on the current line, invoke the
  340. <a class="reference internal" href="#bdb.Bdb.user_line" title="bdb.Bdb.user_line"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_line()</span></code></a> method (which should be overridden in subclasses).
  341. Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BdbQuit</span></code></a> exception if the <a class="reference internal" href="#bdb.Bdb.set_quit" title="bdb.Bdb.set_quit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code></a> flag is set
  342. (which can be set from <a class="reference internal" href="#bdb.Bdb.user_line" title="bdb.Bdb.user_line"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_line()</span></code></a>). Return a reference to the
  343. <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_dispatch()</span></code></a> method for further tracing in that scope.</p>
  344. </dd></dl>
  345. <dl class="py method">
  346. <dt class="sig sig-object py" id="bdb.Bdb.dispatch_call">
  347. <span class="sig-name descname"><span class="pre">dispatch_call</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.dispatch_call" title="Link to this definition">¶</a></dt>
  348. <dd><p>If the debugger should stop on this function call, invoke the
  349. <a class="reference internal" href="#bdb.Bdb.user_call" title="bdb.Bdb.user_call"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_call()</span></code></a> method (which should be overridden in subclasses).
  350. Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BdbQuit</span></code></a> exception if the <a class="reference internal" href="#bdb.Bdb.set_quit" title="bdb.Bdb.set_quit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code></a> flag is set
  351. (which can be set from <a class="reference internal" href="#bdb.Bdb.user_call" title="bdb.Bdb.user_call"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_call()</span></code></a>). Return a reference to the
  352. <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_dispatch()</span></code></a> method for further tracing in that scope.</p>
  353. </dd></dl>
  354. <dl class="py method">
  355. <dt class="sig sig-object py" id="bdb.Bdb.dispatch_return">
  356. <span class="sig-name descname"><span class="pre">dispatch_return</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.dispatch_return" title="Link to this definition">¶</a></dt>
  357. <dd><p>If the debugger should stop on this function return, invoke the
  358. <a class="reference internal" href="#bdb.Bdb.user_return" title="bdb.Bdb.user_return"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_return()</span></code></a> method (which should be overridden in subclasses).
  359. Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BdbQuit</span></code></a> exception if the <a class="reference internal" href="#bdb.Bdb.set_quit" title="bdb.Bdb.set_quit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code></a> flag is set
  360. (which can be set from <a class="reference internal" href="#bdb.Bdb.user_return" title="bdb.Bdb.user_return"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_return()</span></code></a>). Return a reference to the
  361. <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_dispatch()</span></code></a> method for further tracing in that scope.</p>
  362. </dd></dl>
  363. <dl class="py method">
  364. <dt class="sig sig-object py" id="bdb.Bdb.dispatch_exception">
  365. <span class="sig-name descname"><span class="pre">dispatch_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.dispatch_exception" title="Link to this definition">¶</a></dt>
  366. <dd><p>If the debugger should stop at this exception, invokes the
  367. <a class="reference internal" href="#bdb.Bdb.user_exception" title="bdb.Bdb.user_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_exception()</span></code></a> method (which should be overridden in subclasses).
  368. Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BdbQuit</span></code></a> exception if the <a class="reference internal" href="#bdb.Bdb.set_quit" title="bdb.Bdb.set_quit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code></a> flag is set
  369. (which can be set from <a class="reference internal" href="#bdb.Bdb.user_exception" title="bdb.Bdb.user_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">user_exception()</span></code></a>). Return a reference to the
  370. <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_dispatch()</span></code></a> method for further tracing in that scope.</p>
  371. </dd></dl>
  372. <p>Normally derived classes don’t override the following methods, but they may
  373. if they want to redefine the definition of stopping and breakpoints.</p>
  374. <dl class="py method">
  375. <dt class="sig sig-object py" id="bdb.Bdb.is_skipped_line">
  376. <span class="sig-name descname"><span class="pre">is_skipped_line</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">module_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.is_skipped_line" title="Link to this definition">¶</a></dt>
  377. <dd><p>Return True if <em>module_name</em> matches any skip pattern.</p>
  378. </dd></dl>
  379. <dl class="py method">
  380. <dt class="sig sig-object py" id="bdb.Bdb.stop_here">
  381. <span class="sig-name descname"><span class="pre">stop_here</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.stop_here" title="Link to this definition">¶</a></dt>
  382. <dd><p>Return True if <em>frame</em> is below the starting frame in the stack.</p>
  383. </dd></dl>
  384. <dl class="py method">
  385. <dt class="sig sig-object py" id="bdb.Bdb.break_here">
  386. <span class="sig-name descname"><span class="pre">break_here</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.break_here" title="Link to this definition">¶</a></dt>
  387. <dd><p>Return True if there is an effective breakpoint for this line.</p>
  388. <p>Check whether a line or function breakpoint exists and is in effect. Delete temporary
  389. breakpoints based on information from <a class="reference internal" href="#bdb.effective" title="bdb.effective"><code class="xref py py-func docutils literal notranslate"><span class="pre">effective()</span></code></a>.</p>
  390. </dd></dl>
  391. <dl class="py method">
  392. <dt class="sig sig-object py" id="bdb.Bdb.break_anywhere">
  393. <span class="sig-name descname"><span class="pre">break_anywhere</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.break_anywhere" title="Link to this definition">¶</a></dt>
  394. <dd><p>Return True if any breakpoint exists for <em>frame</em>’s filename.</p>
  395. </dd></dl>
  396. <p>Derived classes should override these methods to gain control over debugger
  397. operation.</p>
  398. <dl class="py method">
  399. <dt class="sig sig-object py" id="bdb.Bdb.user_call">
  400. <span class="sig-name descname"><span class="pre">user_call</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">argument_list</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.user_call" title="Link to this definition">¶</a></dt>
  401. <dd><p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_call" title="bdb.Bdb.dispatch_call"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_call()</span></code></a> if a break might stop inside the
  402. called function.</p>
  403. </dd></dl>
  404. <dl class="py method">
  405. <dt class="sig sig-object py" id="bdb.Bdb.user_line">
  406. <span class="sig-name descname"><span class="pre">user_line</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.user_line" title="Link to this definition">¶</a></dt>
  407. <dd><p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_line" title="bdb.Bdb.dispatch_line"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_line()</span></code></a> when either <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stop_here()</span></code></a> or
  408. <a class="reference internal" href="#bdb.Bdb.break_here" title="bdb.Bdb.break_here"><code class="xref py py-meth docutils literal notranslate"><span class="pre">break_here()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  409. </dd></dl>
  410. <dl class="py method">
  411. <dt class="sig sig-object py" id="bdb.Bdb.user_return">
  412. <span class="sig-name descname"><span class="pre">user_return</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.user_return" title="Link to this definition">¶</a></dt>
  413. <dd><p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_return" title="bdb.Bdb.dispatch_return"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_return()</span></code></a> when <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stop_here()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  414. </dd></dl>
  415. <dl class="py method">
  416. <dt class="sig sig-object py" id="bdb.Bdb.user_exception">
  417. <span class="sig-name descname"><span class="pre">user_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.user_exception" title="Link to this definition">¶</a></dt>
  418. <dd><p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_exception" title="bdb.Bdb.dispatch_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_exception()</span></code></a> when <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stop_here()</span></code></a>
  419. returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  420. </dd></dl>
  421. <dl class="py method">
  422. <dt class="sig sig-object py" id="bdb.Bdb.do_clear">
  423. <span class="sig-name descname"><span class="pre">do_clear</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.do_clear" title="Link to this definition">¶</a></dt>
  424. <dd><p>Handle how a breakpoint must be removed when it is a temporary one.</p>
  425. <p>This method must be implemented by derived classes.</p>
  426. </dd></dl>
  427. <p>Derived classes and clients can call the following methods to affect the
  428. stepping state.</p>
  429. <dl class="py method">
  430. <dt class="sig sig-object py" id="bdb.Bdb.set_step">
  431. <span class="sig-name descname"><span class="pre">set_step</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_step" title="Link to this definition">¶</a></dt>
  432. <dd><p>Stop after one line of code.</p>
  433. </dd></dl>
  434. <dl class="py method">
  435. <dt class="sig sig-object py" id="bdb.Bdb.set_next">
  436. <span class="sig-name descname"><span class="pre">set_next</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_next" title="Link to this definition">¶</a></dt>
  437. <dd><p>Stop on the next line in or below the given frame.</p>
  438. </dd></dl>
  439. <dl class="py method">
  440. <dt class="sig sig-object py" id="bdb.Bdb.set_return">
  441. <span class="sig-name descname"><span class="pre">set_return</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_return" title="Link to this definition">¶</a></dt>
  442. <dd><p>Stop when returning from the given frame.</p>
  443. </dd></dl>
  444. <dl class="py method">
  445. <dt class="sig sig-object py" id="bdb.Bdb.set_until">
  446. <span class="sig-name descname"><span class="pre">set_until</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</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="#bdb.Bdb.set_until" title="Link to this definition">¶</a></dt>
  447. <dd><p>Stop when the line with the <em>lineno</em> greater than the current one is
  448. reached or when returning from current frame.</p>
  449. </dd></dl>
  450. <dl class="py method">
  451. <dt class="sig sig-object py" id="bdb.Bdb.set_trace">
  452. <span class="sig-name descname"><span class="pre">set_trace</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_trace" title="Link to this definition">¶</a></dt>
  453. <dd><p>Start debugging from <em>frame</em>. If <em>frame</em> is not specified, debugging
  454. starts from caller’s frame.</p>
  455. </dd></dl>
  456. <dl class="py method">
  457. <dt class="sig sig-object py" id="bdb.Bdb.set_continue">
  458. <span class="sig-name descname"><span class="pre">set_continue</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_continue" title="Link to this definition">¶</a></dt>
  459. <dd><p>Stop only at breakpoints or when finished. If there are no breakpoints,
  460. set the system trace function to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  461. </dd></dl>
  462. <dl class="py method">
  463. <dt class="sig sig-object py" id="bdb.Bdb.set_quit">
  464. <span class="sig-name descname"><span class="pre">set_quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.set_quit" title="Link to this definition">¶</a></dt>
  465. <dd><p id="index-0">Set the <code class="xref py py-attr docutils literal notranslate"><span class="pre">quitting</span></code> attribute to <code class="docutils literal notranslate"><span class="pre">True</span></code>. This raises <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BdbQuit</span></code></a> in
  466. the next call to one of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_*()</span></code> methods.</p>
  467. </dd></dl>
  468. <p>Derived classes and clients can call the following methods to manipulate
  469. breakpoints. These methods return a string containing an error message if
  470. something went wrong, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if all is well.</p>
  471. <dl class="py method">
  472. <dt class="sig sig-object py" id="bdb.Bdb.set_break">
  473. <span class="sig-name descname"><span class="pre">set_break</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">temporary</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">cond</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">funcname</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="#bdb.Bdb.set_break" title="Link to this definition">¶</a></dt>
  474. <dd><p>Set a new breakpoint. If the <em>lineno</em> line doesn’t exist for the
  475. <em>filename</em> passed as argument, return an error message. The <em>filename</em>
  476. should be in canonical form, as described in the <a class="reference internal" href="#bdb.Bdb.canonic" title="bdb.Bdb.canonic"><code class="xref py py-meth docutils literal notranslate"><span class="pre">canonic()</span></code></a> method.</p>
  477. </dd></dl>
  478. <dl class="py method">
  479. <dt class="sig sig-object py" id="bdb.Bdb.clear_break">
  480. <span class="sig-name descname"><span class="pre">clear_break</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.clear_break" title="Link to this definition">¶</a></dt>
  481. <dd><p>Delete the breakpoints in <em>filename</em> and <em>lineno</em>. If none were set,
  482. return an error message.</p>
  483. </dd></dl>
  484. <dl class="py method">
  485. <dt class="sig sig-object py" id="bdb.Bdb.clear_bpbynumber">
  486. <span class="sig-name descname"><span class="pre">clear_bpbynumber</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.clear_bpbynumber" title="Link to this definition">¶</a></dt>
  487. <dd><p>Delete the breakpoint which has the index <em>arg</em> in the
  488. <a class="reference internal" href="#bdb.Breakpoint.bpbynumber" title="bdb.Breakpoint.bpbynumber"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Breakpoint.bpbynumber</span></code></a>. If <em>arg</em> is not numeric or out of range,
  489. return an error message.</p>
  490. </dd></dl>
  491. <dl class="py method">
  492. <dt class="sig sig-object py" id="bdb.Bdb.clear_all_file_breaks">
  493. <span class="sig-name descname"><span class="pre">clear_all_file_breaks</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.clear_all_file_breaks" title="Link to this definition">¶</a></dt>
  494. <dd><p>Delete all breakpoints in <em>filename</em>. If none were set, return an error
  495. message.</p>
  496. </dd></dl>
  497. <dl class="py method">
  498. <dt class="sig sig-object py" id="bdb.Bdb.clear_all_breaks">
  499. <span class="sig-name descname"><span class="pre">clear_all_breaks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.clear_all_breaks" title="Link to this definition">¶</a></dt>
  500. <dd><p>Delete all existing breakpoints. If none were set, return an error
  501. message.</p>
  502. </dd></dl>
  503. <dl class="py method">
  504. <dt class="sig sig-object py" id="bdb.Bdb.get_bpbynumber">
  505. <span class="sig-name descname"><span class="pre">get_bpbynumber</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_bpbynumber" title="Link to this definition">¶</a></dt>
  506. <dd><p>Return a breakpoint specified by the given number. If <em>arg</em> is a string,
  507. it will be converted to a number. If <em>arg</em> is a non-numeric string, if
  508. the given breakpoint never existed or has been deleted, a
  509. <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.</p>
  510. <div class="versionadded">
  511. <p><span class="versionmodified added">New in version 3.2.</span></p>
  512. </div>
  513. </dd></dl>
  514. <dl class="py method">
  515. <dt class="sig sig-object py" id="bdb.Bdb.get_break">
  516. <span class="sig-name descname"><span class="pre">get_break</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_break" title="Link to this definition">¶</a></dt>
  517. <dd><p>Return True if there is a breakpoint for <em>lineno</em> in <em>filename</em>.</p>
  518. </dd></dl>
  519. <dl class="py method">
  520. <dt class="sig sig-object py" id="bdb.Bdb.get_breaks">
  521. <span class="sig-name descname"><span class="pre">get_breaks</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_breaks" title="Link to this definition">¶</a></dt>
  522. <dd><p>Return all breakpoints for <em>lineno</em> in <em>filename</em>, or an empty list if
  523. none are set.</p>
  524. </dd></dl>
  525. <dl class="py method">
  526. <dt class="sig sig-object py" id="bdb.Bdb.get_file_breaks">
  527. <span class="sig-name descname"><span class="pre">get_file_breaks</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_file_breaks" title="Link to this definition">¶</a></dt>
  528. <dd><p>Return all breakpoints in <em>filename</em>, or an empty list if none are set.</p>
  529. </dd></dl>
  530. <dl class="py method">
  531. <dt class="sig sig-object py" id="bdb.Bdb.get_all_breaks">
  532. <span class="sig-name descname"><span class="pre">get_all_breaks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_all_breaks" title="Link to this definition">¶</a></dt>
  533. <dd><p>Return all breakpoints that are set.</p>
  534. </dd></dl>
  535. <p>Derived classes and clients can call the following methods to get a data
  536. structure representing a stack trace.</p>
  537. <dl class="py method">
  538. <dt class="sig sig-object py" id="bdb.Bdb.get_stack">
  539. <span class="sig-name descname"><span class="pre">get_stack</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">t</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.get_stack" title="Link to this definition">¶</a></dt>
  540. <dd><p>Return a list of (frame, lineno) tuples in a stack trace, and a size.</p>
  541. <p>The most recently called frame is last in the list. The size is the number
  542. of frames below the frame where the debugger was invoked.</p>
  543. </dd></dl>
  544. <dl class="py method">
  545. <dt class="sig sig-object py" id="bdb.Bdb.format_stack_entry">
  546. <span class="sig-name descname"><span class="pre">format_stack_entry</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame_lineno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lprefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">':</span> <span class="pre">'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.format_stack_entry" title="Link to this definition">¶</a></dt>
  547. <dd><p>Return a string with information about a stack entry, which is a
  548. <code class="docutils literal notranslate"><span class="pre">(frame,</span> <span class="pre">lineno)</span></code> tuple. The return string contains:</p>
  549. <ul class="simple">
  550. <li><p>The canonical filename which contains the frame.</p></li>
  551. <li><p>The function name or <code class="docutils literal notranslate"><span class="pre">&quot;&lt;lambda&gt;&quot;</span></code>.</p></li>
  552. <li><p>The input arguments.</p></li>
  553. <li><p>The return value.</p></li>
  554. <li><p>The line of code (if it exists).</p></li>
  555. </ul>
  556. </dd></dl>
  557. <p>The following two methods can be called by clients to use a debugger to debug
  558. a <a class="reference internal" href="../glossary.html#term-statement"><span class="xref std std-term">statement</span></a>, given as a string.</p>
  559. <dl class="py method">
  560. <dt class="sig sig-object py" id="bdb.Bdb.run">
  561. <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">cmd</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="#bdb.Bdb.run" title="Link to this definition">¶</a></dt>
  562. <dd><p>Debug a statement executed via the <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> function. <em>globals</em>
  563. defaults to <code class="xref py py-attr docutils literal notranslate"><span class="pre">__main__.__dict__</span></code>, <em>locals</em> defaults to <em>globals</em>.</p>
  564. </dd></dl>
  565. <dl class="py method">
  566. <dt class="sig sig-object py" id="bdb.Bdb.runeval">
  567. <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">expr</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="#bdb.Bdb.runeval" title="Link to this definition">¶</a></dt>
  568. <dd><p>Debug an expression executed via the <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> function. <em>globals</em> and
  569. <em>locals</em> have the same meaning as in <a class="reference internal" href="#bdb.Bdb.run" title="bdb.Bdb.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run()</span></code></a>.</p>
  570. </dd></dl>
  571. <dl class="py method">
  572. <dt class="sig sig-object py" id="bdb.Bdb.runctx">
  573. <span class="sig-name descname"><span class="pre">runctx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.Bdb.runctx" title="Link to this definition">¶</a></dt>
  574. <dd><p>For backwards compatibility. Calls the <a class="reference internal" href="#bdb.Bdb.run" title="bdb.Bdb.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run()</span></code></a> method.</p>
  575. </dd></dl>
  576. <dl class="py method">
  577. <dt class="sig sig-object py" id="bdb.Bdb.runcall">
  578. <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">func</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">/</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="#bdb.Bdb.runcall" title="Link to this definition">¶</a></dt>
  579. <dd><p>Debug a single function call, and return its result.</p>
  580. </dd></dl>
  581. </dd></dl>
  582. <p>Finally, the module defines the following functions:</p>
  583. <dl class="py function">
  584. <dt class="sig sig-object py" id="bdb.checkfuncname">
  585. <span class="sig-prename descclassname"><span class="pre">bdb.</span></span><span class="sig-name descname"><span class="pre">checkfuncname</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.checkfuncname" title="Link to this definition">¶</a></dt>
  586. <dd><p>Return True if we should break here, depending on the way the
  587. <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Breakpoint</span></code></a> <em>b</em> was set.</p>
  588. <p>If it was set via line number, it checks if
  589. <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code class="xref py py-attr docutils literal notranslate"><span class="pre">b.line</span></code></a> is the same as the one in <em>frame</em>.
  590. If the breakpoint was set via
  591. <a class="reference internal" href="#bdb.Breakpoint.funcname" title="bdb.Breakpoint.funcname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">function</span> <span class="pre">name</span></code></a>, we have to check we are in
  592. the right <em>frame</em> (the right function) and if we are on its first executable
  593. line.</p>
  594. </dd></dl>
  595. <dl class="py function">
  596. <dt class="sig sig-object py" id="bdb.effective">
  597. <span class="sig-prename descclassname"><span class="pre">bdb.</span></span><span class="sig-name descname"><span class="pre">effective</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">line</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">frame</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bdb.effective" title="Link to this definition">¶</a></dt>
  598. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">(active</span> <span class="pre">breakpoint,</span> <span class="pre">delete</span> <span class="pre">temporary</span> <span class="pre">flag)</span></code> or <code class="docutils literal notranslate"><span class="pre">(None,</span> <span class="pre">None)</span></code> as the
  599. breakpoint to act upon.</p>
  600. <p>The <em>active breakpoint</em> is the first entry in
  601. <a class="reference internal" href="#bdb.Breakpoint.bplist" title="bdb.Breakpoint.bplist"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bplist</span></code></a> for the
  602. (<a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span></code></a>, <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code class="xref py py-attr docutils literal notranslate"><span class="pre">line</span></code></a>)
  603. (which must exist) that is <a class="reference internal" href="#bdb.Breakpoint.enabled" title="bdb.Breakpoint.enabled"><code class="xref py py-attr docutils literal notranslate"><span class="pre">enabled</span></code></a>, for
  604. which <a class="reference internal" href="#bdb.checkfuncname" title="bdb.checkfuncname"><code class="xref py py-func docutils literal notranslate"><span class="pre">checkfuncname()</span></code></a> is True, and that has neither a False
  605. <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code class="xref py py-attr docutils literal notranslate"><span class="pre">condition</span></code></a> nor positive
  606. <a class="reference internal" href="#bdb.Breakpoint.ignore" title="bdb.Breakpoint.ignore"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ignore</span></code></a> count. The <em>flag</em>, meaning that a
  607. temporary breakpoint should be deleted, is False only when the
  608. <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code class="xref py py-attr docutils literal notranslate"><span class="pre">cond</span></code></a> cannot be evaluated (in which case,
  609. <a class="reference internal" href="#bdb.Breakpoint.ignore" title="bdb.Breakpoint.ignore"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ignore</span></code></a> count is ignored).</p>
  610. <p>If no such entry exists, then (None, None) is returned.</p>
  611. </dd></dl>
  612. <dl class="py function">
  613. <dt class="sig sig-object py" id="bdb.set_trace">
  614. <span class="sig-prename descclassname"><span class="pre">bdb.</span></span><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="#bdb.set_trace" title="Link to this definition">¶</a></dt>
  615. <dd><p>Start debugging with a <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bdb</span></code></a> instance from caller’s frame.</p>
  616. </dd></dl>
  617. </section>
  618. <div class="clearer"></div>
  619. </div>
  620. </div>
  621. </div>
  622. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  623. <div class="sphinxsidebarwrapper">
  624. <div>
  625. <h4>Previous topic</h4>
  626. <p class="topless"><a href="audit_events.html"
  627. title="previous chapter">Audit events table</a></p>
  628. </div>
  629. <div>
  630. <h4>Next topic</h4>
  631. <p class="topless"><a href="faulthandler.html"
  632. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code> — Dump the Python traceback</a></p>
  633. </div>
  634. <div role="note" aria-label="source link">
  635. <h3>This Page</h3>
  636. <ul class="this-page-menu">
  637. <li><a href="../bugs.html">Report a Bug</a></li>
  638. <li>
  639. <a href="https://github.com/python/cpython/blob/main/Doc/library/bdb.rst"
  640. rel="nofollow">Show Source
  641. </a>
  642. </li>
  643. </ul>
  644. </div>
  645. </div>
  646. <div id="sidebarbutton" title="Collapse sidebar">
  647. <span>«</span>
  648. </div>
  649. </div>
  650. <div class="clearer"></div>
  651. </div>
  652. <div class="related" role="navigation" aria-label="related navigation">
  653. <h3>Navigation</h3>
  654. <ul>
  655. <li class="right" style="margin-right: 10px">
  656. <a href="../genindex.html" title="General Index"
  657. >index</a></li>
  658. <li class="right" >
  659. <a href="../py-modindex.html" title="Python Module Index"
  660. >modules</a> |</li>
  661. <li class="right" >
  662. <a href="faulthandler.html" title="faulthandler — Dump the Python traceback"
  663. >next</a> |</li>
  664. <li class="right" >
  665. <a href="audit_events.html" title="Audit events table"
  666. >previous</a> |</li>
  667. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  668. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  669. <li class="switchers">
  670. <div class="language_switcher_placeholder"></div>
  671. <div class="version_switcher_placeholder"></div>
  672. </li>
  673. <li>
  674. </li>
  675. <li id="cpython-language-and-version">
  676. <a href="../index.html">3.12.3 Documentation</a> &#187;
  677. </li>
  678. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  679. <li class="nav-item nav-item-2"><a href="debug.html" >Debugging and Profiling</a> &#187;</li>
  680. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">bdb</span></code> — Debugger framework</a></li>
  681. <li class="right">
  682. <div class="inline-search" role="search">
  683. <form class="inline-search" action="../search.html" method="get">
  684. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  685. <input type="submit" value="Go" />
  686. </form>
  687. </div>
  688. |
  689. </li>
  690. <li class="right">
  691. <label class="theme-selector-label">
  692. Theme
  693. <select class="theme-selector" oninput="activateTheme(this.value)">
  694. <option value="auto" selected>Auto</option>
  695. <option value="light">Light</option>
  696. <option value="dark">Dark</option>
  697. </select>
  698. </label> |</li>
  699. </ul>
  700. </div>
  701. <div class="footer">
  702. &copy;
  703. <a href="../copyright.html">
  704. Copyright
  705. </a>
  706. 2001-2024, Python Software Foundation.
  707. <br />
  708. This page is licensed under the Python Software Foundation License Version 2.
  709. <br />
  710. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  711. <br />
  712. See <a href="/license.html">History and License</a> for more information.<br />
  713. <br />
  714. The Python Software Foundation is a non-profit corporation.
  715. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  716. <br />
  717. <br />
  718. Last updated on Apr 09, 2024 (13:47 UTC).
  719. <a href="/bugs.html">Found a bug</a>?
  720. <br />
  721. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  722. </div>
  723. </body>
  724. </html>
上海开阖软件有限公司 沪ICP备12045867号-1