### 9.7 Using Different Register and Memory Data Representations

Maintainer's note: The way GDB manipulates registers is undergoing significant change. Many of the macros and functions referred to in this section are likely to be subject to further revision. See A.R. Index and Bug Tracking Database for further information. cagney/2002-05-06.

Some architectures can represent a data object in a register using a form that is different to the objects more normal memory representation. For example:

- The Alpha architecture can represent 32 bit integer values in floating-point registers.
- The x86 architecture supports 80-bit floating-point registers. The `long double` data type occupies 96 bits in memory but only 80 bits when stored in a register.

In general, the register representation of a data type is determined by the architecture, or gdb's interface to the architecture, while the memory representation is determined by the Application Binary Interface.

For almost all data types on almost all architectures, the two representations are identical, and no special handling is needed. However, they do occasionally differ. Your architecture may define the following macros to request conversions between the register and memory representations of a data type:

— Function: int gdbarch_convert_register_p (struct gdbarch *gdbarch, int reg)

> Return non-zero if the representation of a data value stored in this register may be different to the representation of that same data value when stored in memory.

> When non-zero, the macros `gdbarch_register_to_value` and `value_to_register` are used to perform any necessary conversion.

> This function should return zero for the register's native type, when no conversion is necessary.

— Function: void gdbarch_register_to_value (struct gdbarch *gdbarch, int reg, struct type *type, char *from, char *to)

> Convert the value of register number reg to a data object of type type. The buffer at from holds the register's value in raw format; the converted value should be placed in the buffer at to.

> Note that `gdbarch_register_to_value` and `gdbarch_value_to_register` take their reg and type arguments in different orders.

> You should only use `gdbarch_register_to_value` with registers for which the `gdbarch_convert_register_p` function returns a non-zero value.

— Function: void gdbarch_value_to_register (struct gdbarch *gdbarch, struct type *type, int reg, char *from, char *to)

> Convert a data value of type type to register number reg' raw format.

> Note that `gdbarch_register_to_value` and `gdbarch_value_to_register` take their reg and type arguments in different orders.

> You should only use `gdbarch_value_to_register` with registers for which the `gdbarch_convert_register_p` function returns a non-zero value.

— Target Macro: void REGISTER_CONVERT_TO_TYPE (int regnum, struct type *type, char *buf)

> See `mips-tdep.c`. It does not do what you want.