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-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Registers</title>
18
19<meta name="description" content="Debugging with GDB: Registers">
20<meta name="keywords" content="Debugging with GDB: Registers">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Data.html#Data" rel="up" title="Data">
29<link href="Floating-Point-Hardware.html#Floating-Point-Hardware" rel="next" title="Floating Point Hardware">
30<link href="Convenience-Funs.html#Convenience-Funs" rel="previous" title="Convenience Funs">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Registers"></a>
65<div class="header">
66<p>
67Next: <a href="Floating-Point-Hardware.html#Floating-Point-Hardware" accesskey="n" rel="next">Floating Point Hardware</a>, Previous: <a href="Convenience-Funs.html#Convenience-Funs" accesskey="p" rel="previous">Convenience Funs</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>
68</div>
69<hr>
70<a name="Registers-1"></a>
71<h3 class="section">10.13 Registers</h3>
72
73<a name="index-registers"></a>
74<p>You can refer to machine register contents, in expressions, as variables
75with names starting with &lsquo;<samp>$</samp>&rsquo;.  The names of registers are different
76for each machine; use <code>info registers</code> to see the names used on
77your machine.
78</p>
79<dl compact="compact">
80<dd><a name="index-info-registers"></a>
81</dd>
82<dt><code>info registers</code></dt>
83<dd><p>Print the names and values of all registers except floating-point
84and vector registers (in the selected stack frame).
85</p>
86<a name="index-info-all_002dregisters"></a>
87<a name="index-floating-point-registers"></a>
88</dd>
89<dt><code>info all-registers</code></dt>
90<dd><p>Print the names and values of all registers, including floating-point
91and vector registers (in the selected stack frame).
92</p>
93<a name="info_005fregisters_005freggroup"></a></dd>
94<dt><code>info registers <var>reggroup</var> &hellip;</code></dt>
95<dd><p>Print the name and value of the registers in each of the specified
96<var>reggroup</var>s.  The <var>reggroup</var> can be any of those returned by
97<code>maint print reggroups</code> (see <a href="Maintenance-Commands.html#Maintenance-Commands">Maintenance Commands</a>).
98</p>
99</dd>
100<dt><code>info registers <var>regname</var> &hellip;</code></dt>
101<dd><p>Print the <em>relativized</em> value of each specified register <var>regname</var>.
102As discussed in detail below, register values are normally relative to
103the selected stack frame.  The <var>regname</var> may be any register name valid on
104the machine you are using, with or without the initial &lsquo;<samp>$</samp>&rsquo;.
105</p></dd>
106</dl>
107
108<a name="standard-registers"></a><a name="index-stack-pointer-register"></a>
109<a name="index-program-counter-register"></a>
110<a name="index-process-status-register"></a>
111<a name="index-frame-pointer-register"></a>
112<a name="index-standard-registers"></a>
113<p><small>GDB</small> has four &ldquo;standard&rdquo; register names that are available (in
114expressions) on most machines&mdash;whenever they do not conflict with an
115architecture&rsquo;s canonical mnemonics for registers.  The register names
116<code>$pc</code> and <code>$sp</code> are used for the program counter register and
117the stack pointer.  <code>$fp</code> is used for a register that contains a
118pointer to the current stack frame, and <code>$ps</code> is used for a
119register that contains the processor status.  For example,
120you could print the program counter in hex with
121</p>
122<div class="smallexample">
123<pre class="smallexample">p/x $pc
124</pre></div>
125
126<p>or print the instruction to be executed next with
127</p>
128<div class="smallexample">
129<pre class="smallexample">x/i $pc
130</pre></div>
131
132<p>or add four to the stack pointer<a name="DOCF12" href="#FOOT12"><sup>12</sup></a> with
133</p>
134<div class="smallexample">
135<pre class="smallexample">set $sp += 4
136</pre></div>
137
138<p>Whenever possible, these four standard register names are available on
139your machine even though the machine has different canonical mnemonics,
140so long as there is no conflict.  The <code>info registers</code> command
141shows the canonical names.  For example, on the SPARC, <code>info
142registers</code> displays the processor status register as <code>$psr</code> but you
143can also refer to it as <code>$ps</code>; and on x86-based machines <code>$ps</code>
144is an alias for the <small>EFLAGS</small> register.
145</p>
146<p><small>GDB</small> always considers the contents of an ordinary register as an
147integer when the register is examined in this way.  Some machines have
148special registers which can hold nothing but floating point; these
149registers are considered to have floating point values.  There is no way
150to refer to the contents of an ordinary register as floating point value
151(although you can <em>print</em> it as a floating point value with
152&lsquo;<samp>print/f $<var>regname</var></samp>&rsquo;).
153</p>
154<p>Some registers have distinct &ldquo;raw&rdquo; and &ldquo;virtual&rdquo; data formats.  This
155means that the data format in which the register contents are saved by
156the operating system is not the same one that your program normally
157sees.  For example, the registers of the 68881 floating point
158coprocessor are always saved in &ldquo;extended&rdquo; (raw) format, but all C
159programs expect to work with &ldquo;double&rdquo; (virtual) format.  In such
160cases, <small>GDB</small> normally works with the virtual format only (the format
161that makes sense for your program), but the <code>info registers</code> command
162prints the data in both formats.
163</p>
164<a name="index-SSE-registers-_0028x86_0029"></a>
165<a name="index-MMX-registers-_0028x86_0029"></a>
166<p>Some machines have special registers whose contents can be interpreted
167in several different ways.  For example, modern x86-based machines
168have SSE and MMX registers that can hold several values packed
169together in several different formats.  <small>GDB</small> refers to such
170registers in <code>struct</code> notation:
171</p>
172<div class="smallexample">
173<pre class="smallexample">(gdb) print $xmm1
174$1 = {
175  v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044},
176  v2_double = {9.92129282474342e-303, 2.7585945287983262e-313},
177  v16_int8 = &quot;\000\000\000\000\3706;\001\v\000\000\000\r\000\000&quot;,
178  v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0},
179  v4_int32 = {0, 20657912, 11, 13},
180  v2_int64 = {88725056443645952, 55834574859},
181  uint128 = 0x0000000d0000000b013b36f800000000
182}
183</pre></div>
184
185<p>To set values of such registers, you need to tell <small>GDB</small> which
186view of the register you wish to change, as if you were assigning
187value to a <code>struct</code> member:
188</p>
189<div class="smallexample">
190<pre class="smallexample"> (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
191</pre></div>
192
193<p>Normally, register values are relative to the selected stack frame
194(see <a href="Selection.html#Selection">Selecting a Frame</a>).  This means that you get the
195value that the register would contain if all stack frames farther in
196were exited and their saved registers restored.  In order to see the
197true contents of hardware registers, you must select the innermost
198frame (with &lsquo;<samp>frame 0</samp>&rsquo;).
199</p>
200<a name="index-caller_002dsaved-registers"></a>
201<a name="index-call_002dclobbered-registers"></a>
202<a name="index-volatile-registers"></a>
203<a name="index-_003cnot-saved_003e-values"></a>
204<p>Usually ABIs reserve some registers as not needed to be saved by the
205callee (a.k.a.: &ldquo;caller-saved&rdquo;, &ldquo;call-clobbered&rdquo; or &ldquo;volatile&rdquo;
206registers).  It may therefore not be possible for <small>GDB</small> to know
207the value a register had before the call (in other words, in the outer
208frame), if the register value has since been changed by the callee.
209<small>GDB</small> tries to deduce where the inner frame saved
210(&ldquo;callee-saved&rdquo;) registers, from the debug info, unwind info, or the
211machine code generated by your compiler.  If some register is not
212saved, and <small>GDB</small> knows the register is &ldquo;caller-saved&rdquo; (via
213its own knowledge of the ABI, or because the debug/unwind info
214explicitly says the register&rsquo;s value is undefined), <small>GDB</small>
215displays &lsquo;<samp>&lt;not&nbsp;saved&gt;</samp>&rsquo;<!-- /@w --> as the register&rsquo;s value.  With targets
216that <small>GDB</small> has no knowledge of the register saving convention,
217if a register was not saved by the callee, then its value and location
218in the outer frame are assumed to be the same of the inner frame.
219This is usually harmless, because if the register is call-clobbered,
220the caller either does not care what is in the register after the
221call, or has code to restore the value that it does care about.  Note,
222however, that if you change such a register in the outer frame, you
223may also be affecting the inner frame.  Also, the more &ldquo;outer&rdquo; the
224frame is you&rsquo;re looking at, the more likely a call-clobbered
225register&rsquo;s value is to be wrong, in the sense that it doesn&rsquo;t actually
226represent the value the register had just before the call.
227</p>
228<div class="footnote">
229<hr>
230<h4 class="footnotes-heading">Footnotes</h4>
231
232<h3><a name="FOOT12" href="#DOCF12">(12)</a></h3>
233<p>This is a way of removing
234one word from the stack, on machines where stacks grow downward in
235memory (most machines, nowadays).  This assumes that the innermost
236stack frame is selected; setting <code>$sp</code> is not allowed when other
237stack frames are selected.  To pop entire frames off the stack,
238regardless of machine architecture, use <code>return</code>;
239see <a href="Returning.html#Returning">Returning from a Function</a>.</p>
240</div>
241<hr>
242<div class="header">
243<p>
244Next: <a href="Floating-Point-Hardware.html#Floating-Point-Hardware" accesskey="n" rel="next">Floating Point Hardware</a>, Previous: <a href="Convenience-Funs.html#Convenience-Funs" accesskey="p" rel="previous">Convenience Funs</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>
245</div>
246
247
248
249</body>
250</html>
251