11.6.5 Register Caching

Caching of registers is used, so that the target does not need to be accessed and reanalyzed multiple times for each register in circumstances where the register value cannot have changed.

gdb provides struct regcache, associated with a particular struct gdbarch to hold the cached values of the raw registers. A set of functions is provided to access both the raw registers (with raw in their name) and the full set of cooked registers (with cooked in their name). Functions are provided to ensure the register cache is kept synchronized with the values of the actual registers in the target.

Accessing registers through the struct regcache routines will ensure that the appropriate struct gdbarch functions are called when necessary to access the underlying target architecture. In general users should use the cooked functions, since these will map to the raw functions automatically as appropriate.

The two key functions are regcache_cooked_read and regcache_cooked_write which read or write a register from or to a byte buffer (type gdb_byte *). For convenience the wrapper functions regcache_cooked_read_signed, regcache_cooked_read_unsigned, regcache_cooked_write_signed and regcache_cooked_write_unsigned are provided, which read or write the value using the buffer and convert to or from an integral value as appropriate.