|
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
-
- Permission is granted to copy, distribute and/or modify this document
- under the terms of the GNU Free Documentation License, Version 1.3 or
- any later version published by the Free Software Foundation; with the
- Invariant Sections being "Free Software" and "Free Software Needs
- Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
- and with the Back-Cover Texts as in (a) below.
-
- (a) The FSF's Back-Cover Text is: "You are free to copy and modify
- this GNU Manual. Buying copies from GNU Press supports the FSF in
- developing GNU and promoting software freedom." -->
- <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Searching Memory (Debugging with GDB)</title>
-
- <meta name="description" content="Searching Memory (Debugging with GDB)">
- <meta name="keywords" content="Searching Memory (Debugging with GDB)">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="makeinfo">
- <link href="index.html#Top" rel="start" title="Top">
- <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
- <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
- <link href="Data.html#Data" rel="up" title="Data">
- <link href="Value-Sizes.html#Value-Sizes" rel="next" title="Value Sizes">
- <link href="Caching-Target-Data.html#Caching-Target-Data" rel="prev" title="Caching Target Data">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.indentedblock {margin-right: 0em}
- blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
- blockquote.smallquotation {font-size: smaller}
- div.display {margin-left: 3.2em}
- div.example {margin-left: 3.2em}
- div.lisp {margin-left: 3.2em}
- div.smalldisplay {margin-left: 3.2em}
- div.smallexample {margin-left: 3.2em}
- div.smalllisp {margin-left: 3.2em}
- kbd {font-style: oblique}
- pre.display {font-family: inherit}
- pre.format {font-family: inherit}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: inherit; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: inherit; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.nolinebreak {white-space: nowrap}
- span.roman {font-family: initial; font-weight: normal}
- span.sansserif {font-family: sans-serif; font-weight: normal}
- ul.no-bullet {list-style: none}
- -->
- </style>
-
-
- </head>
-
- <body lang="en">
- <a name="Searching-Memory"></a>
- <div class="header">
- <p>
- 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> [<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>
- </div>
- <hr>
- <a name="Search-Memory"></a>
- <h3 class="section">10.22 Search Memory</h3>
- <a name="index-searching-memory"></a>
-
- <p>Memory can be searched for a particular sequence of bytes with the
- <code>find</code> command.
- </p>
- <dl compact="compact">
- <dd><a name="index-find"></a>
- </dd>
- <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>, …<span class="roman">]</span></code></dt>
- <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>, …<span class="roman">]</span></code></dt>
- <dd><p>Search memory for the sequence of bytes specified by <var>val1</var>, <var>val2</var>,
- etc. The search begins at address <var>start_addr</var> and continues for either
- <var>len</var> bytes or through to <var>end_addr</var> inclusive.
- </p></dd>
- </dl>
-
- <p><var>s</var> and <var>n</var> are optional parameters.
- They may be specified in either order, apart or together.
- </p>
- <dl compact="compact">
- <dt><span class="roman"><var>s</var>, search query size</span></dt>
- <dd><p>The size of each search query value.
- </p>
- <dl compact="compact">
- <dt><code>b</code></dt>
- <dd><p>bytes
- </p></dd>
- <dt><code>h</code></dt>
- <dd><p>halfwords (two bytes)
- </p></dd>
- <dt><code>w</code></dt>
- <dd><p>words (four bytes)
- </p></dd>
- <dt><code>g</code></dt>
- <dd><p>giant words (eight bytes)
- </p></dd>
- </dl>
-
- <p>All values are interpreted in the current language.
- This means, for example, that if the current source language is C/C<tt>++</tt>
- then searching for the string “hello” includes the trailing ’\0’.
- The null terminator can be removed from searching by using casts,
- e.g.: ‘<samp>{char[5]}"hello"</samp>’.
- </p>
- <p>If the value size is not specified, it is taken from the
- value’s type in the current language.
- This is useful when one wants to specify the search
- pattern as a mixture of types.
- Note that this means, for example, that in the case of C-like languages
- a search for an untyped 0x42 will search for ‘<samp>(int) 0x42</samp>’
- which is typically four bytes.
- </p>
- </dd>
- <dt><span class="roman"><var>n</var>, maximum number of finds</span></dt>
- <dd><p>The maximum number of matches to print. The default is to print all finds.
- </p></dd>
- </dl>
-
- <p>You can use strings as search values. Quote them with double-quotes
- (<code>"</code>).
- The string value is copied into the search pattern byte by byte,
- regardless of the endianness of the target and the size specification.
- </p>
- <p>The address of each match found is printed as well as a count of the
- number of matches found.
- </p>
- <p>The address of the last value found is stored in convenience variable
- ‘<samp>$_</samp>’.
- A count of the number of matches is stored in ‘<samp>$numfound</samp>’.
- </p>
- <p>For example, if stopped at the <code>printf</code> in this function:
- </p>
- <div class="smallexample">
- <pre class="smallexample">void
- hello ()
- {
- static char hello[] = "hello-hello";
- static struct { char c; short s; int i; }
- __attribute__ ((packed)) mixed
- = { 'c', 0x1234, 0x87654321 };
- printf ("%s\n", hello);
- }
- </pre></div>
-
- <p>you get during debugging:
- </p>
- <div class="smallexample">
- <pre class="smallexample">(gdb) find &hello[0], +sizeof(hello), "hello"
- 0x804956d <hello.1620+6>
- 1 pattern found
- (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
- 0x8049567 <hello.1620>
- 0x804956d <hello.1620+6>
- 2 patterns found.
- (gdb) find &hello[0], +sizeof(hello), {char[5]}"hello"
- 0x8049567 <hello.1620>
- 0x804956d <hello.1620+6>
- 2 patterns found.
- (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
- 0x8049567 <hello.1620>
- 1 pattern found
- (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
- 0x8049560 <mixed.1625>
- 1 pattern found
- (gdb) print $numfound
- $1 = 1
- (gdb) print $_
- $2 = (void *) 0x8049560
- </pre></div>
-
- <hr>
- <div class="header">
- <p>
- 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> [<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>
- </div>
-
-
-
- </body>
- </html>
|