### 9.6 Raw and Virtual Register Representations

Maintainer note: This section is pretty much obsolete. The functionality described here has largely been replaced by pseudo-registers and the mechanisms described in Using Different Register and Memory Data Representations. See also Bug Tracking Database and ARI Index for more up-to-date information.

Some architectures use one representation for a value when it lives in a register, but use a different representation when it lives in memory. In gdb's terminology, the raw representation is the one used in the target registers, and the virtual representation is the one used in memory, and within gdb `struct value` objects.

Maintainer note: Notice that the same mechanism is being used to both convert a register to a `struct value` and alternative register forms.

For almost all data types on almost all architectures, the virtual and raw representations are identical, and no special handling is needed. However, they do occasionally differ. For example:

- The x86 architecture supports an 80-bit `long double` type. However, when we store those values in memory, they occupy twelve bytes: the floating-point number occupies the first ten, and the final two bytes are unused. This keeps the values aligned on four-byte boundaries, allowing more efficient access. Thus, the x86 80-bit floating-point type is the raw representation, and the twelve-byte loosely-packed arrangement is the virtual representation.
- Some 64-bit MIPS targets present 32-bit registers to gdb as 64-bit registers, with garbage in their upper bits. gdb ignores the top 32 bits. Thus, the 64-bit form, with garbage in the upper 32 bits, is the raw representation, and the trimmed 32-bit representation is the virtual representation.

In general, the raw representation is determined by the architecture, or gdb's interface to the architecture, while the virtual representation can be chosen for gdb's convenience. gdb's register file, `registers`, holds the register contents in raw format, and the gdb remote protocol transmits register values in raw format.

Your architecture may define the following macros to request conversions between the raw and virtual format:

— Target Macro: int REGISTER_CONVERTIBLE (int reg)

> Return non-zero if register number reg's value needs different raw and virtual formats.

> You should not use `REGISTER_CONVERT_TO_VIRTUAL` for a register unless this macro returns a non-zero value for that register.

— Target Macro: int DEPRECATED_REGISTER_RAW_SIZE (int reg)

> The size of register number reg's raw value. This is the number of bytes the register will occupy in `registers`, or in a gdb remote protocol packet.

— Target Macro: int DEPRECATED_REGISTER_VIRTUAL_SIZE (int reg)

> The size of register number reg's value, in its virtual format. This is the size a `struct value`'s buffer will have, holding that register's value.

— Target Macro: struct type *DEPRECATED_REGISTER_VIRTUAL_TYPE (int reg)

> This is the type of the virtual representation of register number reg. Note that there is no need for a macro giving a type for the register's raw form; once the register's value has been obtained, gdb always uses the virtual form.

— Target Macro: void REGISTER_CONVERT_TO_VIRTUAL (int reg, struct type *type, char *from, char *to)

> Convert the value of register number reg to type, which should always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (`reg`)`. The buffer at from holds the register's value in raw format; the macro should convert the value to virtual format, and place it at to.

> Note that `REGISTER_CONVERT_TO_VIRTUAL` and `REGISTER_CONVERT_TO_RAW` take their reg and type arguments in different orders.

> You should only use `REGISTER_CONVERT_TO_VIRTUAL` with registers for which the `REGISTER_CONVERTIBLE` macro returns a non-zero value.

— Target Macro: void REGISTER_CONVERT_TO_RAW (struct type *type, int reg, char *from, char *to)

> Convert the value of register number reg to type, which should always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (`reg`)`. The buffer at from holds the register's value in raw format; the macro should convert the value to virtual format, and place it at to.

> Note that REGISTER_CONVERT_TO_VIRTUAL and REGISTER_CONVERT_TO_RAW take their reg and type arguments in different orders.