]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | /* Copyright (C) 2012-2023 Free Software Foundation, Inc. |
3aee8918 PA |
2 | |
3 | This file is part of GDB. | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include "server.h" | |
19 | #include "tdesc.h" | |
20 | #include "regdef.h" | |
21 | ||
d80e5242 AH |
22 | #ifndef IN_PROCESS_AGENT |
23 | ||
24 | target_desc::~target_desc () | |
25 | { | |
d80e5242 AH |
26 | xfree ((char *) arch); |
27 | xfree ((char *) osabi); | |
d80e5242 AH |
28 | } |
29 | ||
30 | bool target_desc::operator== (const target_desc &other) const | |
31 | { | |
5cd3e386 | 32 | if (reg_defs != other.reg_defs) |
d80e5242 AH |
33 | return false; |
34 | ||
6a65998a LM |
35 | /* Compare the two vectors of expedited registers. They will only match |
36 | if the following conditions are met: | |
37 | ||
38 | - Both vectors have the same number of elements. | |
39 | - Both vectors contain the same elements. | |
40 | - The elements of both vectors appear in the same order. */ | |
41 | if (expedite_regs != other.expedite_regs) | |
d80e5242 AH |
42 | return false; |
43 | ||
44 | return true; | |
45 | } | |
46 | ||
47 | #endif | |
48 | ||
e98577a9 AH |
49 | void target_desc::accept (tdesc_element_visitor &v) const |
50 | { | |
51 | #ifndef IN_PROCESS_AGENT | |
52 | v.visit_pre (this); | |
53 | ||
54 | for (const tdesc_feature_up &feature : features) | |
55 | feature->accept (v); | |
56 | ||
57 | v.visit_post (this); | |
58 | #endif | |
59 | } | |
60 | ||
3aee8918 | 61 | void |
190852c8 JB |
62 | init_target_desc (struct target_desc *tdesc, |
63 | const char **expedite_regs) | |
3aee8918 | 64 | { |
c4dfafab | 65 | int offset = 0; |
3aee8918 | 66 | |
ea3e7d71 | 67 | /* Go through all the features and populate reg_defs. */ |
82ec9bc7 AH |
68 | for (const tdesc_feature_up &feature : tdesc->features) |
69 | for (const tdesc_reg_up &treg : feature->registers) | |
70 | { | |
71 | int regnum = treg->target_regnum; | |
ea3e7d71 | 72 | |
82ec9bc7 AH |
73 | /* Register number will increase (possibly with gaps) or be zero. */ |
74 | gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ()); | |
ea3e7d71 | 75 | |
82ec9bc7 | 76 | if (regnum != 0) |
5a82b8a1 | 77 | tdesc->reg_defs.resize (regnum, gdb::reg (offset)); |
ea3e7d71 | 78 | |
82ec9bc7 AH |
79 | tdesc->reg_defs.emplace_back (treg->name.c_str (), offset, |
80 | treg->bitsize); | |
81 | offset += treg->bitsize; | |
82 | } | |
3aee8918 PA |
83 | |
84 | tdesc->registers_size = offset / 8; | |
85 | ||
86 | /* Make sure PBUFSIZ is large enough to hold a full register | |
87 | packet. */ | |
38e08fca | 88 | gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ); |
190852c8 JB |
89 | |
90 | #ifndef IN_PROCESS_AGENT | |
6a65998a LM |
91 | /* Drop the contents of the previous vector, if any. */ |
92 | tdesc->expedite_regs.clear (); | |
93 | ||
94 | /* Initialize the vector with new expedite registers contents. */ | |
95 | int expedite_count = 0; | |
96 | while (expedite_regs[expedite_count] != nullptr) | |
97 | tdesc->expedite_regs.push_back (expedite_regs[expedite_count++]); | |
190852c8 | 98 | #endif |
3aee8918 PA |
99 | } |
100 | ||
0e267416 AB |
101 | /* See gdbsupport/tdesc.h. */ |
102 | ||
51a948fd | 103 | target_desc_up |
5f035c07 YQ |
104 | allocate_target_description (void) |
105 | { | |
51a948fd | 106 | return target_desc_up (new target_desc ()); |
5f035c07 YQ |
107 | } |
108 | ||
0e267416 AB |
109 | /* See gdbsupport/tdesc.h. */ |
110 | ||
111 | void | |
112 | target_desc_deleter::operator() (struct target_desc *target_desc) const | |
113 | { | |
114 | delete target_desc; | |
115 | } | |
116 | ||
3aee8918 PA |
117 | #ifndef IN_PROCESS_AGENT |
118 | ||
f49ff000 | 119 | static const struct target_desc default_description {}; |
3aee8918 PA |
120 | |
121 | void | |
122 | copy_target_description (struct target_desc *dest, | |
123 | const struct target_desc *src) | |
124 | { | |
125 | dest->reg_defs = src->reg_defs; | |
3aee8918 PA |
126 | dest->expedite_regs = src->expedite_regs; |
127 | dest->registers_size = src->registers_size; | |
128 | dest->xmltarget = src->xmltarget; | |
129 | } | |
130 | ||
131 | const struct target_desc * | |
132 | current_target_desc (void) | |
133 | { | |
0bfdf32f | 134 | if (current_thread == NULL) |
3aee8918 PA |
135 | return &default_description; |
136 | ||
137 | return current_process ()->tdesc; | |
138 | } | |
0abe8a89 | 139 | |
fbf42f4e AB |
140 | /* An empty structure. */ |
141 | ||
142 | struct tdesc_compatible_info { }; | |
143 | ||
144 | /* See gdbsupport/tdesc.h. */ | |
145 | ||
146 | const std::vector<tdesc_compatible_info_up> & | |
147 | tdesc_compatible_info_list (const target_desc *target_desc) | |
148 | { | |
149 | static std::vector<tdesc_compatible_info_up> empty; | |
150 | return empty; | |
151 | } | |
152 | ||
153 | /* See gdbsupport/tdesc.h. */ | |
154 | ||
155 | const char * | |
156 | tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info) | |
157 | { | |
158 | return nullptr; | |
159 | } | |
160 | ||
268a13a5 | 161 | /* See gdbsupport/tdesc.h. */ |
5f035c07 | 162 | |
d278f585 AH |
163 | const char * |
164 | tdesc_architecture_name (const struct target_desc *target_desc) | |
165 | { | |
166 | return target_desc->arch; | |
167 | } | |
168 | ||
268a13a5 | 169 | /* See gdbsupport/tdesc.h. */ |
d278f585 | 170 | |
0abe8a89 YQ |
171 | void |
172 | set_tdesc_architecture (struct target_desc *target_desc, | |
173 | const char *name) | |
174 | { | |
175 | target_desc->arch = xstrdup (name); | |
176 | } | |
177 | ||
268a13a5 | 178 | /* See gdbsupport/tdesc.h. */ |
5f035c07 | 179 | |
d278f585 AH |
180 | const char * |
181 | tdesc_osabi_name (const struct target_desc *target_desc) | |
182 | { | |
183 | return target_desc->osabi; | |
184 | } | |
185 | ||
268a13a5 | 186 | /* See gdbsupport/tdesc.h. */ |
d278f585 | 187 | |
0abe8a89 YQ |
188 | void |
189 | set_tdesc_osabi (struct target_desc *target_desc, const char *name) | |
190 | { | |
191 | target_desc->osabi = xstrdup (name); | |
192 | } | |
193 | ||
268a13a5 | 194 | /* See gdbsupport/tdesc.h. */ |
0abe8a89 YQ |
195 | |
196 | const char * | |
e98577a9 | 197 | tdesc_get_features_xml (const target_desc *tdesc) |
0abe8a89 YQ |
198 | { |
199 | /* Either .xmltarget or .features is not NULL. */ | |
200 | gdb_assert (tdesc->xmltarget != NULL | |
17d08cd4 | 201 | || (!tdesc->features.empty () |
1d0aa65c | 202 | && tdesc->arch != NULL)); |
0abe8a89 YQ |
203 | |
204 | if (tdesc->xmltarget == NULL) | |
205 | { | |
e98577a9 AH |
206 | std::string buffer ("@"); |
207 | print_xml_feature v (&buffer); | |
208 | tdesc->accept (v); | |
0abe8a89 YQ |
209 | tdesc->xmltarget = xstrdup (buffer.c_str ()); |
210 | } | |
211 | ||
212 | return tdesc->xmltarget; | |
213 | } | |
3aee8918 | 214 | #endif |
f49ff000 | 215 | |
268a13a5 | 216 | /* See gdbsupport/tdesc.h. */ |
f49ff000 YQ |
217 | |
218 | struct tdesc_feature * | |
3b74854b | 219 | tdesc_create_feature (struct target_desc *tdesc, const char *name) |
f49ff000 | 220 | { |
3b74854b | 221 | struct tdesc_feature *new_feature = new tdesc_feature (name); |
82ec9bc7 AH |
222 | tdesc->features.emplace_back (new_feature); |
223 | return new_feature; | |
f49ff000 | 224 | } |
6cdd651f LM |
225 | |
226 | /* See gdbsupport/tdesc.h. */ | |
227 | ||
228 | bool | |
229 | tdesc_contains_feature (const target_desc *tdesc, const std::string &feature) | |
230 | { | |
231 | gdb_assert (tdesc != nullptr); | |
232 | ||
233 | for (const tdesc_feature_up &f : tdesc->features) | |
234 | { | |
235 | if (f->name == feature) | |
236 | return true; | |
237 | } | |
238 | ||
239 | return false; | |
240 | } |