1<html lang="en"> 2<head> 3<title>Selecting Pretty-Printers - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Python-API.html#Python-API" title="Python API"> 9<link rel="prev" href="Pretty-Printing-API.html#Pretty-Printing-API" title="Pretty Printing API"> 10<link rel="next" href="Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter" title="Writing a Pretty-Printer"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988-2013 Free Software Foundation, Inc. 14 15Permission is granted to copy, distribute and/or modify this document 16under the terms of the GNU Free Documentation License, Version 1.3 or 17any later version published by the Free Software Foundation; with the 18Invariant Sections being ``Free Software'' and ``Free Software Needs 19Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 20and with the Back-Cover Texts as in (a) below. 21 22(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 23this GNU Manual. Buying copies from GNU Press supports the FSF in 24developing GNU and promoting software freedom.'' 25--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Selecting-Pretty-Printers"></a> 43<a name="Selecting-Pretty_002dPrinters"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter">Writing a Pretty-Printer</a>, 46Previous: <a rel="previous" accesskey="p" href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>, 47Up: <a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a> 48<hr> 49</div> 50 51<h5 class="subsubsection">23.2.2.6 Selecting Pretty-Printers</h5> 52 53<p>The Python list <code>gdb.pretty_printers</code> contains an array of 54functions or callable objects that have been registered via addition 55as a pretty-printer. Printers in this list are called <code>global</code> 56printers, they're available when debugging all inferiors. 57Each <code>gdb.Progspace</code> contains a <code>pretty_printers</code> attribute. 58Each <code>gdb.Objfile</code> also contains a <code>pretty_printers</code> 59attribute. 60 61 <p>Each function on these lists is passed a single <code>gdb.Value</code> 62argument and should return a pretty-printer object conforming to the 63interface definition above (see <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>). If a function 64cannot create a pretty-printer for the value, it should return 65<code>None</code>. 66 67 <p><span class="sc">gdb</span> first checks the <code>pretty_printers</code> attribute of each 68<code>gdb.Objfile</code> in the current program space and iteratively calls 69each enabled lookup routine in the list for that <code>gdb.Objfile</code> 70until it receives a pretty-printer object. 71If no pretty-printer is found in the objfile lists, <span class="sc">gdb</span> then 72searches the pretty-printer list of the current program space, 73calling each enabled function until an object is returned. 74After these lists have been exhausted, it tries the global 75<code>gdb.pretty_printers</code> list, again calling each enabled function until an 76object is returned. 77 78 <p>The order in which the objfiles are searched is not specified. For a 79given list, functions are always invoked from the head of the list, 80and iterated over sequentially until the end of the list, or a printer 81object is returned. 82 83 <p>For various reasons a pretty-printer may not work. 84For example, the underlying data structure may have changed and 85the pretty-printer is out of date. 86 87 <p>The consequences of a broken pretty-printer are severe enough that 88<span class="sc">gdb</span> provides support for enabling and disabling individual 89printers. For example, if <code>print frame-arguments</code> is on, 90a backtrace can become highly illegible if any argument is printed 91with a broken printer. 92 93 <p>Pretty-printers are enabled and disabled by attaching an <code>enabled</code> 94attribute to the registered function or callable object. If this attribute 95is present and its value is <code>False</code>, the printer is disabled, otherwise 96the printer is enabled. 97 98 </body></html> 99 100