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.

140 lines
6.9KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Selecting Pretty-Printers (Debugging with GDB)</title>
  17. <meta name="description" content="Selecting Pretty-Printers (Debugging with GDB)">
  18. <meta name="keywords" content="Selecting Pretty-Printers (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Python-API.html#Python-API" rel="up" title="Python API">
  26. <link href="Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter" rel="next" title="Writing a Pretty-Printer">
  27. <link href="Pretty-Printing-API.html#Pretty-Printing-API" rel="prev" title="Pretty Printing API">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Selecting-Pretty_002dPrinters"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter" accesskey="n" rel="next">Writing a Pretty-Printer</a>, Previous: <a href="Pretty-Printing-API.html#Pretty-Printing-API" accesskey="p" rel="prev">Pretty Printing API</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Selecting-Pretty_002dPrinters-1"></a>
  64. <h4 class="subsubsection">23.2.2.6 Selecting Pretty-Printers</h4>
  65. <a name="index-selecting-python-pretty_002dprinters"></a>
  66. <p><small>GDB</small> provides several ways to register a pretty-printer:
  67. globally, per program space, and per objfile. When choosing how to
  68. register your pretty-printer, a good rule is to register it with the
  69. smallest scope possible: that is prefer a specific objfile first, then
  70. a program space, and only register a printer globally as a last
  71. resort.
  72. </p>
  73. <a name="index-gdb_002epretty_005fprinters"></a>
  74. <dl>
  75. <dt><a name="index-gdb_002epretty_005fprinters-1"></a>Variable: <strong>gdb.pretty_printers</strong></dt>
  76. <dd><p>The Python list <code>gdb.pretty_printers</code> contains an array of
  77. functions or callable objects that have been registered via addition
  78. as a pretty-printer. Printers in this list are called <code>global</code>
  79. printers, they&rsquo;re available when debugging all inferiors.
  80. </p></dd></dl>
  81. <p>Each <code>gdb.Progspace</code> contains a <code>pretty_printers</code> attribute.
  82. Each <code>gdb.Objfile</code> also contains a <code>pretty_printers</code>
  83. attribute.
  84. </p>
  85. <p>Each function on these lists is passed a single <code>gdb.Value</code>
  86. argument and should return a pretty-printer object conforming to the
  87. interface definition above (see <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>). If a function
  88. cannot create a pretty-printer for the value, it should return
  89. <code>None</code>.
  90. </p>
  91. <p><small>GDB</small> first checks the <code>pretty_printers</code> attribute of each
  92. <code>gdb.Objfile</code> in the current program space and iteratively calls
  93. each enabled lookup routine in the list for that <code>gdb.Objfile</code>
  94. until it receives a pretty-printer object.
  95. If no pretty-printer is found in the objfile lists, <small>GDB</small> then
  96. searches the pretty-printer list of the current program space,
  97. calling each enabled function until an object is returned.
  98. After these lists have been exhausted, it tries the global
  99. <code>gdb.pretty_printers</code> list, again calling each enabled function until an
  100. object is returned.
  101. </p>
  102. <p>The order in which the objfiles are searched is not specified. For a
  103. given list, functions are always invoked from the head of the list,
  104. and iterated over sequentially until the end of the list, or a printer
  105. object is returned.
  106. </p>
  107. <p>For various reasons a pretty-printer may not work.
  108. For example, the underlying data structure may have changed and
  109. the pretty-printer is out of date.
  110. </p>
  111. <p>The consequences of a broken pretty-printer are severe enough that
  112. <small>GDB</small> provides support for enabling and disabling individual
  113. printers. For example, if <code>print frame-arguments</code> is on,
  114. a backtrace can become highly illegible if any argument is printed
  115. with a broken printer.
  116. </p>
  117. <p>Pretty-printers are enabled and disabled by attaching an <code>enabled</code>
  118. attribute to the registered function or callable object. If this attribute
  119. is present and its value is <code>False</code>, the printer is disabled, otherwise
  120. the printer is enabled.
  121. </p>
  122. <hr>
  123. <div class="header">
  124. <p>
  125. Next: <a href="Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter" accesskey="n" rel="next">Writing a Pretty-Printer</a>, Previous: <a href="Pretty-Printing-API.html#Pretty-Printing-API" accesskey="p" rel="prev">Pretty Printing API</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  126. </div>
  127. </body>
  128. </html>