Auto-Display.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: Auto Display</title>
  16. <meta name="description" content="Debugging with GDB: Auto Display">
  17. <meta name="keywords" content="Debugging with GDB: Auto Display">
  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="Data.html#Data" rel="up" title="Data">
  26. <link href="Print-Settings.html#Print-Settings" rel="next" title="Print Settings">
  27. <link href="Memory.html#Memory" rel="previous" title="Memory">
  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="Auto-Display"></a>
  59. <div class="header">
  60. <p>
  61. Next: <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> &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="Automatic-Display"></a>
  65. <h3 class="section">10.7 Automatic Display</h3>
  66. <a name="index-automatic-display"></a>
  67. <a name="index-display-of-expressions"></a>
  68. <p>If you find that you want to print the value of an expression frequently
  69. (to see how it changes), you might want to add it to the <em>automatic
  70. display list</em> so that <small>GDB</small> prints its value each time your program stops.
  71. Each expression added to the list is given a number to identify it;
  72. to remove an expression from the list, you specify that number.
  73. The automatic display looks like this:
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">2: foo = 38
  77. 3: bar[5] = (struct hack *) 0x3804
  78. </pre></div>
  79. <p>This display shows item numbers, expressions and their current values. As with
  80. displays you request manually using <code>x</code> or <code>print</code>, you can
  81. specify the output format you prefer; in fact, <code>display</code> decides
  82. whether to use <code>print</code> or <code>x</code> depending your format
  83. specification&mdash;it uses <code>x</code> if you specify either the &lsquo;<samp>i</samp>&rsquo;
  84. or &lsquo;<samp>s</samp>&rsquo; format, or a unit size; otherwise it uses <code>print</code>.
  85. </p>
  86. <dl compact="compact">
  87. <dd><a name="index-display"></a>
  88. </dd>
  89. <dt><code>display <var>expr</var></code></dt>
  90. <dd><p>Add the expression <var>expr</var> to the list of expressions to display
  91. each time your program stops. See <a href="Expressions.html#Expressions">Expressions</a>.
  92. </p>
  93. <p><code>display</code> does not repeat if you press <tt class="key">RET</tt> again after using it.
  94. </p>
  95. </dd>
  96. <dt><code>display/<var>fmt</var> <var>expr</var></code></dt>
  97. <dd><p>For <var>fmt</var> specifying only a display format and not a size or
  98. count, add the expression <var>expr</var> to the auto-display list but
  99. arrange to display it each time in the specified format <var>fmt</var>.
  100. See <a href="Output-Formats.html#Output-Formats">Output Formats</a>.
  101. </p>
  102. </dd>
  103. <dt><code>display/<var>fmt</var> <var>addr</var></code></dt>
  104. <dd><p>For <var>fmt</var> &lsquo;<samp>i</samp>&rsquo; or &lsquo;<samp>s</samp>&rsquo;, or including a unit-size or a
  105. number of units, add the expression <var>addr</var> as a memory address to
  106. be examined each time your program stops. Examining means in effect
  107. doing &lsquo;<samp>x/<var>fmt</var> <var>addr</var></samp>&rsquo;. See <a href="Memory.html#Memory">Examining Memory</a>.
  108. </p></dd>
  109. </dl>
  110. <p>For example, &lsquo;<samp>display/i $pc</samp>&rsquo; can be helpful, to see the machine
  111. instruction about to be executed each time execution stops (&lsquo;<samp>$pc</samp>&rsquo;
  112. is a common name for the program counter; see <a href="Registers.html#Registers">Registers</a>).
  113. </p>
  114. <dl compact="compact">
  115. <dd><a name="index-delete-display"></a>
  116. <a name="index-undisplay"></a>
  117. </dd>
  118. <dt><code>undisplay <var>dnums</var>&hellip;</code></dt>
  119. <dt><code>delete display <var>dnums</var>&hellip;</code></dt>
  120. <dd><p>Remove items from the list of expressions to display. Specify the
  121. numbers of the displays that you want affected with the command
  122. argument <var>dnums</var>. It can be a single display number, one of the
  123. numbers shown in the first field of the &lsquo;<samp>info display</samp>&rsquo; display;
  124. or it could be a range of display numbers, as in <code>2-4</code>.
  125. </p>
  126. <p><code>undisplay</code> does not repeat if you press <tt class="key">RET</tt> after using it.
  127. (Otherwise you would just get the error &lsquo;<samp>No display number &hellip;</samp>&rsquo;.)
  128. </p>
  129. <a name="index-disable-display"></a>
  130. </dd>
  131. <dt><code>disable display <var>dnums</var>&hellip;</code></dt>
  132. <dd><p>Disable the display of item numbers <var>dnums</var>. A disabled display
  133. item is not printed automatically, but is not forgotten. It may be
  134. enabled again later. Specify the numbers of the displays that you
  135. want affected with the command argument <var>dnums</var>. It can be a
  136. single display number, one of the numbers shown in the first field of
  137. the &lsquo;<samp>info display</samp>&rsquo; display; or it could be a range of display
  138. numbers, as in <code>2-4</code>.
  139. </p>
  140. <a name="index-enable-display"></a>
  141. </dd>
  142. <dt><code>enable display <var>dnums</var>&hellip;</code></dt>
  143. <dd><p>Enable display of item numbers <var>dnums</var>. It becomes effective once
  144. again in auto display of its expression, until you specify otherwise.
  145. Specify the numbers of the displays that you want affected with the
  146. command argument <var>dnums</var>. It can be a single display number, one
  147. of the numbers shown in the first field of the &lsquo;<samp>info display</samp>&rsquo;
  148. display; or it could be a range of display numbers, as in <code>2-4</code>.
  149. </p>
  150. </dd>
  151. <dt><code>display</code></dt>
  152. <dd><p>Display the current values of the expressions on the list, just as is
  153. done when your program stops.
  154. </p>
  155. <a name="index-info-display"></a>
  156. </dd>
  157. <dt><code>info display</code></dt>
  158. <dd><p>Print the list of expressions previously set up to display
  159. automatically, each one with its item number, but without showing the
  160. values. This includes disabled expressions, which are marked as such.
  161. It also includes expressions which would not be displayed right now
  162. because they refer to automatic variables not currently available.
  163. </p></dd>
  164. </dl>
  165. <a name="index-display-disabled-out-of-scope"></a>
  166. <p>If a display expression refers to local variables, then it does not make
  167. sense outside the lexical context for which it was set up. Such an
  168. expression is disabled when execution enters a context where one of its
  169. variables is not defined. For example, if you give the command
  170. <code>display last_char</code> while inside a function with an argument
  171. <code>last_char</code>, <small>GDB</small> displays this argument while your program
  172. continues to stop inside that function. When it stops elsewhere&mdash;where
  173. there is no variable <code>last_char</code>&mdash;the display is disabled
  174. automatically. The next time your program stops where <code>last_char</code>
  175. is meaningful, you can enable the display expression once again.
  176. </p>
  177. <hr>
  178. <div class="header">
  179. <p>
  180. Next: <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> &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>
  181. </div>
  182. </body>
  183. </html>