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