Output-Formats.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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: Output Formats</title>
  16. <meta name="description" content="Debugging with GDB: Output Formats">
  17. <meta name="keywords" content="Debugging with GDB: Output Formats">
  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="Memory.html#Memory" rel="next" title="Memory">
  27. <link href="Arrays.html#Arrays" rel="previous" title="Arrays">
  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="Output-Formats"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Memory.html#Memory" accesskey="n" rel="next">Memory</a>, Previous: <a href="Arrays.html#Arrays" accesskey="p" rel="previous">Arrays</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="Output-Formats-1"></a>
  65. <h3 class="section">10.5 Output Formats</h3>
  66. <a name="index-formatted-output"></a>
  67. <a name="index-output-formats"></a>
  68. <p>By default, <small>GDB</small> prints a value according to its data type. Sometimes
  69. this is not what you want. For example, you might want to print a number
  70. in hex, or a pointer in decimal. Or you might want to view data in memory
  71. at a certain address as a character string or as an instruction. To do
  72. these things, specify an <em>output format</em> when you print a value.
  73. </p>
  74. <p>The simplest use of output formats is to say how to print a value
  75. already computed. This is done by starting the arguments of the
  76. <code>print</code> command with a slash and a format letter. The format
  77. letters supported are:
  78. </p>
  79. <dl compact="compact">
  80. <dt><code>x</code></dt>
  81. <dd><p>Regard the bits of the value as an integer, and print the integer in
  82. hexadecimal.
  83. </p>
  84. </dd>
  85. <dt><code>d</code></dt>
  86. <dd><p>Print as integer in signed decimal.
  87. </p>
  88. </dd>
  89. <dt><code>u</code></dt>
  90. <dd><p>Print as integer in unsigned decimal.
  91. </p>
  92. </dd>
  93. <dt><code>o</code></dt>
  94. <dd><p>Print as integer in octal.
  95. </p>
  96. </dd>
  97. <dt><code>t</code></dt>
  98. <dd><p>Print as integer in binary. The letter &lsquo;<samp>t</samp>&rsquo; stands for &ldquo;two&rdquo;.
  99. <a name="DOCF11" href="#FOOT11"><sup>11</sup></a>
  100. </p>
  101. </dd>
  102. <dt><code>a</code></dt>
  103. <dd><a name="index-unknown-address_002c-locating"></a>
  104. <a name="index-locate-address"></a>
  105. <p>Print as an address, both absolute in hexadecimal and as an offset from
  106. the nearest preceding symbol. You can use this format used to discover
  107. where (in what function) an unknown address is located:
  108. </p>
  109. <div class="smallexample">
  110. <pre class="smallexample">(gdb) p/a 0x54320
  111. $3 = 0x54320 &lt;_initialize_vx+396&gt;
  112. </pre></div>
  113. <p>The command <code>info symbol 0x54320</code> yields similar results.
  114. See <a href="Symbols.html#Symbols">info symbol</a>.
  115. </p>
  116. </dd>
  117. <dt><code>c</code></dt>
  118. <dd><p>Regard as an integer and print it as a character constant. This
  119. prints both the numerical value and its character representation. The
  120. character representation is replaced with the octal escape &lsquo;<samp>\nnn</samp>&rsquo;
  121. for characters outside the 7-bit <small>ASCII</small> range.
  122. </p>
  123. <p>Without this format, <small>GDB</small> displays <code>char</code>,
  124. <code>unsigned&nbsp;char</code><!-- /@w -->, and <code>signed&nbsp;char</code><!-- /@w --> data as character
  125. constants. Single-byte members of vectors are displayed as integer
  126. data.
  127. </p>
  128. </dd>
  129. <dt><code>f</code></dt>
  130. <dd><p>Regard the bits of the value as a floating point number and print
  131. using typical floating point syntax.
  132. </p>
  133. </dd>
  134. <dt><code>s</code></dt>
  135. <dd><a name="index-printing-strings"></a>
  136. <a name="index-printing-byte-arrays"></a>
  137. <p>Regard as a string, if possible. With this format, pointers to single-byte
  138. data are displayed as null-terminated strings and arrays of single-byte data
  139. are displayed as fixed-length strings. Other values are displayed in their
  140. natural types.
  141. </p>
  142. <p>Without this format, <small>GDB</small> displays pointers to and arrays of
  143. <code>char</code>, <code>unsigned&nbsp;char</code><!-- /@w -->, and <code>signed&nbsp;char</code><!-- /@w --> as
  144. strings. Single-byte members of a vector are displayed as an integer
  145. array.
  146. </p>
  147. </dd>
  148. <dt><code>z</code></dt>
  149. <dd><p>Like &lsquo;<samp>x</samp>&rsquo; formatting, the value is treated as an integer and
  150. printed as hexadecimal, but leading zeros are printed to pad the value
  151. to the size of the integer type.
  152. </p>
  153. </dd>
  154. <dt><code>r</code></dt>
  155. <dd><a name="index-raw-printing"></a>
  156. <p>Print using the &lsquo;<samp>raw</samp>&rsquo; formatting. By default, <small>GDB</small> will
  157. use a Python-based pretty-printer, if one is available (see <a href="Pretty-Printing.html#Pretty-Printing">Pretty Printing</a>). This typically results in a higher-level display of the
  158. value&rsquo;s contents. The &lsquo;<samp>r</samp>&rsquo; format bypasses any Python
  159. pretty-printer which might exist.
  160. </p></dd>
  161. </dl>
  162. <p>For example, to print the program counter in hex (see <a href="Registers.html#Registers">Registers</a>), type
  163. </p>
  164. <div class="smallexample">
  165. <pre class="smallexample">p/x $pc
  166. </pre></div>
  167. <p>Note that no space is required before the slash; this is because command
  168. names in <small>GDB</small> cannot contain a slash.
  169. </p>
  170. <p>To reprint the last value in the value history with a different format,
  171. you can use the <code>print</code> command with just a format and no
  172. expression. For example, &lsquo;<samp>p/x</samp>&rsquo; reprints the last value in hex.
  173. </p>
  174. <div class="footnote">
  175. <hr>
  176. <h4 class="footnotes-heading">Footnotes</h4>
  177. <h3><a name="FOOT11" href="#DOCF11">(11)</a></h3>
  178. <p>&lsquo;<samp>b</samp>&rsquo; cannot be used because these format letters are also
  179. used with the <code>x</code> command, where &lsquo;<samp>b</samp>&rsquo; stands for &ldquo;byte&rdquo;;
  180. see <a href="Memory.html#Memory">Examining Memory</a>.</p>
  181. </div>
  182. <hr>
  183. <div class="header">
  184. <p>
  185. Next: <a href="Memory.html#Memory" accesskey="n" rel="next">Memory</a>, Previous: <a href="Arrays.html#Arrays" accesskey="p" rel="previous">Arrays</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>
  186. </div>
  187. </body>
  188. </html>