| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- Copyright (C) 1988-2015 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 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>Debugging with GDB: Registers</title> |
| |
| <meta name="description" content="Debugging with GDB: Registers"> |
| <meta name="keywords" content="Debugging with GDB: Registers"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="makeinfo"> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <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="Floating-Point-Hardware.html#Floating-Point-Hardware" rel="next" title="Floating Point Hardware"> |
| <link href="Convenience-Funs.html#Convenience-Funs" rel="prev" title="Convenience Funs"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| 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.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="Registers"></a> |
| <div class="header"> |
| <p> |
| Next: <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="prev">Convenience Funs</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="Registers-1"></a> |
| <h3 class="section">10.13 Registers</h3> |
| |
| <a name="index-registers"></a> |
| <p>You can refer to machine register contents, in expressions, as variables |
| with names starting with ‘<samp>$</samp>’. The names of registers are different |
| for each machine; use <code>info registers</code> to see the names used on |
| your machine. |
| </p> |
| <dl compact="compact"> |
| <dd><a name="index-info-registers"></a> |
| </dd> |
| <dt><code>info registers</code></dt> |
| <dd><p>Print the names and values of all registers except floating-point |
| and vector registers (in the selected stack frame). |
| </p> |
| <a name="index-info-all_002dregisters"></a> |
| <a name="index-floating-point-registers"></a> |
| </dd> |
| <dt><code>info all-registers</code></dt> |
| <dd><p>Print the names and values of all registers, including floating-point |
| and vector registers (in the selected stack frame). |
| </p> |
| </dd> |
| <dt><code>info registers <var>regname</var> …</code></dt> |
| <dd><p>Print the <em>relativized</em> value of each specified register <var>regname</var>. |
| As discussed in detail below, register values are normally relative to |
| the selected stack frame. The <var>regname</var> may be any register name valid on |
| the machine you are using, with or without the initial ‘<samp>$</samp>’. |
| </p></dd> |
| </dl> |
| |
| <a name="standard-registers"></a><a name="index-stack-pointer-register"></a> |
| <a name="index-program-counter-register"></a> |
| <a name="index-process-status-register"></a> |
| <a name="index-frame-pointer-register"></a> |
| <a name="index-standard-registers"></a> |
| <p><small>GDB</small> has four “standard” register names that are available (in |
| expressions) on most machines—whenever they do not conflict with an |
| architecture’s canonical mnemonics for registers. The register names |
| <code>$pc</code> and <code>$sp</code> are used for the program counter register and |
| the stack pointer. <code>$fp</code> is used for a register that contains a |
| pointer to the current stack frame, and <code>$ps</code> is used for a |
| register that contains the processor status. For example, |
| you could print the program counter in hex with |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">p/x $pc |
| </pre></div> |
| |
| <p>or print the instruction to be executed next with |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">x/i $pc |
| </pre></div> |
| |
| <p>or add four to the stack pointer<a name="DOCF11" href="#FOOT11"><sup>11</sup></a> with |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">set $sp += 4 |
| </pre></div> |
| |
| <p>Whenever possible, these four standard register names are available on |
| your machine even though the machine has different canonical mnemonics, |
| so long as there is no conflict. The <code>info registers</code> command |
| shows the canonical names. For example, on the SPARC, <code>info |
| registers</code> displays the processor status register as <code>$psr</code> but you |
| can also refer to it as <code>$ps</code>; and on x86-based machines <code>$ps</code> |
| is an alias for the <small>EFLAGS</small> register. |
| </p> |
| <p><small>GDB</small> always considers the contents of an ordinary register as an |
| integer when the register is examined in this way. Some machines have |
| special registers which can hold nothing but floating point; these |
| registers are considered to have floating point values. There is no way |
| to refer to the contents of an ordinary register as floating point value |
| (although you can <em>print</em> it as a floating point value with |
| ‘<samp>print/f $<var>regname</var></samp>’). |
| </p> |
| <p>Some registers have distinct “raw” and “virtual” data formats. This |
| means that the data format in which the register contents are saved by |
| the operating system is not the same one that your program normally |
| sees. For example, the registers of the 68881 floating point |
| coprocessor are always saved in “extended” (raw) format, but all C |
| programs expect to work with “double” (virtual) format. In such |
| cases, <small>GDB</small> normally works with the virtual format only (the format |
| that makes sense for your program), but the <code>info registers</code> command |
| prints the data in both formats. |
| </p> |
| <a name="index-SSE-registers-_0028x86_0029"></a> |
| <a name="index-MMX-registers-_0028x86_0029"></a> |
| <p>Some machines have special registers whose contents can be interpreted |
| in several different ways. For example, modern x86-based machines |
| have SSE and MMX registers that can hold several values packed |
| together in several different formats. <small>GDB</small> refers to such |
| registers in <code>struct</code> notation: |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">(gdb) print $xmm1 |
| $1 = { |
| v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044}, |
| v2_double = {9.92129282474342e-303, 2.7585945287983262e-313}, |
| v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000", |
| v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0}, |
| v4_int32 = {0, 20657912, 11, 13}, |
| v2_int64 = {88725056443645952, 55834574859}, |
| uint128 = 0x0000000d0000000b013b36f800000000 |
| } |
| </pre></div> |
| |
| <p>To set values of such registers, you need to tell <small>GDB</small> which |
| view of the register you wish to change, as if you were assigning |
| value to a <code>struct</code> member: |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample"> (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF |
| </pre></div> |
| |
| <p>Normally, register values are relative to the selected stack frame |
| (see <a href="Selection.html#Selection">Selecting a Frame</a>). This means that you get the |
| value that the register would contain if all stack frames farther in |
| were exited and their saved registers restored. In order to see the |
| true contents of hardware registers, you must select the innermost |
| frame (with ‘<samp>frame 0</samp>’). |
| </p> |
| <a name="index-caller_002dsaved-registers"></a> |
| <a name="index-call_002dclobbered-registers"></a> |
| <a name="index-volatile-registers"></a> |
| <a name="index-_003cnot-saved_003e-values"></a> |
| <p>Usually ABIs reserve some registers as not needed to be saved by the |
| callee (a.k.a.: “caller-saved”, “call-clobbered” or “volatile” |
| registers). It may therefore not be possible for <small>GDB</small> to know |
| the value a register had before the call (in other words, in the outer |
| frame), if the register value has since been changed by the callee. |
| <small>GDB</small> tries to deduce where the inner frame saved |
| (“callee-saved”) registers, from the debug info, unwind info, or the |
| machine code generated by your compiler. If some register is not |
| saved, and <small>GDB</small> knows the register is “caller-saved” (via |
| its own knowledge of the ABI, or because the debug/unwind info |
| explicitly says the register’s value is undefined), <small>GDB</small> |
| displays ‘<samp><not saved></samp>’<!-- /@w --> as the register’s value. With targets |
| that <small>GDB</small> has no knowledge of the register saving convention, |
| if a register was not saved by the callee, then its value and location |
| in the outer frame are assumed to be the same of the inner frame. |
| This is usually harmless, because if the register is call-clobbered, |
| the caller either does not care what is in the register after the |
| call, or has code to restore the value that it does care about. Note, |
| however, that if you change such a register in the outer frame, you |
| may also be affecting the inner frame. Also, the more “outer” the |
| frame is you’re looking at, the more likely a call-clobbered |
| register’s value is to be wrong, in the sense that it doesn’t actually |
| represent the value the register had just before the call. |
| </p> |
| <div class="footnote"> |
| <hr> |
| <h4 class="footnotes-heading">Footnotes</h4> |
| |
| <h3><a name="FOOT11" href="#DOCF11">(11)</a></h3> |
| <p>This is a way of removing |
| one word from the stack, on machines where stacks grow downward in |
| memory (most machines, nowadays). This assumes that the innermost |
| stack frame is selected; setting <code>$sp</code> is not allowed when other |
| stack frames are selected. To pop entire frames off the stack, |
| regardless of machine architecture, use <code>return</code>; |
| see <a href="Returning.html#Returning">Returning from a Function</a>.</p> |
| </div> |
| <hr> |
| <div class="header"> |
| <p> |
| Next: <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="prev">Convenience Funs</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> |