You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
8.3KB

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