### 10.21 Caching Data of Targets

GDB caches data exchanged between the debugger and a target. Each cache is associated with the address space of the inferior. See Inferiors and Programs, about inferior and address space. Such caching generally improves performance in remote debugging (see Remote Debugging), because it reduces the overhead of the remote protocol by bundling memory reads and writes into large chunks. Unfortunately, simply caching everything would lead to incorrect results, since GDB does not necessarily know anything about volatile values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode (see Non-Stop Mode) memory can be changed while a gdb command is executing. Therefore, by default, GDB only caches data known to be on the stack12 or in the code segment. Other regions of memory can be explicitly marked as cacheable; see Memory Region Attributes.

`set remotecache on`
`set remotecache off`

  This option no longer does anything; it exists for compatibility with old scripts.

`show remotecache`

  Show the current state of the obsolete remotecache flag.

`set stack-cache on`
`set stack-cache off`

  Enable or disable caching of stack accesses. When `on`, use caching. By default, this option is `on`.

`show stack-cache`

  Show the current state of data caching for memory accesses.

`set code-cache on`
`set code-cache off`

  Enable or disable caching of code segment accesses. When `on`, use caching. By default, this option is `on`. This improves performance of disassembly in remote debugging.

`show code-cache`

  Show the current state of target memory cache for code segment accesses.

`info dcache [line]`

  Print the information about the performance of data cache of the current inferior’s address space. The information displayed includes the dcache width and depth, and for each cache line, its number, address, and how many times it was referenced. This command is useful for debugging the data cache operation.

  If a line number is specified, the contents of that line will be printed in hex.

`set dcache size size`

  Set maximum number of entries in dcache (dcache depth above).

`set dcache line-size line-size`

  Set number of bytes each dcache entry caches (dcache width above). Must be a power of 2.

`show dcache size`

  Show maximum number of dcache entries. See info dcache.

`show dcache line-size`

  Show default size of dcache lines.

#### Footnotes

### (12)

In non-stop mode, it is moderately rare for a running thread to modify the stack of a stopped thread in a way that would interfere with a backtrace, and caching of stack reads provides a significant speed up of remote backtraces.