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.

191 lines
7.7KB

  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>Searching Memory (Debugging with GDB)</title>
  17. <meta name="description" content="Searching Memory (Debugging with GDB)">
  18. <meta name="keywords" content="Searching Memory (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="Value-Sizes.html#Value-Sizes" rel="next" title="Value Sizes">
  27. <link href="Caching-Target-Data.html#Caching-Target-Data" rel="prev" title="Caching Target Data">
  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="Searching-Memory"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Value-Sizes.html#Value-Sizes" accesskey="n" rel="next">Value Sizes</a>, Previous: <a href="Caching-Target-Data.html#Caching-Target-Data" accesskey="p" rel="prev">Caching Target Data</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="Search-Memory"></a>
  64. <h3 class="section">10.22 Search Memory</h3>
  65. <a name="index-searching-memory"></a>
  66. <p>Memory can be searched for a particular sequence of bytes with the
  67. <code>find</code> command.
  68. </p>
  69. <dl compact="compact">
  70. <dd><a name="index-find"></a>
  71. </dd>
  72. <dt><code>find <span class="roman">[</span>/<var>sn</var><span class="roman">]</span> <var>start_addr</var>, +<var>len</var>, <var>val1</var> <span class="roman">[</span>, <var>val2</var>, &hellip;<span class="roman">]</span></code></dt>
  73. <dt><code>find <span class="roman">[</span>/<var>sn</var><span class="roman">]</span> <var>start_addr</var>, <var>end_addr</var>, <var>val1</var> <span class="roman">[</span>, <var>val2</var>, &hellip;<span class="roman">]</span></code></dt>
  74. <dd><p>Search memory for the sequence of bytes specified by <var>val1</var>, <var>val2</var>,
  75. etc. The search begins at address <var>start_addr</var> and continues for either
  76. <var>len</var> bytes or through to <var>end_addr</var> inclusive.
  77. </p></dd>
  78. </dl>
  79. <p><var>s</var> and <var>n</var> are optional parameters.
  80. They may be specified in either order, apart or together.
  81. </p>
  82. <dl compact="compact">
  83. <dt><span class="roman"><var>s</var>, search query size</span></dt>
  84. <dd><p>The size of each search query value.
  85. </p>
  86. <dl compact="compact">
  87. <dt><code>b</code></dt>
  88. <dd><p>bytes
  89. </p></dd>
  90. <dt><code>h</code></dt>
  91. <dd><p>halfwords (two bytes)
  92. </p></dd>
  93. <dt><code>w</code></dt>
  94. <dd><p>words (four bytes)
  95. </p></dd>
  96. <dt><code>g</code></dt>
  97. <dd><p>giant words (eight bytes)
  98. </p></dd>
  99. </dl>
  100. <p>All values are interpreted in the current language.
  101. This means, for example, that if the current source language is C/C<tt>++</tt>
  102. then searching for the string &ldquo;hello&rdquo; includes the trailing &rsquo;\0&rsquo;.
  103. The null terminator can be removed from searching by using casts,
  104. e.g.: &lsquo;<samp>{char[5]}&quot;hello&quot;</samp>&rsquo;.
  105. </p>
  106. <p>If the value size is not specified, it is taken from the
  107. value&rsquo;s type in the current language.
  108. This is useful when one wants to specify the search
  109. pattern as a mixture of types.
  110. Note that this means, for example, that in the case of C-like languages
  111. a search for an untyped 0x42 will search for &lsquo;<samp>(int) 0x42</samp>&rsquo;
  112. which is typically four bytes.
  113. </p>
  114. </dd>
  115. <dt><span class="roman"><var>n</var>, maximum number of finds</span></dt>
  116. <dd><p>The maximum number of matches to print. The default is to print all finds.
  117. </p></dd>
  118. </dl>
  119. <p>You can use strings as search values. Quote them with double-quotes
  120. (<code>&quot;</code>).
  121. The string value is copied into the search pattern byte by byte,
  122. regardless of the endianness of the target and the size specification.
  123. </p>
  124. <p>The address of each match found is printed as well as a count of the
  125. number of matches found.
  126. </p>
  127. <p>The address of the last value found is stored in convenience variable
  128. &lsquo;<samp>$_</samp>&rsquo;.
  129. A count of the number of matches is stored in &lsquo;<samp>$numfound</samp>&rsquo;.
  130. </p>
  131. <p>For example, if stopped at the <code>printf</code> in this function:
  132. </p>
  133. <div class="smallexample">
  134. <pre class="smallexample">void
  135. hello ()
  136. {
  137. static char hello[] = &quot;hello-hello&quot;;
  138. static struct { char c; short s; int i; }
  139. __attribute__ ((packed)) mixed
  140. = { 'c', 0x1234, 0x87654321 };
  141. printf (&quot;%s\n&quot;, hello);
  142. }
  143. </pre></div>
  144. <p>you get during debugging:
  145. </p>
  146. <div class="smallexample">
  147. <pre class="smallexample">(gdb) find &amp;hello[0], +sizeof(hello), &quot;hello&quot;
  148. 0x804956d &lt;hello.1620+6&gt;
  149. 1 pattern found
  150. (gdb) find &amp;hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
  151. 0x8049567 &lt;hello.1620&gt;
  152. 0x804956d &lt;hello.1620+6&gt;
  153. 2 patterns found.
  154. (gdb) find &amp;hello[0], +sizeof(hello), {char[5]}&quot;hello&quot;
  155. 0x8049567 &lt;hello.1620&gt;
  156. 0x804956d &lt;hello.1620+6&gt;
  157. 2 patterns found.
  158. (gdb) find /b1 &amp;hello[0], +sizeof(hello), 'h', 0x65, 'l'
  159. 0x8049567 &lt;hello.1620&gt;
  160. 1 pattern found
  161. (gdb) find &amp;mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
  162. 0x8049560 &lt;mixed.1625&gt;
  163. 1 pattern found
  164. (gdb) print $numfound
  165. $1 = 1
  166. (gdb) print $_
  167. $2 = (void *) 0x8049560
  168. </pre></div>
  169. <hr>
  170. <div class="header">
  171. <p>
  172. Next: <a href="Value-Sizes.html#Value-Sizes" accesskey="n" rel="next">Value Sizes</a>, Previous: <a href="Caching-Target-Data.html#Caching-Target-Data" accesskey="p" rel="prev">Caching Target Data</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>
  173. </div>
  174. </body>
  175. </html>