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