xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/common-regcache.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
1 /* Cache and manage the values of registers
2 
3    Copyright (C) 2014-2024 Free Software Foundation, Inc.
4 
5    This file is part of GDB.
6 
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.
11 
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.
16 
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/>.  */
19 
20 #ifndef COMMON_COMMON_REGCACHE_H
21 #define COMMON_COMMON_REGCACHE_H
22 
23 struct reg_buffer_common;
24 
25 /* This header is a stopgap until we have an independent regcache.  */
26 
27 enum register_status : signed char
28   {
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,
32 
33     /* The register value is valid and cached.  */
34     REG_VALID = 1,
35 
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
43   };
44 
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.  */
48 
49 extern reg_buffer_common *get_thread_regcache_for_ptid (ptid_t ptid);
50 
51 /* Return the size of register numbered N in REGCACHE.  This function
52    must be provided by the client.  */
53 
54 extern int regcache_register_size (const reg_buffer_common *regcache, int n);
55 
56 /* Read the PC register.  This function must be provided by the
57    client.  */
58 
59 extern CORE_ADDR regcache_read_pc (reg_buffer_common *regcache);
60 
61 /* Read the PC register.  If PC cannot be read, return 0.
62    This is a wrapper around 'regcache_read_pc'.  */
63 
64 extern CORE_ADDR regcache_read_pc_protected (reg_buffer_common *regcache);
65 
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);
70 
71 ULONGEST regcache_raw_get_unsigned (reg_buffer_common *regcache, int regnum);
72 
73 struct reg_buffer_common
74 {
75   virtual ~reg_buffer_common () = default;
76 
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;
80 
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;
85 
86   void raw_supply (int regnum, const uint64_t *src)
87   {
88     raw_supply (regnum,
89 		gdb::make_array_view ((const gdb_byte *) src, sizeof (*src)));
90   }
91 
92   void raw_supply (int regnum, const gdb_byte *src)
93   {
94     raw_supply (regnum,
95 		gdb::make_array_view (src,
96 				      regcache_register_size (this, regnum)));
97   }
98 
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;
103 
104   void raw_collect (int regnum, uint64_t *dst) const
105   {
106     raw_collect (regnum,
107 		 gdb::make_array_view ((gdb_byte *) dst, sizeof (*dst)));
108   };
109 
110   void raw_collect (int regnum, gdb_byte *dst)
111   {
112     raw_collect (regnum,
113 		 gdb::make_array_view (dst,
114 				       regcache_register_size (this, regnum)));
115   }
116 
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;
121 };
122 
123 #endif /* COMMON_COMMON_REGCACHE_H */
124