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