gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

784 lines
48KB

  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="Debugging C API extensions and CPython Internals with GDB" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/howto/gdb_helpers.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This document explains how the Python GDB extension, python-gdb.py, can be used with the GDB debugger to debug CPython extensions and the CPython interpreter itself. When debugging low-level proble..." />
  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="This document explains how the Python GDB extension, python-gdb.py, can be used with the GDB debugger to debug CPython extensions and the CPython interpreter itself. When debugging low-level proble..." />
  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>Debugging C API extensions and CPython Internals with GDB &#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="Enum HOWTO" href="enum.html" />
  33. <link rel="prev" title="Descriptor Guide" href="descriptor.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/howto/gdb_helpers.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">Debugging C API extensions and CPython Internals with GDB</a><ul>
  86. <li><a class="reference internal" href="#prerequisites">Prerequisites</a><ul>
  87. <li><a class="reference internal" href="#setup-with-python-built-from-source">Setup with Python built from source</a></li>
  88. <li><a class="reference internal" href="#setup-for-python-from-a-linux-distro">Setup for Python from a Linux distro</a></li>
  89. </ul>
  90. </li>
  91. <li><a class="reference internal" href="#using-the-debug-build-and-development-mode">Using the Debug build and Development mode</a></li>
  92. <li><a class="reference internal" href="#using-the-python-gdb-extension">Using the <code class="docutils literal notranslate"><span class="pre">python-gdb</span></code> extension</a><ul>
  93. <li><a class="reference internal" href="#pretty-printers">Pretty-printers</a></li>
  94. <li><a class="reference internal" href="#py-list"><code class="docutils literal notranslate"><span class="pre">py-list</span></code></a></li>
  95. <li><a class="reference internal" href="#py-up-and-py-down"><code class="docutils literal notranslate"><span class="pre">py-up</span></code> and <code class="docutils literal notranslate"><span class="pre">py-down</span></code></a></li>
  96. <li><a class="reference internal" href="#py-bt"><code class="docutils literal notranslate"><span class="pre">py-bt</span></code></a></li>
  97. <li><a class="reference internal" href="#py-print"><code class="docutils literal notranslate"><span class="pre">py-print</span></code></a></li>
  98. <li><a class="reference internal" href="#py-locals"><code class="docutils literal notranslate"><span class="pre">py-locals</span></code></a></li>
  99. </ul>
  100. </li>
  101. <li><a class="reference internal" href="#use-with-gdb-commands">Use with GDB commands</a></li>
  102. </ul>
  103. </li>
  104. </ul>
  105. </div>
  106. <div>
  107. <h4>Previous topic</h4>
  108. <p class="topless"><a href="descriptor.html"
  109. title="previous chapter">Descriptor Guide</a></p>
  110. </div>
  111. <div>
  112. <h4>Next topic</h4>
  113. <p class="topless"><a href="enum.html"
  114. title="next chapter">Enum HOWTO</a></p>
  115. </div>
  116. <div role="note" aria-label="source link">
  117. <h3>This Page</h3>
  118. <ul class="this-page-menu">
  119. <li><a href="../bugs.html">Report a Bug</a></li>
  120. <li>
  121. <a href="https://github.com/python/cpython/blob/main/Doc/howto/gdb_helpers.rst"
  122. rel="nofollow">Show Source
  123. </a>
  124. </li>
  125. </ul>
  126. </div>
  127. </nav>
  128. </div>
  129. </div>
  130. <div class="related" role="navigation" aria-label="related navigation">
  131. <h3>Navigation</h3>
  132. <ul>
  133. <li class="right" style="margin-right: 10px">
  134. <a href="../genindex.html" title="General Index"
  135. accesskey="I">index</a></li>
  136. <li class="right" >
  137. <a href="../py-modindex.html" title="Python Module Index"
  138. >modules</a> |</li>
  139. <li class="right" >
  140. <a href="enum.html" title="Enum HOWTO"
  141. accesskey="N">next</a> |</li>
  142. <li class="right" >
  143. <a href="descriptor.html" title="Descriptor Guide"
  144. accesskey="P">previous</a> |</li>
  145. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  146. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  147. <li class="switchers">
  148. <div class="language_switcher_placeholder"></div>
  149. <div class="version_switcher_placeholder"></div>
  150. </li>
  151. <li>
  152. </li>
  153. <li id="cpython-language-and-version">
  154. <a href="../index.html">3.12.3 Documentation</a> &#187;
  155. </li>
  156. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python HOWTOs</a> &#187;</li>
  157. <li class="nav-item nav-item-this"><a href="">Debugging C API extensions and CPython Internals with GDB</a></li>
  158. <li class="right">
  159. <div class="inline-search" role="search">
  160. <form class="inline-search" action="../search.html" method="get">
  161. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  162. <input type="submit" value="Go" />
  163. </form>
  164. </div>
  165. |
  166. </li>
  167. <li class="right">
  168. <label class="theme-selector-label">
  169. Theme
  170. <select class="theme-selector" oninput="activateTheme(this.value)">
  171. <option value="auto" selected>Auto</option>
  172. <option value="light">Light</option>
  173. <option value="dark">Dark</option>
  174. </select>
  175. </label> |</li>
  176. </ul>
  177. </div>
  178. <div class="document">
  179. <div class="documentwrapper">
  180. <div class="bodywrapper">
  181. <div class="body" role="main">
  182. <section id="debugging-c-api-extensions-and-cpython-internals-with-gdb">
  183. <span id="gdb"></span><h1>Debugging C API extensions and CPython Internals with GDB<a class="headerlink" href="#debugging-c-api-extensions-and-cpython-internals-with-gdb" title="Link to this heading">¶</a></h1>
  184. <p>This document explains how the Python GDB extension, <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code>, can
  185. be used with the GDB debugger to debug CPython extensions and the
  186. CPython interpreter itself.</p>
  187. <p>When debugging low-level problems such as crashes or deadlocks, a low-level
  188. debugger, such as GDB, is useful to diagnose and correct the issue.
  189. By default, GDB (or any of its front-ends) doesn’t support high-level
  190. information specific to the CPython interpreter.</p>
  191. <p>The <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code> extension adds CPython interpreter information to GDB.
  192. The extension helps introspect the stack of currently executing Python functions.
  193. Given a Python object represented by a <span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/structures.html#c.PyObject" title="PyObject"><span class="n">PyObject</span></a><span class="p">*</span></span> pointer,
  194. the extension surfaces the type and value of the object.</p>
  195. <p>Developers who are working on CPython extensions or tinkering with parts
  196. of CPython that are written in C can use this document to learn how to use the
  197. <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code> extension with GDB.</p>
  198. <div class="admonition note">
  199. <p class="admonition-title">Note</p>
  200. <p>This document assumes that you are familiar with the basics of GDB and the
  201. CPython C API. It consolidates guidance from the
  202. <a class="reference external" href="https://devguide.python.org">devguide</a> and the
  203. <a class="reference external" href="https://wiki.python.org/moin/DebuggingWithGdb">Python wiki</a>.</p>
  204. </div>
  205. <section id="prerequisites">
  206. <h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Link to this heading">¶</a></h2>
  207. <p>You need to have:</p>
  208. <ul class="simple">
  209. <li><p>GDB 7 or later. (For earlier versions of GDB, see <code class="docutils literal notranslate"><span class="pre">Misc/gdbinit</span></code> in the
  210. sources of Python 3.11 or earlier.)</p></li>
  211. <li><p>GDB-compatible debugging information for Python and any extension you are
  212. debugging.</p></li>
  213. <li><p>The <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code> extension.</p></li>
  214. </ul>
  215. <p>The extension is built with Python, but might be distributed separately or
  216. not at all. Below, we include tips for a few common systems as examples.
  217. Note that even if the instructions match your system, they might be outdated.</p>
  218. <section id="setup-with-python-built-from-source">
  219. <h3>Setup with Python built from source<a class="headerlink" href="#setup-with-python-built-from-source" title="Link to this heading">¶</a></h3>
  220. <p>When you build CPython from source, debugging information should be available,
  221. and the build should add a <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code> file to the root directory of
  222. your repository.</p>
  223. <p>To activate support, you must add the directory containing <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code>
  224. to GDB’s “auto-load-safe-path”.
  225. If you haven’t done this, recent versions of GDB will print out a warning
  226. with instructions on how to do this.</p>
  227. <div class="admonition note">
  228. <p class="admonition-title">Note</p>
  229. <p>If you do not see instructions for your version of GDB, put this in your
  230. configuration file (<code class="docutils literal notranslate"><span class="pre">~/.gdbinit</span></code> or <code class="docutils literal notranslate"><span class="pre">~/.config/gdb/gdbinit</span></code>):</p>
  231. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>add-auto-load-safe-path /path/to/cpython
  232. </pre></div>
  233. </div>
  234. <p>You can also add multiple paths, separated by <code class="docutils literal notranslate"><span class="pre">:</span></code>.</p>
  235. </div>
  236. </section>
  237. <section id="setup-for-python-from-a-linux-distro">
  238. <h3>Setup for Python from a Linux distro<a class="headerlink" href="#setup-for-python-from-a-linux-distro" title="Link to this heading">¶</a></h3>
  239. <p>Most Linux systems provide debug information for the system Python
  240. in a package called <code class="docutils literal notranslate"><span class="pre">python-debuginfo</span></code>, <code class="docutils literal notranslate"><span class="pre">python-dbg</span></code> or similar.
  241. For example:</p>
  242. <ul>
  243. <li><p>Fedora:</p>
  244. <blockquote>
  245. <div><div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>dnf<span class="w"> </span>install<span class="w"> </span>gdb
  246. sudo<span class="w"> </span>dnf<span class="w"> </span>debuginfo-install<span class="w"> </span>python3
  247. </pre></div>
  248. </div>
  249. </div></blockquote>
  250. </li>
  251. <li><p>Ubuntu:</p>
  252. <blockquote>
  253. <div><div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>apt<span class="w"> </span>install<span class="w"> </span>gdb<span class="w"> </span>python3-dbg
  254. </pre></div>
  255. </div>
  256. </div></blockquote>
  257. </li>
  258. </ul>
  259. <p>On several recent Linux systems, GDB can download debugging symbols
  260. automatically using <em>debuginfod</em>.
  261. However, this will not install the <code class="docutils literal notranslate"><span class="pre">python-gdb.py</span></code> extension;
  262. you generally do need to install the debug info package separately.</p>
  263. </section>
  264. </section>
  265. <section id="using-the-debug-build-and-development-mode">
  266. <h2>Using the Debug build and Development mode<a class="headerlink" href="#using-the-debug-build-and-development-mode" title="Link to this heading">¶</a></h2>
  267. <p>For easier debugging, you might want to:</p>
  268. <ul class="simple">
  269. <li><p>Use a <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a> of Python. (When building from source,
  270. use <code class="docutils literal notranslate"><span class="pre">configure</span> <span class="pre">--with-pydebug</span></code>. On Linux distros, install and run a package
  271. like <code class="docutils literal notranslate"><span class="pre">python-debug</span></code> or <code class="docutils literal notranslate"><span class="pre">python-dbg</span></code>, if available.)</p></li>
  272. <li><p>Use the runtime <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">development mode</span></a> (<code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">dev</span></code>).</p></li>
  273. </ul>
  274. <p>Both enable extra assertions and disable some optimizations.
  275. Sometimes this hides the bug you are trying to find, but in most cases they
  276. make the process easier.</p>
  277. </section>
  278. <section id="using-the-python-gdb-extension">
  279. <h2>Using the <code class="docutils literal notranslate"><span class="pre">python-gdb</span></code> extension<a class="headerlink" href="#using-the-python-gdb-extension" title="Link to this heading">¶</a></h2>
  280. <p>When the extension is loaded, it provides two main features:
  281. pretty printers for Python values, and additional commands.</p>
  282. <section id="pretty-printers">
  283. <h3>Pretty-printers<a class="headerlink" href="#pretty-printers" title="Link to this heading">¶</a></h3>
  284. <p>This is what a GDB backtrace looks like (truncated) when this extension is
  285. enabled:</p>
  286. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#0 0x000000000041a6b1 in PyObject_Malloc (nbytes=Cannot access memory at address 0x7fffff7fefe8
  287. ) at Objects/obmalloc.c:748
  288. #1 0x000000000041b7c0 in _PyObject_DebugMallocApi (id=111 &#39;o&#39;, nbytes=24) at Objects/obmalloc.c:1445
  289. #2 0x000000000041b717 in _PyObject_DebugMalloc (nbytes=24) at Objects/obmalloc.c:1412
  290. #3 0x000000000044060a in _PyUnicode_New (length=11) at Objects/unicodeobject.c:346
  291. #4 0x00000000004466aa in PyUnicodeUCS2_DecodeUTF8Stateful (s=0x5c2b8d &quot;__lltrace__&quot;, size=11, errors=0x0, consumed=
  292. 0x0) at Objects/unicodeobject.c:2531
  293. #5 0x0000000000446647 in PyUnicodeUCS2_DecodeUTF8 (s=0x5c2b8d &quot;__lltrace__&quot;, size=11, errors=0x0)
  294. at Objects/unicodeobject.c:2495
  295. #6 0x0000000000440d1b in PyUnicodeUCS2_FromStringAndSize (u=0x5c2b8d &quot;__lltrace__&quot;, size=11)
  296. at Objects/unicodeobject.c:551
  297. #7 0x0000000000440d94 in PyUnicodeUCS2_FromString (u=0x5c2b8d &quot;__lltrace__&quot;) at Objects/unicodeobject.c:569
  298. #8 0x0000000000584abd in PyDict_GetItemString (v=
  299. {&#39;Yuck&#39;: &lt;type at remote 0xad4730&gt;, &#39;__builtins__&#39;: &lt;module at remote 0x7ffff7fd5ee8&gt;, &#39;__file__&#39;: &#39;Lib/test/crashers/nasty_eq_vs_dict.py&#39;, &#39;__package__&#39;: None, &#39;y&#39;: &lt;Yuck(i=0) at remote 0xaacd80&gt;, &#39;dict&#39;: {0: 0, 1: 1, 2: 2, 3: 3}, &#39;__cached__&#39;: None, &#39;__name__&#39;: &#39;__main__&#39;, &#39;z&#39;: &lt;Yuck(i=0) at remote 0xaace60&gt;, &#39;__doc__&#39;: None}, key=
  300. 0x5c2b8d &quot;__lltrace__&quot;) at Objects/dictobject.c:2171
  301. </pre></div>
  302. </div>
  303. <p>Notice how the dictionary argument to <code class="docutils literal notranslate"><span class="pre">PyDict_GetItemString</span></code> is displayed
  304. as its <code class="docutils literal notranslate"><span class="pre">repr()</span></code>, rather than an opaque <code class="docutils literal notranslate"><span class="pre">PyObject</span> <span class="pre">*</span></code> pointer.</p>
  305. <p>The extension works by supplying a custom printing routine for values of type
  306. <code class="docutils literal notranslate"><span class="pre">PyObject</span> <span class="pre">*</span></code>. If you need to access lower-level details of an object, then
  307. cast the value to a pointer of the appropriate type. For example:</p>
  308. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) p globals
  309. $1 = {&#39;__builtins__&#39;: &lt;module at remote 0x7ffff7fb1868&gt;, &#39;__name__&#39;:
  310. &#39;__main__&#39;, &#39;ctypes&#39;: &lt;module at remote 0x7ffff7f14360&gt;, &#39;__doc__&#39;: None,
  311. &#39;__package__&#39;: None}
  312. (gdb) p *(PyDictObject*)globals
  313. $2 = {ob_refcnt = 3, ob_type = 0x3dbdf85820, ma_fill = 5, ma_used = 5,
  314. ma_mask = 7, ma_table = 0x63d0f8, ma_lookup = 0x3dbdc7ea70
  315. &lt;lookdict_string&gt;, ma_smalltable = {{me_hash = 7065186196740147912,
  316. me_key = &#39;__builtins__&#39;, me_value = &lt;module at remote 0x7ffff7fb1868&gt;},
  317. {me_hash = -368181376027291943, me_key = &#39;__name__&#39;,
  318. me_value =&#39;__main__&#39;}, {me_hash = 0, me_key = 0x0, me_value = 0x0},
  319. {me_hash = 0, me_key = 0x0, me_value = 0x0},
  320. {me_hash = -9177857982131165996, me_key = &#39;ctypes&#39;,
  321. me_value = &lt;module at remote 0x7ffff7f14360&gt;},
  322. {me_hash = -8518757509529533123, me_key = &#39;__doc__&#39;, me_value = None},
  323. {me_hash = 0, me_key = 0x0, me_value = 0x0}, {
  324. me_hash = 6614918939584953775, me_key = &#39;__package__&#39;, me_value = None}}}
  325. </pre></div>
  326. </div>
  327. <p>Note that the pretty-printers do not actually call <code class="docutils literal notranslate"><span class="pre">repr()</span></code>.
  328. For basic types, they try to match its result closely.</p>
  329. <p>An area that can be confusing is that the custom printer for some types look a
  330. lot like GDB’s built-in printer for standard types. For example, the
  331. pretty-printer for a Python <code class="docutils literal notranslate"><span class="pre">int</span></code> (<span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><span class="n">PyLongObject</span></a><span class="p">*</span></span>)
  332. gives a representation that is not distinguishable from one of a
  333. regular machine-level integer:</p>
  334. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) p some_machine_integer
  335. $3 = 42
  336. (gdb) p some_python_integer
  337. $4 = 42
  338. </pre></div>
  339. </div>
  340. <p>The internal structure can be revealed with a cast to <span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><span class="n">PyLongObject</span></a><span class="p">*</span></span>:</p>
  341. <blockquote>
  342. <div><p>(gdb) p <em>(PyLongObject</em>)some_python_integer
  343. $5 = {ob_base = {ob_base = {ob_refcnt = 8, ob_type = 0x3dad39f5e0}, ob_size = 1},
  344. ob_digit = {42}}</p>
  345. </div></blockquote>
  346. <p>A similar confusion can arise with the <code class="docutils literal notranslate"><span class="pre">str</span></code> type, where the output looks a
  347. lot like gdb’s built-in printer for <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>:</p>
  348. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) p ptr_to_python_str
  349. $6 = &#39;__builtins__&#39;
  350. </pre></div>
  351. </div>
  352. <p>The pretty-printer for <code class="docutils literal notranslate"><span class="pre">str</span></code> instances defaults to using single-quotes (as
  353. does Python’s <code class="docutils literal notranslate"><span class="pre">repr</span></code> for strings) whereas the standard printer for <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>
  354. values uses double-quotes and contains a hexadecimal address:</p>
  355. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) p ptr_to_char_star
  356. $7 = 0x6d72c0 &quot;hello world&quot;
  357. </pre></div>
  358. </div>
  359. <p>Again, the implementation details can be revealed with a cast to
  360. <span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/unicode.html#c.PyUnicodeObject" title="PyUnicodeObject"><span class="n">PyUnicodeObject</span></a><span class="p">*</span></span>:</p>
  361. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) p *(PyUnicodeObject*)$6
  362. $8 = {ob_base = {ob_refcnt = 33, ob_type = 0x3dad3a95a0}, length = 12,
  363. str = 0x7ffff2128500, hash = 7065186196740147912, state = 1, defenc = 0x0}
  364. </pre></div>
  365. </div>
  366. </section>
  367. <section id="py-list">
  368. <h3><code class="docutils literal notranslate"><span class="pre">py-list</span></code><a class="headerlink" href="#py-list" title="Link to this heading">¶</a></h3>
  369. <blockquote>
  370. <div><p>The extension adds a <code class="docutils literal notranslate"><span class="pre">py-list</span></code> command, which
  371. lists the Python source code (if any) for the current frame in the selected
  372. thread. The current line is marked with a “&gt;”:</p>
  373. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-list
  374. 901 if options.profile:
  375. 902 options.profile = False
  376. 903 profile_me()
  377. 904 return
  378. 905
  379. &gt;906 u = UI()
  380. 907 if not u.quit:
  381. 908 try:
  382. 909 gtk.main()
  383. 910 except KeyboardInterrupt:
  384. 911 # properly quit on a keyboard interrupt...
  385. </pre></div>
  386. </div>
  387. <p>Use <code class="docutils literal notranslate"><span class="pre">py-list</span> <span class="pre">START</span></code> to list at a different line number within the Python
  388. source, and <code class="docutils literal notranslate"><span class="pre">py-list</span> <span class="pre">START,END</span></code> to list a specific range of lines within
  389. the Python source.</p>
  390. </div></blockquote>
  391. </section>
  392. <section id="py-up-and-py-down">
  393. <h3><code class="docutils literal notranslate"><span class="pre">py-up</span></code> and <code class="docutils literal notranslate"><span class="pre">py-down</span></code><a class="headerlink" href="#py-up-and-py-down" title="Link to this heading">¶</a></h3>
  394. <blockquote>
  395. <div><p>The <code class="docutils literal notranslate"><span class="pre">py-up</span></code> and <code class="docutils literal notranslate"><span class="pre">py-down</span></code> commands are analogous to GDB’s regular <code class="docutils literal notranslate"><span class="pre">up</span></code>
  396. and <code class="docutils literal notranslate"><span class="pre">down</span></code> commands, but try to move at the level of CPython frames, rather
  397. than C frames.</p>
  398. <p>GDB is not always able to read the relevant frame information, depending on
  399. the optimization level with which CPython was compiled. Internally, the
  400. commands look for C frames that are executing the default frame evaluation
  401. function (that is, the core bytecode interpreter loop within CPython) and
  402. look up the value of the related <code class="docutils literal notranslate"><span class="pre">PyFrameObject</span> <span class="pre">*</span></code>.</p>
  403. <p>They emit the frame number (at the C level) within the thread.</p>
  404. <p>For example:</p>
  405. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-up
  406. #37 Frame 0x9420b04, for file /usr/lib/python2.6/site-packages/
  407. gnome_sudoku/main.py, line 906, in start_game ()
  408. u = UI()
  409. (gdb) py-up
  410. #40 Frame 0x948e82c, for file /usr/lib/python2.6/site-packages/
  411. gnome_sudoku/gnome_sudoku.py, line 22, in start_game(main=&lt;module at remote 0xb771b7f4&gt;)
  412. main.start_game()
  413. (gdb) py-up
  414. Unable to find an older python frame
  415. </pre></div>
  416. </div>
  417. <p>so we’re at the top of the Python stack.</p>
  418. <p>The frame numbers correspond to those displayed by GDB’s standard
  419. <code class="docutils literal notranslate"><span class="pre">backtrace</span></code> command.
  420. The command skips C frames which are not executing Python code.</p>
  421. <p>Going back down:</p>
  422. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-down
  423. #37 Frame 0x9420b04, for file /usr/lib/python2.6/site-packages/gnome_sudoku/main.py, line 906, in start_game ()
  424. u = UI()
  425. (gdb) py-down
  426. #34 (unable to read python frame information)
  427. (gdb) py-down
  428. #23 (unable to read python frame information)
  429. (gdb) py-down
  430. #19 (unable to read python frame information)
  431. (gdb) py-down
  432. #14 Frame 0x99262ac, for file /usr/lib/python2.6/site-packages/gnome_sudoku/game_selector.py, line 201, in run_swallowed_dialog (self=&lt;NewOrSavedGameSelector(new_game_model=&lt;gtk.ListStore at remote 0x98fab44&gt;, puzzle=None, saved_games=[{&#39;gsd.auto_fills&#39;: 0, &#39;tracking&#39;: {}, &#39;trackers&#39;: {}, &#39;notes&#39;: [], &#39;saved_at&#39;: 1270084485, &#39;game&#39;: &#39;7 8 0 0 0 0 0 5 6 0 0 9 0 8 0 1 0 0 0 4 6 0 0 0 0 7 0 6 5 0 0 0 4 7 9 2 0 0 0 9 0 1 0 0 0 3 9 7 6 0 0 0 1 8 0 6 0 0 0 0 2 8 0 0 0 5 0 4 0 6 0 0 2 1 0 0 0 0 0 4 5\n7 8 0 0 0 0 0 5 6 0 0 9 0 8 0 1 0 0 0 4 6 0 0 0 0 7 0 6 5 1 8 3 4 7 9 2 0 0 0 9 0 1 0 0 0 3 9 7 6 0 0 0 1 8 0 6 0 0 0 0 2 8 0 0 0 5 0 4 0 6 0 0 2 1 0 0 0 0 0 4 5&#39;, &#39;gsd.impossible_hints&#39;: 0, &#39;timer.__absolute_start_time__&#39;: &lt;float at remote 0x984b474&gt;, &#39;gsd.hints&#39;: 0, &#39;timer.active_time&#39;: &lt;float at remote 0x984b494&gt;, &#39;timer.total_time&#39;: &lt;float at remote 0x984b464&gt;}], dialog=&lt;gtk.Dialog at remote 0x98faaa4&gt;, saved_game_model=&lt;gtk.ListStore at remote 0x98fad24&gt;, sudoku_maker=&lt;SudokuMaker(terminated=False, played=[], batch_siz...(truncated)
  433. swallower.run_dialog(self.dialog)
  434. (gdb) py-down
  435. #11 Frame 0x9aead74, for file /usr/lib/python2.6/site-packages/gnome_sudoku/dialog_swallower.py, line 48, in run_dialog (self=&lt;SwappableArea(running=&lt;gtk.Dialog at remote 0x98faaa4&gt;, main_page=0) at remote 0x98fa6e4&gt;, d=&lt;gtk.Dialog at remote 0x98faaa4&gt;)
  436. gtk.main()
  437. (gdb) py-down
  438. #8 (unable to read python frame information)
  439. (gdb) py-down
  440. Unable to find a newer python frame
  441. </pre></div>
  442. </div>
  443. <p>and we’re at the bottom of the Python stack.</p>
  444. <p>Note that in Python 3.12 and newer, the same C stack frame can be used for
  445. multiple Python stack frames. This means that <code class="docutils literal notranslate"><span class="pre">py-up</span></code> and <code class="docutils literal notranslate"><span class="pre">py-down</span></code>
  446. may move multiple Python frames at once. For example:</p>
  447. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-up
  448. #6 Frame 0x7ffff7fb62b0, for file /tmp/rec.py, line 5, in recursive_function (n=0)
  449. time.sleep(5)
  450. #6 Frame 0x7ffff7fb6240, for file /tmp/rec.py, line 7, in recursive_function (n=1)
  451. recursive_function(n-1)
  452. #6 Frame 0x7ffff7fb61d0, for file /tmp/rec.py, line 7, in recursive_function (n=2)
  453. recursive_function(n-1)
  454. #6 Frame 0x7ffff7fb6160, for file /tmp/rec.py, line 7, in recursive_function (n=3)
  455. recursive_function(n-1)
  456. #6 Frame 0x7ffff7fb60f0, for file /tmp/rec.py, line 7, in recursive_function (n=4)
  457. recursive_function(n-1)
  458. #6 Frame 0x7ffff7fb6080, for file /tmp/rec.py, line 7, in recursive_function (n=5)
  459. recursive_function(n-1)
  460. #6 Frame 0x7ffff7fb6020, for file /tmp/rec.py, line 9, in &lt;module&gt; ()
  461. recursive_function(5)
  462. (gdb) py-up
  463. Unable to find an older python frame
  464. </pre></div>
  465. </div>
  466. </div></blockquote>
  467. </section>
  468. <section id="py-bt">
  469. <h3><code class="docutils literal notranslate"><span class="pre">py-bt</span></code><a class="headerlink" href="#py-bt" title="Link to this heading">¶</a></h3>
  470. <blockquote>
  471. <div><p>The <code class="docutils literal notranslate"><span class="pre">py-bt</span></code> command attempts to display a Python-level backtrace of the
  472. current thread.</p>
  473. <p>For example:</p>
  474. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-bt
  475. #8 (unable to read python frame information)
  476. #11 Frame 0x9aead74, for file /usr/lib/python2.6/site-packages/gnome_sudoku/dialog_swallower.py, line 48, in run_dialog (self=&lt;SwappableArea(running=&lt;gtk.Dialog at remote 0x98faaa4&gt;, main_page=0) at remote 0x98fa6e4&gt;, d=&lt;gtk.Dialog at remote 0x98faaa4&gt;)
  477. gtk.main()
  478. #14 Frame 0x99262ac, for file /usr/lib/python2.6/site-packages/gnome_sudoku/game_selector.py, line 201, in run_swallowed_dialog (self=&lt;NewOrSavedGameSelector(new_game_model=&lt;gtk.ListStore at remote 0x98fab44&gt;, puzzle=None, saved_games=[{&#39;gsd.auto_fills&#39;: 0, &#39;tracking&#39;: {}, &#39;trackers&#39;: {}, &#39;notes&#39;: [], &#39;saved_at&#39;: 1270084485, &#39;game&#39;: &#39;7 8 0 0 0 0 0 5 6 0 0 9 0 8 0 1 0 0 0 4 6 0 0 0 0 7 0 6 5 0 0 0 4 7 9 2 0 0 0 9 0 1 0 0 0 3 9 7 6 0 0 0 1 8 0 6 0 0 0 0 2 8 0 0 0 5 0 4 0 6 0 0 2 1 0 0 0 0 0 4 5\n7 8 0 0 0 0 0 5 6 0 0 9 0 8 0 1 0 0 0 4 6 0 0 0 0 7 0 6 5 1 8 3 4 7 9 2 0 0 0 9 0 1 0 0 0 3 9 7 6 0 0 0 1 8 0 6 0 0 0 0 2 8 0 0 0 5 0 4 0 6 0 0 2 1 0 0 0 0 0 4 5&#39;, &#39;gsd.impossible_hints&#39;: 0, &#39;timer.__absolute_start_time__&#39;: &lt;float at remote 0x984b474&gt;, &#39;gsd.hints&#39;: 0, &#39;timer.active_time&#39;: &lt;float at remote 0x984b494&gt;, &#39;timer.total_time&#39;: &lt;float at remote 0x984b464&gt;}], dialog=&lt;gtk.Dialog at remote 0x98faaa4&gt;, saved_game_model=&lt;gtk.ListStore at remote 0x98fad24&gt;, sudoku_maker=&lt;SudokuMaker(terminated=False, played=[], batch_siz...(truncated)
  479. swallower.run_dialog(self.dialog)
  480. #19 (unable to read python frame information)
  481. #23 (unable to read python frame information)
  482. #34 (unable to read python frame information)
  483. #37 Frame 0x9420b04, for file /usr/lib/python2.6/site-packages/gnome_sudoku/main.py, line 906, in start_game ()
  484. u = UI()
  485. #40 Frame 0x948e82c, for file /usr/lib/python2.6/site-packages/gnome_sudoku/gnome_sudoku.py, line 22, in start_game (main=&lt;module at remote 0xb771b7f4&gt;)
  486. main.start_game()
  487. </pre></div>
  488. </div>
  489. <p>The frame numbers correspond to those displayed by GDB’s standard
  490. <code class="docutils literal notranslate"><span class="pre">backtrace</span></code> command.</p>
  491. </div></blockquote>
  492. </section>
  493. <section id="py-print">
  494. <h3><code class="docutils literal notranslate"><span class="pre">py-print</span></code><a class="headerlink" href="#py-print" title="Link to this heading">¶</a></h3>
  495. <blockquote>
  496. <div><p>The <code class="docutils literal notranslate"><span class="pre">py-print</span></code> command looks up a Python name and tries to print it.
  497. It looks in locals within the current thread, then globals, then finally
  498. builtins:</p>
  499. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-print self
  500. local &#39;self&#39; = &lt;SwappableArea(running=&lt;gtk.Dialog at remote 0x98faaa4&gt;,
  501. main_page=0) at remote 0x98fa6e4&gt;
  502. (gdb) py-print __name__
  503. global &#39;__name__&#39; = &#39;gnome_sudoku.dialog_swallower&#39;
  504. (gdb) py-print len
  505. builtin &#39;len&#39; = &lt;built-in function len&gt;
  506. (gdb) py-print scarlet_pimpernel
  507. &#39;scarlet_pimpernel&#39; not found
  508. </pre></div>
  509. </div>
  510. <p>If the current C frame corresponds to multiple Python frames, <code class="docutils literal notranslate"><span class="pre">py-print</span></code>
  511. only considers the first one.</p>
  512. </div></blockquote>
  513. </section>
  514. <section id="py-locals">
  515. <h3><code class="docutils literal notranslate"><span class="pre">py-locals</span></code><a class="headerlink" href="#py-locals" title="Link to this heading">¶</a></h3>
  516. <blockquote>
  517. <div><p>The <code class="docutils literal notranslate"><span class="pre">py-locals</span></code> command looks up all Python locals within the current
  518. Python frame in the selected thread, and prints their representations:</p>
  519. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-locals
  520. self = &lt;SwappableArea(running=&lt;gtk.Dialog at remote 0x98faaa4&gt;,
  521. main_page=0) at remote 0x98fa6e4&gt;
  522. d = &lt;gtk.Dialog at remote 0x98faaa4&gt;
  523. </pre></div>
  524. </div>
  525. <p>If the current C frame corresponds to multiple Python frames, locals from
  526. all of them will be shown:</p>
  527. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-locals
  528. Locals for recursive_function
  529. n = 0
  530. Locals for recursive_function
  531. n = 1
  532. Locals for recursive_function
  533. n = 2
  534. Locals for recursive_function
  535. n = 3
  536. Locals for recursive_function
  537. n = 4
  538. Locals for recursive_function
  539. n = 5
  540. Locals for &lt;module&gt;
  541. </pre></div>
  542. </div>
  543. </div></blockquote>
  544. </section>
  545. </section>
  546. <section id="use-with-gdb-commands">
  547. <h2>Use with GDB commands<a class="headerlink" href="#use-with-gdb-commands" title="Link to this heading">¶</a></h2>
  548. <p>The extension commands complement GDB’s built-in commands.
  549. For example, you can use a frame numbers shown by <code class="docutils literal notranslate"><span class="pre">py-bt</span></code> with the <code class="docutils literal notranslate"><span class="pre">frame</span></code>
  550. command to go a specific frame within the selected thread, like this:</p>
  551. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) py-bt
  552. (output snipped)
  553. #68 Frame 0xaa4560, for file Lib/test/regrtest.py, line 1548, in &lt;module&gt; ()
  554. main()
  555. (gdb) frame 68
  556. #68 0x00000000004cd1e6 in PyEval_EvalFrameEx (f=Frame 0xaa4560, for file Lib/test/regrtest.py, line 1548, in &lt;module&gt; (), throwflag=0) at Python/ceval.c:2665
  557. 2665 x = call_function(&amp;sp, oparg);
  558. (gdb) py-list
  559. 1543 # Run the tests in a context manager that temporary changes the CWD to a
  560. 1544 # temporary and writable directory. If it&#39;s not possible to create or
  561. 1545 # change the CWD, the original CWD will be used. The original CWD is
  562. 1546 # available from test_support.SAVEDCWD.
  563. 1547 with test_support.temp_cwd(TESTCWD, quiet=True):
  564. &gt;1548 main()
  565. </pre></div>
  566. </div>
  567. <p>The <code class="docutils literal notranslate"><span class="pre">info</span> <span class="pre">threads</span></code> command will give you a list of the threads within the
  568. process, and you can use the <code class="docutils literal notranslate"><span class="pre">thread</span></code> command to select a different one:</p>
  569. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) info threads
  570. 105 Thread 0x7fffefa18710 (LWP 10260) sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
  571. 104 Thread 0x7fffdf5fe710 (LWP 10259) sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
  572. * 1 Thread 0x7ffff7fe2700 (LWP 10145) 0x00000038e46d73e3 in select () at ../sysdeps/unix/syscall-template.S:82
  573. </pre></div>
  574. </div>
  575. <p>You can use <code class="docutils literal notranslate"><span class="pre">thread</span> <span class="pre">apply</span> <span class="pre">all</span> <span class="pre">COMMAND</span></code> or (<code class="docutils literal notranslate"><span class="pre">t</span> <span class="pre">a</span> <span class="pre">a</span> <span class="pre">COMMAND</span></code> for short) to run
  576. a command on all threads. With <code class="docutils literal notranslate"><span class="pre">py-bt</span></code>, this lets you see what every
  577. thread is doing at the Python level:</p>
  578. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) t a a py-bt
  579. Thread 105 (Thread 0x7fffefa18710 (LWP 10260)):
  580. #5 Frame 0x7fffd00019d0, for file /home/david/coding/python-svn/Lib/threading.py, line 155, in _acquire_restore (self=&lt;_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=&lt;thread.lock at remote 0x858770&gt;, _RLock__count=1) at remote 0xd7ff40&gt;, count_owner=(1, 140737213728528), count=1, owner=140737213728528)
  581. self.__block.acquire()
  582. #8 Frame 0x7fffac001640, for file /home/david/coding/python-svn/Lib/threading.py, line 269, in wait (self=&lt;_Condition(_Condition__lock=&lt;_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=&lt;thread.lock at remote 0x858770&gt;, _RLock__count=1) at remote 0xd7ff40&gt;, acquire=&lt;instancemethod at remote 0xd80260&gt;, _is_owned=&lt;instancemethod at remote 0xd80160&gt;, _release_save=&lt;instancemethod at remote 0xd803e0&gt;, release=&lt;instancemethod at remote 0xd802e0&gt;, _acquire_restore=&lt;instancemethod at remote 0xd7ee60&gt;, _Verbose__verbose=False, _Condition__waiters=[]) at remote 0xd7fd10&gt;, timeout=None, waiter=&lt;thread.lock at remote 0x858a90&gt;, saved_state=(1, 140737213728528))
  583. self._acquire_restore(saved_state)
  584. #12 Frame 0x7fffb8001a10, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 348, in f ()
  585. cond.wait()
  586. #16 Frame 0x7fffb8001c40, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 37, in task (tid=140737213728528)
  587. f()
  588. Thread 104 (Thread 0x7fffdf5fe710 (LWP 10259)):
  589. #5 Frame 0x7fffe4001580, for file /home/david/coding/python-svn/Lib/threading.py, line 155, in _acquire_restore (self=&lt;_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=&lt;thread.lock at remote 0x858770&gt;, _RLock__count=1) at remote 0xd7ff40&gt;, count_owner=(1, 140736940992272), count=1, owner=140736940992272)
  590. self.__block.acquire()
  591. #8 Frame 0x7fffc8002090, for file /home/david/coding/python-svn/Lib/threading.py, line 269, in wait (self=&lt;_Condition(_Condition__lock=&lt;_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=&lt;thread.lock at remote 0x858770&gt;, _RLock__count=1) at remote 0xd7ff40&gt;, acquire=&lt;instancemethod at remote 0xd80260&gt;, _is_owned=&lt;instancemethod at remote 0xd80160&gt;, _release_save=&lt;instancemethod at remote 0xd803e0&gt;, release=&lt;instancemethod at remote 0xd802e0&gt;, _acquire_restore=&lt;instancemethod at remote 0xd7ee60&gt;, _Verbose__verbose=False, _Condition__waiters=[]) at remote 0xd7fd10&gt;, timeout=None, waiter=&lt;thread.lock at remote 0x858860&gt;, saved_state=(1, 140736940992272))
  592. self._acquire_restore(saved_state)
  593. #12 Frame 0x7fffac001c90, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 348, in f ()
  594. cond.wait()
  595. #16 Frame 0x7fffac0011c0, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 37, in task (tid=140736940992272)
  596. f()
  597. Thread 1 (Thread 0x7ffff7fe2700 (LWP 10145)):
  598. #5 Frame 0xcb5380, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 16, in _wait ()
  599. time.sleep(0.01)
  600. #8 Frame 0x7fffd00024a0, for file /home/david/coding/python-svn/Lib/test/lock_tests.py, line 378, in _check_notify (self=&lt;ConditionTests(_testMethodName=&#39;test_notify&#39;, _resultForDoCleanups=&lt;TestResult(_original_stdout=&lt;cStringIO.StringO at remote 0xc191e0&gt;, skipped=[], _mirrorOutput=False, testsRun=39, buffer=False, _original_stderr=&lt;file at remote 0x7ffff7fc6340&gt;, _stdout_buffer=&lt;cStringIO.StringO at remote 0xc9c7f8&gt;, _stderr_buffer=&lt;cStringIO.StringO at remote 0xc9c790&gt;, _moduleSetUpFailed=False, expectedFailures=[], errors=[], _previousTestClass=&lt;type at remote 0x928310&gt;, unexpectedSuccesses=[], failures=[], shouldStop=False, failfast=False) at remote 0xc185a0&gt;, _threads=(0,), _cleanups=[], _type_equality_funcs={&lt;type at remote 0x7eba00&gt;: &lt;instancemethod at remote 0xd750e0&gt;, &lt;type at remote 0x7e7820&gt;: &lt;instancemethod at remote 0xd75160&gt;, &lt;type at remote 0x7e30e0&gt;: &lt;instancemethod at remote 0xd75060&gt;, &lt;type at remote 0x7e7d20&gt;: &lt;instancemethod at remote 0xd751e0&gt;, &lt;type at remote 0x7f19e0...(truncated)
  601. _wait()
  602. </pre></div>
  603. </div>
  604. </section>
  605. </section>
  606. <div class="clearer"></div>
  607. </div>
  608. </div>
  609. </div>
  610. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  611. <div class="sphinxsidebarwrapper">
  612. <div>
  613. <h3><a href="../contents.html">Table of Contents</a></h3>
  614. <ul>
  615. <li><a class="reference internal" href="#">Debugging C API extensions and CPython Internals with GDB</a><ul>
  616. <li><a class="reference internal" href="#prerequisites">Prerequisites</a><ul>
  617. <li><a class="reference internal" href="#setup-with-python-built-from-source">Setup with Python built from source</a></li>
  618. <li><a class="reference internal" href="#setup-for-python-from-a-linux-distro">Setup for Python from a Linux distro</a></li>
  619. </ul>
  620. </li>
  621. <li><a class="reference internal" href="#using-the-debug-build-and-development-mode">Using the Debug build and Development mode</a></li>
  622. <li><a class="reference internal" href="#using-the-python-gdb-extension">Using the <code class="docutils literal notranslate"><span class="pre">python-gdb</span></code> extension</a><ul>
  623. <li><a class="reference internal" href="#pretty-printers">Pretty-printers</a></li>
  624. <li><a class="reference internal" href="#py-list"><code class="docutils literal notranslate"><span class="pre">py-list</span></code></a></li>
  625. <li><a class="reference internal" href="#py-up-and-py-down"><code class="docutils literal notranslate"><span class="pre">py-up</span></code> and <code class="docutils literal notranslate"><span class="pre">py-down</span></code></a></li>
  626. <li><a class="reference internal" href="#py-bt"><code class="docutils literal notranslate"><span class="pre">py-bt</span></code></a></li>
  627. <li><a class="reference internal" href="#py-print"><code class="docutils literal notranslate"><span class="pre">py-print</span></code></a></li>
  628. <li><a class="reference internal" href="#py-locals"><code class="docutils literal notranslate"><span class="pre">py-locals</span></code></a></li>
  629. </ul>
  630. </li>
  631. <li><a class="reference internal" href="#use-with-gdb-commands">Use with GDB commands</a></li>
  632. </ul>
  633. </li>
  634. </ul>
  635. </div>
  636. <div>
  637. <h4>Previous topic</h4>
  638. <p class="topless"><a href="descriptor.html"
  639. title="previous chapter">Descriptor Guide</a></p>
  640. </div>
  641. <div>
  642. <h4>Next topic</h4>
  643. <p class="topless"><a href="enum.html"
  644. title="next chapter">Enum HOWTO</a></p>
  645. </div>
  646. <div role="note" aria-label="source link">
  647. <h3>This Page</h3>
  648. <ul class="this-page-menu">
  649. <li><a href="../bugs.html">Report a Bug</a></li>
  650. <li>
  651. <a href="https://github.com/python/cpython/blob/main/Doc/howto/gdb_helpers.rst"
  652. rel="nofollow">Show Source
  653. </a>
  654. </li>
  655. </ul>
  656. </div>
  657. </div>
  658. <div id="sidebarbutton" title="Collapse sidebar">
  659. <span>«</span>
  660. </div>
  661. </div>
  662. <div class="clearer"></div>
  663. </div>
  664. <div class="related" role="navigation" aria-label="related navigation">
  665. <h3>Navigation</h3>
  666. <ul>
  667. <li class="right" style="margin-right: 10px">
  668. <a href="../genindex.html" title="General Index"
  669. >index</a></li>
  670. <li class="right" >
  671. <a href="../py-modindex.html" title="Python Module Index"
  672. >modules</a> |</li>
  673. <li class="right" >
  674. <a href="enum.html" title="Enum HOWTO"
  675. >next</a> |</li>
  676. <li class="right" >
  677. <a href="descriptor.html" title="Descriptor Guide"
  678. >previous</a> |</li>
  679. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  680. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  681. <li class="switchers">
  682. <div class="language_switcher_placeholder"></div>
  683. <div class="version_switcher_placeholder"></div>
  684. </li>
  685. <li>
  686. </li>
  687. <li id="cpython-language-and-version">
  688. <a href="../index.html">3.12.3 Documentation</a> &#187;
  689. </li>
  690. <li class="nav-item nav-item-1"><a href="index.html" >Python HOWTOs</a> &#187;</li>
  691. <li class="nav-item nav-item-this"><a href="">Debugging C API extensions and CPython Internals with GDB</a></li>
  692. <li class="right">
  693. <div class="inline-search" role="search">
  694. <form class="inline-search" action="../search.html" method="get">
  695. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  696. <input type="submit" value="Go" />
  697. </form>
  698. </div>
  699. |
  700. </li>
  701. <li class="right">
  702. <label class="theme-selector-label">
  703. Theme
  704. <select class="theme-selector" oninput="activateTheme(this.value)">
  705. <option value="auto" selected>Auto</option>
  706. <option value="light">Light</option>
  707. <option value="dark">Dark</option>
  708. </select>
  709. </label> |</li>
  710. </ul>
  711. </div>
  712. <div class="footer">
  713. &copy;
  714. <a href="../copyright.html">
  715. Copyright
  716. </a>
  717. 2001-2024, Python Software Foundation.
  718. <br />
  719. This page is licensed under the Python Software Foundation License Version 2.
  720. <br />
  721. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  722. <br />
  723. See <a href="/license.html">History and License</a> for more information.<br />
  724. <br />
  725. The Python Software Foundation is a non-profit corporation.
  726. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  727. <br />
  728. <br />
  729. Last updated on Apr 09, 2024 (13:47 UTC).
  730. <a href="/bugs.html">Found a bug</a>?
  731. <br />
  732. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  733. </div>
  734. </body>
  735. </html>
上海开阖软件有限公司 沪ICP备12045867号-1