Use std::vector in uploaded_tp
[deliverable/binutils-gdb.git] / gdb / gdbserver / tdesc.c
CommitLineData
e2882c85 1/* Copyright (C) 2012-2018 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
24target_desc::~target_desc ()
25{
26 int i;
27
d80e5242
AH
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
38bool target_desc::operator== (const target_desc &other) const
39{
5cd3e386 40 if (reg_defs != other.reg_defs)
d80e5242
AH
41 return false;
42
d80e5242
AH
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
3aee8918
PA
58void
59init_target_desc (struct target_desc *tdesc)
60{
c4dfafab 61 int offset = 0;
3aee8918 62
5cd3e386 63 for (reg &reg : tdesc->reg_defs)
3aee8918 64 {
5cd3e386
AH
65 reg.offset = offset;
66 offset += reg.size;
3aee8918
PA
67 }
68
69 tdesc->registers_size = offset / 8;
70
71 /* Make sure PBUFSIZ is large enough to hold a full register
72 packet. */
38e08fca 73 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
3aee8918
PA
74}
75
5f035c07
YQ
76struct target_desc *
77allocate_target_description (void)
78{
79 return new target_desc ();
80}
81
3aee8918
PA
82#ifndef IN_PROCESS_AGENT
83
f49ff000 84static const struct target_desc default_description {};
3aee8918
PA
85
86void
87copy_target_description (struct target_desc *dest,
88 const struct target_desc *src)
89{
90 dest->reg_defs = src->reg_defs;
3aee8918
PA
91 dest->expedite_regs = src->expedite_regs;
92 dest->registers_size = src->registers_size;
93 dest->xmltarget = src->xmltarget;
94}
95
96const struct target_desc *
97current_target_desc (void)
98{
0bfdf32f 99 if (current_thread == NULL)
3aee8918
PA
100 return &default_description;
101
102 return current_process ()->tdesc;
103}
0abe8a89 104
f46cd62a 105/* See common/tdesc.h. */
5f035c07 106
0abe8a89
YQ
107void
108set_tdesc_architecture (struct target_desc *target_desc,
109 const char *name)
110{
111 target_desc->arch = xstrdup (name);
112}
113
f46cd62a 114/* See common/tdesc.h. */
5f035c07 115
0abe8a89
YQ
116void
117set_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
125const char *
126tdesc_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
1d0aa65c 131 && tdesc->arch != NULL));
0abe8a89
YQ
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
1d0aa65c
AH
143 if (tdesc->osabi != nullptr)
144 {
145 buffer += "<osabi>";
146 buffer += tdesc->osabi;
147 buffer += "</osabi>";
148 }
0abe8a89
YQ
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}
3aee8918 166#endif
f49ff000
YQ
167
168struct tdesc_type
169{};
170
f46cd62a 171/* See common/tdesc.h. */
f49ff000
YQ
172
173struct tdesc_feature *
0abe8a89
YQ
174tdesc_create_feature (struct target_desc *tdesc, const char *name,
175 const char *xml)
f49ff000 176{
0abe8a89
YQ
177#ifndef IN_PROCESS_AGENT
178 VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml));
179#endif
f49ff000
YQ
180 return tdesc;
181}
182
f46cd62a 183/* See common/tdesc.h. */
f49ff000 184
d4a0e8b5 185tdesc_type_with_fields *
f49ff000
YQ
186tdesc_create_flags (struct tdesc_feature *feature, const char *name,
187 int size)
188{
189 return NULL;
190}
191
f46cd62a 192/* See common/tdesc.h. */
f49ff000
YQ
193
194void
d4a0e8b5 195tdesc_add_flag (tdesc_type_with_fields *type, int start,
f49ff000
YQ
196 const char *flag_name)
197{}
198
f46cd62a 199/* See common/tdesc.h. */
f49ff000
YQ
200
201struct tdesc_type *
202tdesc_named_type (const struct tdesc_feature *feature, const char *id)
203{
204 return NULL;
205}
206
f46cd62a 207/* See common/tdesc.h. */
f49ff000 208
d4a0e8b5 209tdesc_type_with_fields *
f49ff000
YQ
210tdesc_create_union (struct tdesc_feature *feature, const char *id)
211{
212 return NULL;
213}
214
f46cd62a 215/* See common/tdesc.h. */
f49ff000 216
d4a0e8b5 217tdesc_type_with_fields *
f49ff000
YQ
218tdesc_create_struct (struct tdesc_feature *feature, const char *id)
219{
220 return NULL;
221}
222
f46cd62a 223/* See common/tdesc.h. */
f49ff000
YQ
224
225void
226tdesc_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
5cd3e386 232 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
f49ff000 233
5cd3e386
AH
234 if (regnum != 0)
235 tdesc->reg_defs.resize (regnum);
f49ff000 236
5cd3e386 237 tdesc->reg_defs.emplace_back (name, bitsize);
f49ff000
YQ
238}
239
f46cd62a 240/* See common/tdesc.h. */
f49ff000
YQ
241
242struct tdesc_type *
243tdesc_create_vector (struct tdesc_feature *feature, const char *name,
244 struct tdesc_type *field_type, int count)
245{
246 return NULL;
247}
248
249void
d4a0e8b5 250tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
f49ff000
YQ
251 int start, int end)
252{}
253
f46cd62a 254/* See common/tdesc.h. */
f49ff000
YQ
255
256void
d4a0e8b5 257tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
f49ff000
YQ
258 struct tdesc_type *field_type)
259{}
260
f46cd62a 261/* See common/tdesc.h. */
f49ff000
YQ
262
263void
d4a0e8b5 264tdesc_set_struct_size (tdesc_type_with_fields *type, int size)
f49ff000
YQ
265{
266}
This page took 0.558416 seconds and 4 git commands to generate.