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">
12 Node:
<a name=
"Registers">Registers
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Floating-Point-Hardware.html#Floating%20Point%20Hardware">Floating Point Hardware
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Convenience-Vars.html#Convenience%20Vars">Convenience Vars
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Data.html#Data">Data
</a>
19 <h3 class=
"section">Registers
</h3>
21 <p>You can refer to machine register contents, in expressions, as variables
22 with names starting with
<code>$
</code>. The names of registers are different
23 for each machine; use
<code>info registers
</code> to see the names used on
27 <dt><code>info registers
</code>
28 <dd>Print the names and values of all registers except floating-point
29 registers (in the selected stack frame).
31 <br><dt><code>info all-registers
</code>
32 <dd>Print the names and values of all registers, including floating-point
35 <br><dt><code>info registers
</code><var>regname
</var><code> ...
</code>
36 <dd>Print the
<dfn>relativized
</dfn> value of each specified register
<var>regname
</var>.
37 As discussed in detail below, register values are normally relative to
38 the selected stack frame.
<var>regname
</var> may be any register name valid on
39 the machine you are using, with or without the initial
<code>$
</code>.
42 GDB has four
"standard" register names that are available (in
43 expressions) on most machines--whenever they do not conflict with an
44 architecture's canonical mnemonics for registers. The register names
45 <code>$pc
</code> and
<code>$sp
</code> are used for the program counter register and
46 the stack pointer.
<code>$fp
</code> is used for a register that contains a
47 pointer to the current stack frame, and
<code>$ps
</code> is used for a
48 register that contains the processor status. For example,
49 you could print the program counter in hex with
51 <pre class=
"example"> p/x $pc
54 <p>or print the instruction to be executed next with
56 <pre class=
"example"> x/i $pc
59 <p>or add four to the stack pointer
<a rel=
"footnote" href=
"#fn-1"><sup>1</sup></a> with
61 <pre class=
"example"> set $sp +=
4
64 <p>Whenever possible, these four standard register names are available on
65 your machine even though the machine has different canonical mnemonics,
66 so long as there is no conflict. The
<code>info registers
</code> command
67 shows the canonical names. For example, on the SPARC,
<code>info
68 registers
</code> displays the processor status register as
<code>$psr
</code> but you
69 can also refer to it as
<code>$ps
</code>; and on x86-based machines
<code>$ps
</code>
70 is an alias for the
<small>EFLAGS
</small> register.
72 GDB always considers the contents of an ordinary register as an
73 integer when the register is examined in this way. Some machines have
74 special registers which can hold nothing but floating point; these
75 registers are considered to have floating point values. There is no way
76 to refer to the contents of an ordinary register as floating point value
77 (although you can
<em>print
</em> it as a floating point value with
78 <code>print/f $
</code><var>regname
</var><code></code>).
80 <p>Some registers have distinct
"raw" and
"virtual" data formats. This
81 means that the data format in which the register contents are saved by
82 the operating system is not the same one that your program normally
83 sees. For example, the registers of the
68881 floating point
84 coprocessor are always saved in
"extended" (raw) format, but all C
85 programs expect to work with
"double" (virtual) format. In such
86 cases, GDB normally works with the virtual format only (the format
87 that makes sense for your program), but the
<code>info registers
</code> command
88 prints the data in both formats.
90 <p>Normally, register values are relative to the selected stack frame
91 (see
<a href=
"Selection.html#Selection">Selecting a frame
</a>). This means that you get the
92 value that the register would contain if all stack frames farther in
93 were exited and their saved registers restored. In order to see the
94 true contents of hardware registers, you must select the innermost
95 frame (with
<code>frame
0</code>).
97 <p>However, GDB must deduce where registers are saved, from the machine
98 code generated by your compiler. If some registers are not saved, or if
99 GDB is unable to locate the saved registers, the selected stack
100 frame makes no difference.
102 <div class=
"footnote">
106 <li><a name=
"fn-1"></a>
107 <p>This is a way of removing
108 one word from the stack, on machines where stacks grow downward in
109 memory (most machines, nowadays). This assumes that the innermost
110 stack frame is selected; setting
<code>$sp
</code> is not allowed when other
111 stack frames are selected. To pop entire frames off the stack,
112 regardless of machine architecture, use
<code>return
</code>;
113 see
<a href=
"Returning.html#Returning">Returning from a function
</a>.
</p>