Selecting-Pretty_002dPrinters.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Selecting Pretty-Printers</title>
  16. <meta name="description" content="Debugging with GDB: Selecting Pretty-Printers">
  17. <meta name="keywords" content="Debugging with GDB: Selecting Pretty-Printers">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="previous" title="Pretty Printing API">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Selecting-Pretty_002dPrinters"></a>
  59. <div class="header">
  60. <p>
  61. 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="previous">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>
  62. </div>
  63. <hr>
  64. <a name="Selecting-Pretty_002dPrinters-1"></a>
  65. <h4 class="subsubsection">23.2.2.6 Selecting Pretty-Printers</h4>
  66. <a name="index-selecting-python-pretty_002dprinters"></a>
  67. <p><small>GDB</small> provides several ways to register a pretty-printer:
  68. globally, per program space, and per objfile. When choosing how to
  69. register your pretty-printer, a good rule is to register it with the
  70. smallest scope possible: that is prefer a specific objfile first, then
  71. a program space, and only register a printer globally as a last
  72. resort.
  73. </p>
  74. <a name="index-gdb_002epretty_005fprinters"></a>
  75. <dl>
  76. <dt><a name="index-gdb_002epretty_005fprinters-1"></a>Variable: <strong>gdb.pretty_printers</strong></dt>
  77. <dd><p>The Python list <code>gdb.pretty_printers</code> contains an array of
  78. functions or callable objects that have been registered via addition
  79. as a pretty-printer. Printers in this list are called <code>global</code>
  80. printers, they&rsquo;re available when debugging all inferiors.
  81. </p></dd></dl>
  82. <p>Each <code>gdb.Progspace</code> contains a <code>pretty_printers</code> attribute.
  83. Each <code>gdb.Objfile</code> also contains a <code>pretty_printers</code>
  84. attribute.
  85. </p>
  86. <p>Each function on these lists is passed a single <code>gdb.Value</code>
  87. argument and should return a pretty-printer object conforming to the
  88. interface definition above (see <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>). If a function
  89. cannot create a pretty-printer for the value, it should return
  90. <code>None</code>.
  91. </p>
  92. <p><small>GDB</small> first checks the <code>pretty_printers</code> attribute of each
  93. <code>gdb.Objfile</code> in the current program space and iteratively calls
  94. each enabled lookup routine in the list for that <code>gdb.Objfile</code>
  95. until it receives a pretty-printer object.
  96. If no pretty-printer is found in the objfile lists, <small>GDB</small> then
  97. searches the pretty-printer list of the current program space,
  98. calling each enabled function until an object is returned.
  99. After these lists have been exhausted, it tries the global
  100. <code>gdb.pretty_printers</code> list, again calling each enabled function until an
  101. object is returned.
  102. </p>
  103. <p>The order in which the objfiles are searched is not specified. For a
  104. given list, functions are always invoked from the head of the list,
  105. and iterated over sequentially until the end of the list, or a printer
  106. object is returned.
  107. </p>
  108. <p>For various reasons a pretty-printer may not work.
  109. For example, the underlying data structure may have changed and
  110. the pretty-printer is out of date.
  111. </p>
  112. <p>The consequences of a broken pretty-printer are severe enough that
  113. <small>GDB</small> provides support for enabling and disabling individual
  114. printers. For example, if <code>print frame-arguments</code> is on,
  115. a backtrace can become highly illegible if any argument is printed
  116. with a broken printer.
  117. </p>
  118. <p>Pretty-printers are enabled and disabled by attaching an <code>enabled</code>
  119. attribute to the registered function or callable object. If this attribute
  120. is present and its value is <code>False</code>, the printer is disabled, otherwise
  121. the printer is enabled.
  122. </p>
  123. <hr>
  124. <div class="header">
  125. <p>
  126. 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="previous">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>
  127. </div>
  128. </body>
  129. </html>