Make gdbserver reg_defs a vector of objects
[deliverable/binutils-gdb.git] / gdb / gdbserver / tdesc.c
1 /* Copyright (C) 2012-2018 Free Software Foundation, Inc.
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
22 #ifndef IN_PROCESS_AGENT
23
24 target_desc::~target_desc ()
25 {
26 int i;
27
28 xfree ((char *) arch);
29 xfree ((char *) osabi);
30
31 char *f;
32
33 for (i = 0; VEC_iterate (char_ptr, features, i, f); i++)
34 xfree (f);
35 VEC_free (char_ptr, features);
36 }
37
38 bool target_desc::operator== (const target_desc &other) const
39 {
40 if (reg_defs != other.reg_defs)
41 return false;
42
43 /* Compare expedite_regs. */
44 int i = 0;
45 for (; expedite_regs[i] != NULL; i++)
46 {
47 if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
48 return false;
49 }
50 if (other.expedite_regs[i] != NULL)
51 return false;
52
53 return true;
54 }
55
56 #endif
57
58 void
59 init_target_desc (struct target_desc *tdesc)
60 {
61 int offset = 0;
62
63 for (reg &reg : tdesc->reg_defs)
64 {
65 reg.offset = offset;
66 offset += reg.size;
67 }
68
69 tdesc->registers_size = offset / 8;
70
71 /* Make sure PBUFSIZ is large enough to hold a full register
72 packet. */
73 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
74 }
75
76 struct target_desc *
77 allocate_target_description (void)
78 {
79 return new target_desc ();
80 }
81
82 #ifndef IN_PROCESS_AGENT
83
84 static const struct target_desc default_description {};
85
86 void
87 copy_target_description (struct target_desc *dest,
88 const struct target_desc *src)
89 {
90 dest->reg_defs = src->reg_defs;
91 dest->expedite_regs = src->expedite_regs;
92 dest->registers_size = src->registers_size;
93 dest->xmltarget = src->xmltarget;
94 }
95
96 const struct target_desc *
97 current_target_desc (void)
98 {
99 if (current_thread == NULL)
100 return &default_description;
101
102 return current_process ()->tdesc;
103 }
104
105 /* See common/tdesc.h. */
106
107 void
108 set_tdesc_architecture (struct target_desc *target_desc,
109 const char *name)
110 {
111 target_desc->arch = xstrdup (name);
112 }
113
114 /* See common/tdesc.h. */
115
116 void
117 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
118 {
119 target_desc->osabi = xstrdup (name);
120 }
121
122 /* Return a string which is of XML format, including XML target
123 description to be sent to GDB. */
124
125 const char *
126 tdesc_get_features_xml (target_desc *tdesc)
127 {
128 /* Either .xmltarget or .features is not NULL. */
129 gdb_assert (tdesc->xmltarget != NULL
130 || (tdesc->features != NULL
131 && tdesc->arch != NULL));
132
133 if (tdesc->xmltarget == NULL)
134 {
135 std::string buffer ("@<?xml version=\"1.0\"?>");
136
137 buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
138 buffer += "<target>";
139 buffer += "<architecture>";
140 buffer += tdesc->arch;
141 buffer += "</architecture>";
142
143 if (tdesc->osabi != nullptr)
144 {
145 buffer += "<osabi>";
146 buffer += tdesc->osabi;
147 buffer += "</osabi>";
148 }
149
150 char *xml;
151
152 for (int i = 0; VEC_iterate (char_ptr, tdesc->features, i, xml); i++)
153 {
154 buffer += "<xi:include href=\"";
155 buffer += xml;
156 buffer += "\"/>";
157 }
158
159 buffer += "</target>";
160
161 tdesc->xmltarget = xstrdup (buffer.c_str ());
162 }
163
164 return tdesc->xmltarget;
165 }
166 #endif
167
168 struct tdesc_type
169 {};
170
171 /* See common/tdesc.h. */
172
173 struct tdesc_feature *
174 tdesc_create_feature (struct target_desc *tdesc, const char *name,
175 const char *xml)
176 {
177 #ifndef IN_PROCESS_AGENT
178 VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml));
179 #endif
180 return tdesc;
181 }
182
183 /* See common/tdesc.h. */
184
185 tdesc_type_with_fields *
186 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
187 int size)
188 {
189 return NULL;
190 }
191
192 /* See common/tdesc.h. */
193
194 void
195 tdesc_add_flag (tdesc_type_with_fields *type, int start,
196 const char *flag_name)
197 {}
198
199 /* See common/tdesc.h. */
200
201 struct tdesc_type *
202 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
203 {
204 return NULL;
205 }
206
207 /* See common/tdesc.h. */
208
209 tdesc_type_with_fields *
210 tdesc_create_union (struct tdesc_feature *feature, const char *id)
211 {
212 return NULL;
213 }
214
215 /* See common/tdesc.h. */
216
217 tdesc_type_with_fields *
218 tdesc_create_struct (struct tdesc_feature *feature, const char *id)
219 {
220 return NULL;
221 }
222
223 /* See common/tdesc.h. */
224
225 void
226 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
227 int regnum, int save_restore, const char *group,
228 int bitsize, const char *type)
229 {
230 struct target_desc *tdesc = (struct target_desc *) feature;
231
232 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
233
234 if (regnum != 0)
235 tdesc->reg_defs.resize (regnum);
236
237 tdesc->reg_defs.emplace_back (name, bitsize);
238 }
239
240 /* See common/tdesc.h. */
241
242 struct tdesc_type *
243 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
244 struct tdesc_type *field_type, int count)
245 {
246 return NULL;
247 }
248
249 void
250 tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
251 int start, int end)
252 {}
253
254 /* See common/tdesc.h. */
255
256 void
257 tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
258 struct tdesc_type *field_type)
259 {}
260
261 /* See common/tdesc.h. */
262
263 void
264 tdesc_set_struct_size (tdesc_type_with_fields *type, int size)
265 {
266 }
This page took 0.040022 seconds and 5 git commands to generate.