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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Auto Display</title> 18 19<meta name="description" content="Debugging with GDB: Auto Display"> 20<meta name="keywords" content="Debugging with GDB: Auto Display"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Data.html#Data" rel="up" title="Data"> 29<link href="Print-Settings.html#Print-Settings" rel="next" title="Print Settings"> 30<link href="Memory.html#Memory" rel="previous" title="Memory"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Auto-Display"></a> 65<div class="header"> 66<p> 67Next: <a href="Print-Settings.html#Print-Settings" accesskey="n" rel="next">Print Settings</a>, Previous: <a href="Memory.html#Memory" accesskey="p" rel="previous">Memory</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</a> [<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> 68</div> 69<hr> 70<a name="Automatic-Display"></a> 71<h3 class="section">10.7 Automatic Display</h3> 72<a name="index-automatic-display"></a> 73<a name="index-display-of-expressions"></a> 74 75<p>If you find that you want to print the value of an expression frequently 76(to see how it changes), you might want to add it to the <em>automatic 77display list</em> so that <small>GDB</small> prints its value each time your program stops. 78Each expression added to the list is given a number to identify it; 79to remove an expression from the list, you specify that number. 80The automatic display looks like this: 81</p> 82<div class="smallexample"> 83<pre class="smallexample">2: foo = 38 843: bar[5] = (struct hack *) 0x3804 85</pre></div> 86 87<p>This display shows item numbers, expressions and their current values. As with 88displays you request manually using <code>x</code> or <code>print</code>, you can 89specify the output format you prefer; in fact, <code>display</code> decides 90whether to use <code>print</code> or <code>x</code> depending your format 91specification—it uses <code>x</code> if you specify either the ‘<samp>i</samp>’ 92or ‘<samp>s</samp>’ format, or a unit size; otherwise it uses <code>print</code>. 93</p> 94<dl compact="compact"> 95<dd><a name="index-display"></a> 96</dd> 97<dt><code>display <var>expr</var></code></dt> 98<dd><p>Add the expression <var>expr</var> to the list of expressions to display 99each time your program stops. See <a href="Expressions.html#Expressions">Expressions</a>. 100</p> 101<p><code>display</code> does not repeat if you press <tt class="key">RET</tt> again after using it. 102</p> 103</dd> 104<dt><code>display/<var>fmt</var> <var>expr</var></code></dt> 105<dd><p>For <var>fmt</var> specifying only a display format and not a size or 106count, add the expression <var>expr</var> to the auto-display list but 107arrange to display it each time in the specified format <var>fmt</var>. 108See <a href="Output-Formats.html#Output-Formats">Output Formats</a>. 109</p> 110</dd> 111<dt><code>display/<var>fmt</var> <var>addr</var></code></dt> 112<dd><p>For <var>fmt</var> ‘<samp>i</samp>’ or ‘<samp>s</samp>’, or including a unit-size or a 113number of units, add the expression <var>addr</var> as a memory address to 114be examined each time your program stops. Examining means in effect 115doing ‘<samp>x/<var>fmt</var> <var>addr</var></samp>’. See <a href="Memory.html#Memory">Examining Memory</a>. 116</p></dd> 117</dl> 118 119<p>For example, ‘<samp>display/i $pc</samp>’ can be helpful, to see the machine 120instruction about to be executed each time execution stops (‘<samp>$pc</samp>’ 121is a common name for the program counter; see <a href="Registers.html#Registers">Registers</a>). 122</p> 123<dl compact="compact"> 124<dd><a name="index-delete-display"></a> 125<a name="index-undisplay"></a> 126</dd> 127<dt><code>undisplay <var>dnums</var>…</code></dt> 128<dt><code>delete display <var>dnums</var>…</code></dt> 129<dd><p>Remove items from the list of expressions to display. Specify the 130numbers of the displays that you want affected with the command 131argument <var>dnums</var>. It can be a single display number, one of the 132numbers shown in the first field of the ‘<samp>info display</samp>’ display; 133or it could be a range of display numbers, as in <code>2-4</code>. 134</p> 135<p><code>undisplay</code> does not repeat if you press <tt class="key">RET</tt> after using it. 136(Otherwise you would just get the error ‘<samp>No display number …</samp>’.) 137</p> 138<a name="index-disable-display"></a> 139</dd> 140<dt><code>disable display <var>dnums</var>…</code></dt> 141<dd><p>Disable the display of item numbers <var>dnums</var>. A disabled display 142item is not printed automatically, but is not forgotten. It may be 143enabled again later. Specify the numbers of the displays that you 144want affected with the command argument <var>dnums</var>. It can be a 145single display number, one of the numbers shown in the first field of 146the ‘<samp>info display</samp>’ display; or it could be a range of display 147numbers, as in <code>2-4</code>. 148</p> 149<a name="index-enable-display"></a> 150</dd> 151<dt><code>enable display <var>dnums</var>…</code></dt> 152<dd><p>Enable display of item numbers <var>dnums</var>. It becomes effective once 153again in auto display of its expression, until you specify otherwise. 154Specify the numbers of the displays that you want affected with the 155command argument <var>dnums</var>. It can be a single display number, one 156of the numbers shown in the first field of the ‘<samp>info display</samp>’ 157display; or it could be a range of display numbers, as in <code>2-4</code>. 158</p> 159</dd> 160<dt><code>display</code></dt> 161<dd><p>Display the current values of the expressions on the list, just as is 162done when your program stops. 163</p> 164<a name="index-info-display"></a> 165</dd> 166<dt><code>info display</code></dt> 167<dd><p>Print the list of expressions previously set up to display 168automatically, each one with its item number, but without showing the 169values. This includes disabled expressions, which are marked as such. 170It also includes expressions which would not be displayed right now 171because they refer to automatic variables not currently available. 172</p></dd> 173</dl> 174 175<a name="index-display-disabled-out-of-scope"></a> 176<p>If a display expression refers to local variables, then it does not make 177sense outside the lexical context for which it was set up. Such an 178expression is disabled when execution enters a context where one of its 179variables is not defined. For example, if you give the command 180<code>display last_char</code> while inside a function with an argument 181<code>last_char</code>, <small>GDB</small> displays this argument while your program 182continues to stop inside that function. When it stops elsewhere—where 183there is no variable <code>last_char</code>—the display is disabled 184automatically. The next time your program stops where <code>last_char</code> 185is meaningful, you can enable the display expression once again. 186</p> 187<hr> 188<div class="header"> 189<p> 190Next: <a href="Print-Settings.html#Print-Settings" accesskey="n" rel="next">Print Settings</a>, Previous: <a href="Memory.html#Memory" accesskey="p" rel="previous">Memory</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</a> [<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> 191</div> 192 193 194 195</body> 196</html> 197