Fix seg-fault in the DWARF reader code when accessing an abbreviatuin table with...
[binutils-gdb.git] / gdbsupport / common-regcache.h
blobf8704c16939ae1973812fd06d71649b854285e75
1 /* Cache and manage the values of registers
3 Copyright (C) 2014-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef COMMON_COMMON_REGCACHE_H
21 #define COMMON_COMMON_REGCACHE_H
23 struct reg_buffer_common;
25 /* This header is a stopgap until we have an independent regcache. */
27 enum register_status : signed char
29 /* The register value is not in the cache, and we don't know yet
30 whether it's available in the target (or traceframe). */
31 REG_UNKNOWN = 0,
33 /* The register value is valid and cached. */
34 REG_VALID = 1,
36 /* The register value is unavailable. E.g., we're inspecting a
37 traceframe, and this register wasn't collected. Note that this
38 is different a different "unavailable" from saying the register
39 does not exist in the target's architecture --- in that case,
40 the target should have given us a target description that does
41 not include the register in the first place. */
42 REG_UNAVAILABLE = -1
45 /* Return a pointer to the register cache associated with the
46 thread specified by PTID. This function must be provided by
47 the client. */
49 extern reg_buffer_common *get_thread_regcache_for_ptid (ptid_t ptid);
51 /* Return the size of register numbered N in REGCACHE. This function
52 must be provided by the client. */
54 extern int regcache_register_size (const reg_buffer_common *regcache, int n);
56 /* Read the PC register. This function must be provided by the
57 client. */
59 extern CORE_ADDR regcache_read_pc (reg_buffer_common *regcache);
61 /* Read the PC register. If PC cannot be read, return 0.
62 This is a wrapper around 'regcache_read_pc'. */
64 extern CORE_ADDR regcache_read_pc_protected (reg_buffer_common *regcache);
66 /* Read a raw register into a unsigned integer. */
67 extern enum register_status
68 regcache_raw_read_unsigned (reg_buffer_common *regcache, int regnum,
69 ULONGEST *val);
71 ULONGEST regcache_raw_get_unsigned (reg_buffer_common *regcache, int regnum);
73 struct reg_buffer_common
75 virtual ~reg_buffer_common () = default;
77 /* Get the availability status of the value of register REGNUM in this
78 buffer. */
79 virtual register_status get_register_status (int regnum) const = 0;
81 /* Supply register REGNUM, whose contents are stored in SRC, to this register
82 buffer. */
83 virtual void raw_supply (int regnum, gdb::array_view<const gdb_byte> src)
84 = 0;
86 void raw_supply (int regnum, const uint64_t *src)
88 raw_supply (regnum,
89 gdb::make_array_view ((const gdb_byte *) src, sizeof (*src)));
92 void raw_supply (int regnum, const gdb_byte *src)
94 raw_supply (regnum,
95 gdb::make_array_view (src,
96 regcache_register_size (this, regnum)));
99 /* Collect register REGNUM from this register buffer and store its contents in
100 DST. */
101 virtual void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const
102 = 0;
104 void raw_collect (int regnum, uint64_t *dst) const
106 raw_collect (regnum,
107 gdb::make_array_view ((gdb_byte *) dst, sizeof (*dst)));
110 void raw_collect (int regnum, gdb_byte *dst)
112 raw_collect (regnum,
113 gdb::make_array_view (dst,
114 regcache_register_size (this, regnum)));
117 /* Compare the contents of the register stored in the regcache (ignoring the
118 first OFFSET bytes) to the contents of BUF (without any offset). Returns
119 true if the same. */
120 virtual bool raw_compare (int regnum, const void *buf, int offset) const = 0;
123 #endif /* COMMON_COMMON_REGCACHE_H */