Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Memory.html
blobb5c0b498b8eaca97d943dd638ba8c387ec7b738d
1 <html lang="en">
2 <head>
3 <title>Debugging with GDB</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="description" content="Debugging with GDB">
6 <meta name="generator" content="makeinfo 4.3">
7 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="Memory">Memory</a>,
13 Next:<a rel="next" accesskey="n" href="Auto-Display.html#Auto%20Display">Auto Display</a>,
14 Previous:<a rel="previous" accesskey="p" href="Output-Formats.html#Output%20Formats">Output Formats</a>,
15 Up:<a rel="up" accesskey="u" href="Data.html#Data">Data</a>
16 <hr><br>
17 </div>
19 <h3 class="section">Examining memory</h3>
21 <p>You can use the command <code>x</code> (for "examine") to examine memory in
22 any of several formats, independently of your program's data types.
24 <dl>
25 <dt><code>x/</code><var>nfu</var><code> </code><var>addr</var><code></code>
26 <dd><dt><code>x </code><var>addr</var><code></code>
27 <dd><dt><code>x</code>
28 <dd>Use the <code>x</code> command to examine memory.
29 </dl>
31 <p><var>n</var>, <var>f</var>, and <var>u</var> are all optional parameters that specify how
32 much memory to display and how to format it; <var>addr</var> is an
33 expression giving the address where you want to start displaying memory.
34 If you use defaults for <var>nfu</var>, you need not type the slash <code>/</code>.
35 Several commands set convenient defaults for <var>addr</var>.
37 <dl>
38 <dt><var>n</var>, the repeat count
39 <dd>The repeat count is a decimal integer; the default is 1. It specifies
40 how much memory (counting by units <var>u</var>) to display.
42 <br><dt><var>f</var>, the display format
43 <dd>The display format is one of the formats used by <code>print</code>,
44 <code>s</code> (null-terminated string), or <code>i</code> (machine instruction).
45 The default is <code>x</code> (hexadecimal) initially.
46 The default changes each time you use either <code>x</code> or <code>print</code>.
48 <br><dt><var>u</var>, the unit size
49 <dd>The unit size is any of
51 <dl>
52 <dt><code>b</code>
53 <dd>Bytes.
54 <br><dt><code>h</code>
55 <dd>Halfwords (two bytes).
56 <br><dt><code>w</code>
57 <dd>Words (four bytes). This is the initial default.
58 <br><dt><code>g</code>
59 <dd>Giant words (eight bytes).
60 </dl>
62 <p>Each time you specify a unit size with <code>x</code>, that size becomes the
63 default unit the next time you use <code>x</code>. (For the <code>s</code> and
64 <code>i</code> formats, the unit size is ignored and is normally not written.)
66 <br><dt><var>addr</var>, starting display address
67 <dd><var>addr</var> is the address where you want GDB to begin displaying
68 memory. The expression need not have a pointer value (though it may);
69 it is always interpreted as an integer address of a byte of memory.
70 See <a href="Expressions.html#Expressions">Expressions</a>, for more information on expressions. The default for
71 <var>addr</var> is usually just after the last address examined--but several
72 other commands also set the default address: <code>info breakpoints</code> (to
73 the address of the last breakpoint listed), <code>info line</code> (to the
74 starting address of a line), and <code>print</code> (if you use it to display
75 a value from memory).
76 </dl>
78 <p>For example, <code>x/3uh 0x54320</code> is a request to display three halfwords
79 (<code>h</code>) of memory, formatted as unsigned decimal integers (<code>u</code>),
80 starting at address <code>0x54320</code>. <code>x/4xw $sp</code> prints the four
81 words (<code>w</code>) of memory above the stack pointer (here, <code>$sp</code>;
82 see <a href="Registers.html#Registers">Registers</a>) in hexadecimal (<code>x</code>).
84 <p>Since the letters indicating unit sizes are all distinct from the
85 letters specifying output formats, you do not have to remember whether
86 unit size or format comes first; either order works. The output
87 specifications <code>4xw</code> and <code>4wx</code> mean exactly the same thing.
88 (However, the count <var>n</var> must come first; <code>wx4</code> does not work.)
90 <p>Even though the unit size <var>u</var> is ignored for the formats <code>s</code>
91 and <code>i</code>, you might still want to use a count <var>n</var>; for example,
92 <code>3i</code> specifies that you want to see three machine instructions,
93 including any operands. The command <code>disassemble</code> gives an
94 alternative way of inspecting machine instructions; see <a href="Machine-Code.html#Machine%20Code">Source and machine code</a>.
96 <p>All the defaults for the arguments to <code>x</code> are designed to make it
97 easy to continue scanning memory with minimal specifications each time
98 you use <code>x</code>. For example, after you have inspected three machine
99 instructions with <code>x/3i </code><var>addr</var><code></code>, you can inspect the next seven
100 with just <code>x/7</code>. If you use &lt;RET&gt; to repeat the <code>x</code> command,
101 the repeat count <var>n</var> is used again; the other arguments default as
102 for successive uses of <code>x</code>.
104 <p>The addresses and contents printed by the <code>x</code> command are not saved
105 in the value history because there is often too much of them and they
106 would get in the way. Instead, GDB makes these values available for
107 subsequent use in expressions as values of the convenience variables
108 <code>$_</code> and <code>$__</code>. After an <code>x</code> command, the last address
109 examined is available for use in expressions in the convenience variable
110 <code>$_</code>. The contents of that address, as examined, are available in
111 the convenience variable <code>$__</code>.
113 <p>If the <code>x</code> command has a repeat count, the address and contents saved
114 are from the last memory unit printed; this is not the same as the last
115 address printed if several units were printed on the last line of output.
117 </body></html>