trad-frame.h revision 1.10 1 1.1 christos /* Traditional frame unwind support, for GDB the GNU Debugger.
2 1.1 christos
3 1.10 christos Copyright (C) 2003-2023 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef TRAD_FRAME_H
21 1.1 christos #define TRAD_FRAME_H
22 1.1 christos
23 1.1 christos #include "frame.h" /* For "struct frame_id". */
24 1.1 christos
25 1.10 christos class frame_info_ptr;
26 1.8 christos struct regcache_map_entry;
27 1.1 christos struct trad_frame_cache;
28 1.1 christos
29 1.1 christos /* A simple, or traditional frame cache.
30 1.1 christos
31 1.1 christos The entire cache is populated in a single pass and then generic
32 1.1 christos routines are used to extract the various cache values. */
33 1.1 christos
34 1.10 christos struct trad_frame_cache *trad_frame_cache_zalloc (frame_info_ptr);
35 1.1 christos
36 1.1 christos /* This frame's ID. */
37 1.1 christos void trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
38 1.1 christos struct frame_id this_id);
39 1.1 christos void trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
40 1.1 christos struct frame_id *this_id);
41 1.1 christos void trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
42 1.1 christos CORE_ADDR this_base);
43 1.1 christos CORE_ADDR trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache);
44 1.1 christos
45 1.1 christos void trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
46 1.1 christos int regnum, int realreg);
47 1.1 christos void trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
48 1.1 christos int regnum, CORE_ADDR addr);
49 1.8 christos void trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache,
50 1.8 christos const struct regcache_map_entry *regmap,
51 1.8 christos CORE_ADDR addr, size_t size);
52 1.1 christos void trad_frame_set_reg_value (struct trad_frame_cache *this_cache,
53 1.1 christos int regnum, LONGEST val);
54 1.1 christos
55 1.10 christos /* Given the cache in THIS_TRAD_CACHE, set the value of REGNUM to the bytes
56 1.10 christos contained in BYTES with size SIZE. */
57 1.10 christos void trad_frame_set_reg_value_bytes (struct trad_frame_cache *this_trad_cache,
58 1.10 christos int regnum,
59 1.10 christos gdb::array_view<const gdb_byte> bytes);
60 1.10 christos
61 1.1 christos struct value *trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
62 1.10 christos frame_info_ptr this_frame,
63 1.1 christos int regnum);
64 1.1 christos
65 1.10 christos /* Describes the kind of encoding a stored register has. */
66 1.10 christos enum class trad_frame_saved_reg_kind
67 1.10 christos {
68 1.10 christos /* Register value is unknown. */
69 1.10 christos UNKNOWN = 0,
70 1.10 christos /* Register value is a constant. */
71 1.10 christos VALUE,
72 1.10 christos /* Register value is in another register. */
73 1.10 christos REALREG,
74 1.10 christos /* Register value is at an address. */
75 1.10 christos ADDR,
76 1.10 christos /* Register value is a sequence of bytes. */
77 1.10 christos VALUE_BYTES
78 1.10 christos };
79 1.1 christos
80 1.10 christos /* A struct that describes a saved register in a frame. */
81 1.1 christos
82 1.1 christos struct trad_frame_saved_reg
83 1.1 christos {
84 1.10 christos /* Setters */
85 1.10 christos
86 1.10 christos /* Encode that the saved register's value is constant VAL in the
87 1.10 christos trad-frame. */
88 1.10 christos void set_value (LONGEST val)
89 1.10 christos {
90 1.10 christos m_kind = trad_frame_saved_reg_kind::VALUE;
91 1.10 christos m_reg.value = val;
92 1.10 christos }
93 1.10 christos
94 1.10 christos /* Encode that the saved register's value is stored in register REALREG. */
95 1.10 christos void set_realreg (int realreg)
96 1.10 christos {
97 1.10 christos m_kind = trad_frame_saved_reg_kind::REALREG;
98 1.10 christos m_reg.realreg = realreg;
99 1.10 christos }
100 1.10 christos
101 1.10 christos /* Encode that the saved register's value is stored in memory at ADDR. */
102 1.10 christos void set_addr (LONGEST addr)
103 1.10 christos {
104 1.10 christos m_kind = trad_frame_saved_reg_kind::ADDR;
105 1.10 christos m_reg.addr = addr;
106 1.10 christos }
107 1.10 christos
108 1.10 christos /* Encode that the saved register's value is unknown. */
109 1.10 christos void set_unknown ()
110 1.10 christos {
111 1.10 christos m_kind = trad_frame_saved_reg_kind::UNKNOWN;
112 1.10 christos }
113 1.10 christos
114 1.10 christos /* Encode that the saved register's value is stored as a sequence of bytes.
115 1.10 christos This is useful when the value is larger than what primitive types
116 1.10 christos can hold. */
117 1.10 christos void set_value_bytes (gdb::array_view<const gdb_byte> bytes)
118 1.10 christos {
119 1.10 christos /* Allocate the space and copy the data bytes. */
120 1.10 christos gdb_byte *data = FRAME_OBSTACK_CALLOC (bytes.size (), gdb_byte);
121 1.10 christos memcpy (data, bytes.data (), bytes.size ());
122 1.10 christos
123 1.10 christos m_kind = trad_frame_saved_reg_kind::VALUE_BYTES;
124 1.10 christos m_reg.value_bytes = data;
125 1.10 christos }
126 1.10 christos
127 1.10 christos /* Getters */
128 1.10 christos
129 1.10 christos LONGEST value () const
130 1.10 christos {
131 1.10 christos gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE);
132 1.10 christos return m_reg.value;
133 1.10 christos }
134 1.10 christos
135 1.10 christos int realreg () const
136 1.10 christos {
137 1.10 christos gdb_assert (m_kind == trad_frame_saved_reg_kind::REALREG);
138 1.10 christos return m_reg.realreg;
139 1.10 christos }
140 1.10 christos
141 1.10 christos LONGEST addr () const
142 1.10 christos {
143 1.10 christos gdb_assert (m_kind == trad_frame_saved_reg_kind::ADDR);
144 1.10 christos return m_reg.addr;
145 1.10 christos }
146 1.10 christos
147 1.10 christos const gdb_byte *value_bytes () const
148 1.10 christos {
149 1.10 christos gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE_BYTES);
150 1.10 christos return m_reg.value_bytes;
151 1.10 christos }
152 1.10 christos
153 1.10 christos /* Convenience functions, return true if the register has been
154 1.10 christos encoded as specified. Return false otherwise. */
155 1.10 christos bool is_value () const
156 1.10 christos {
157 1.10 christos return m_kind == trad_frame_saved_reg_kind::VALUE;
158 1.10 christos }
159 1.10 christos
160 1.10 christos bool is_realreg () const
161 1.10 christos {
162 1.10 christos return m_kind == trad_frame_saved_reg_kind::REALREG;
163 1.10 christos }
164 1.10 christos
165 1.10 christos bool is_addr () const
166 1.10 christos {
167 1.10 christos return m_kind == trad_frame_saved_reg_kind::ADDR;
168 1.10 christos }
169 1.10 christos
170 1.10 christos bool is_unknown () const
171 1.10 christos {
172 1.10 christos return m_kind == trad_frame_saved_reg_kind::UNKNOWN;
173 1.10 christos }
174 1.10 christos
175 1.10 christos bool is_value_bytes () const
176 1.10 christos {
177 1.10 christos return m_kind == trad_frame_saved_reg_kind::VALUE_BYTES;
178 1.10 christos }
179 1.10 christos
180 1.10 christos private:
181 1.10 christos
182 1.10 christos trad_frame_saved_reg_kind m_kind;
183 1.10 christos
184 1.10 christos union {
185 1.10 christos LONGEST value;
186 1.10 christos int realreg;
187 1.10 christos LONGEST addr;
188 1.10 christos const gdb_byte *value_bytes;
189 1.10 christos } m_reg;
190 1.1 christos };
191 1.1 christos
192 1.10 christos /* Reset the saved regs cache, setting register values to REALREG. */
193 1.9 christos void trad_frame_reset_saved_regs (struct gdbarch *gdbarch,
194 1.10 christos trad_frame_saved_reg *regs);
195 1.1 christos
196 1.1 christos /* Return a freshly allocated (and initialized) trad_frame array. */
197 1.10 christos trad_frame_saved_reg *trad_frame_alloc_saved_regs (frame_info_ptr);
198 1.10 christos trad_frame_saved_reg *trad_frame_alloc_saved_regs (struct gdbarch *);
199 1.1 christos
200 1.1 christos /* Given the trad_frame info, return the location of the specified
201 1.1 christos register. */
202 1.10 christos struct value *trad_frame_get_prev_register (frame_info_ptr this_frame,
203 1.10 christos trad_frame_saved_reg this_saved_regs[],
204 1.1 christos int regnum);
205 1.1 christos
206 1.1 christos #endif
207