Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdbserver / tdesc.cc
CommitLineData
3666a048 1/* Copyright (C) 2012-2021 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{
d80e5242
AH
26 xfree ((char *) arch);
27 xfree ((char *) osabi);
d80e5242
AH
28}
29
30bool target_desc::operator== (const target_desc &other) const
31{
5cd3e386 32 if (reg_defs != other.reg_defs)
d80e5242
AH
33 return false;
34
d80e5242
AH
35 /* Compare expedite_regs. */
36 int i = 0;
37 for (; expedite_regs[i] != NULL; i++)
38 {
39 if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
40 return false;
41 }
42 if (other.expedite_regs[i] != NULL)
43 return false;
44
45 return true;
46}
47
48#endif
49
e98577a9
AH
50void target_desc::accept (tdesc_element_visitor &v) const
51{
52#ifndef IN_PROCESS_AGENT
53 v.visit_pre (this);
54
55 for (const tdesc_feature_up &feature : features)
56 feature->accept (v);
57
58 v.visit_post (this);
59#endif
60}
61
3aee8918 62void
190852c8
JB
63init_target_desc (struct target_desc *tdesc,
64 const char **expedite_regs)
3aee8918 65{
c4dfafab 66 int offset = 0;
3aee8918 67
ea3e7d71 68 /* Go through all the features and populate reg_defs. */
82ec9bc7
AH
69 for (const tdesc_feature_up &feature : tdesc->features)
70 for (const tdesc_reg_up &treg : feature->registers)
71 {
72 int regnum = treg->target_regnum;
ea3e7d71 73
82ec9bc7
AH
74 /* Register number will increase (possibly with gaps) or be zero. */
75 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
ea3e7d71 76
82ec9bc7 77 if (regnum != 0)
5a82b8a1 78 tdesc->reg_defs.resize (regnum, gdb::reg (offset));
ea3e7d71 79
82ec9bc7
AH
80 tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
81 treg->bitsize);
82 offset += treg->bitsize;
83 }
3aee8918
PA
84
85 tdesc->registers_size = offset / 8;
86
87 /* Make sure PBUFSIZ is large enough to hold a full register
88 packet. */
38e08fca 89 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
190852c8
JB
90
91#ifndef IN_PROCESS_AGENT
92 tdesc->expedite_regs = expedite_regs;
93#endif
3aee8918
PA
94}
95
0e267416
AB
96/* See gdbsupport/tdesc.h. */
97
51a948fd 98target_desc_up
5f035c07
YQ
99allocate_target_description (void)
100{
51a948fd 101 return target_desc_up (new target_desc ());
5f035c07
YQ
102}
103
0e267416
AB
104/* See gdbsupport/tdesc.h. */
105
106void
107target_desc_deleter::operator() (struct target_desc *target_desc) const
108{
109 delete target_desc;
110}
111
3aee8918
PA
112#ifndef IN_PROCESS_AGENT
113
f49ff000 114static const struct target_desc default_description {};
3aee8918
PA
115
116void
117copy_target_description (struct target_desc *dest,
118 const struct target_desc *src)
119{
120 dest->reg_defs = src->reg_defs;
3aee8918
PA
121 dest->expedite_regs = src->expedite_regs;
122 dest->registers_size = src->registers_size;
123 dest->xmltarget = src->xmltarget;
124}
125
126const struct target_desc *
127current_target_desc (void)
128{
0bfdf32f 129 if (current_thread == NULL)
3aee8918
PA
130 return &default_description;
131
132 return current_process ()->tdesc;
133}
0abe8a89 134
fbf42f4e
AB
135/* An empty structure. */
136
137struct tdesc_compatible_info { };
138
139/* See gdbsupport/tdesc.h. */
140
141const std::vector<tdesc_compatible_info_up> &
142tdesc_compatible_info_list (const target_desc *target_desc)
143{
144 static std::vector<tdesc_compatible_info_up> empty;
145 return empty;
146}
147
148/* See gdbsupport/tdesc.h. */
149
150const char *
151tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info)
152{
153 return nullptr;
154}
155
268a13a5 156/* See gdbsupport/tdesc.h. */
5f035c07 157
d278f585
AH
158const char *
159tdesc_architecture_name (const struct target_desc *target_desc)
160{
161 return target_desc->arch;
162}
163
268a13a5 164/* See gdbsupport/tdesc.h. */
d278f585 165
0abe8a89
YQ
166void
167set_tdesc_architecture (struct target_desc *target_desc,
168 const char *name)
169{
170 target_desc->arch = xstrdup (name);
171}
172
268a13a5 173/* See gdbsupport/tdesc.h. */
5f035c07 174
d278f585
AH
175const char *
176tdesc_osabi_name (const struct target_desc *target_desc)
177{
178 return target_desc->osabi;
179}
180
268a13a5 181/* See gdbsupport/tdesc.h. */
d278f585 182
0abe8a89
YQ
183void
184set_tdesc_osabi (struct target_desc *target_desc, const char *name)
185{
186 target_desc->osabi = xstrdup (name);
187}
188
268a13a5 189/* See gdbsupport/tdesc.h. */
0abe8a89
YQ
190
191const char *
e98577a9 192tdesc_get_features_xml (const target_desc *tdesc)
0abe8a89
YQ
193{
194 /* Either .xmltarget or .features is not NULL. */
195 gdb_assert (tdesc->xmltarget != NULL
17d08cd4 196 || (!tdesc->features.empty ()
1d0aa65c 197 && tdesc->arch != NULL));
0abe8a89
YQ
198
199 if (tdesc->xmltarget == NULL)
200 {
e98577a9
AH
201 std::string buffer ("@");
202 print_xml_feature v (&buffer);
203 tdesc->accept (v);
0abe8a89
YQ
204 tdesc->xmltarget = xstrdup (buffer.c_str ());
205 }
206
207 return tdesc->xmltarget;
208}
3aee8918 209#endif
f49ff000 210
268a13a5 211/* See gdbsupport/tdesc.h. */
f49ff000
YQ
212
213struct tdesc_feature *
3b74854b 214tdesc_create_feature (struct target_desc *tdesc, const char *name)
f49ff000 215{
3b74854b 216 struct tdesc_feature *new_feature = new tdesc_feature (name);
82ec9bc7
AH
217 tdesc->features.emplace_back (new_feature);
218 return new_feature;
f49ff000 219}
6cdd651f
LM
220
221/* See gdbsupport/tdesc.h. */
222
223bool
224tdesc_contains_feature (const target_desc *tdesc, const std::string &feature)
225{
226 gdb_assert (tdesc != nullptr);
227
228 for (const tdesc_feature_up &f : tdesc->features)
229 {
230 if (f->name == feature)
231 return true;
232 }
233
234 return false;
235}
This page took 0.636316 seconds and 4 git commands to generate.