Add feature reference in .dat files
[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{
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
3aee8918
PA
50void
51init_target_desc (struct target_desc *tdesc)
52{
c4dfafab 53 int offset = 0;
3aee8918 54
ea3e7d71 55 /* Go through all the features and populate reg_defs. */
82ec9bc7
AH
56 for (const tdesc_feature_up &feature : tdesc->features)
57 for (const tdesc_reg_up &treg : feature->registers)
58 {
59 int regnum = treg->target_regnum;
ea3e7d71 60
82ec9bc7
AH
61 /* Register number will increase (possibly with gaps) or be zero. */
62 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
ea3e7d71 63
82ec9bc7
AH
64 if (regnum != 0)
65 tdesc->reg_defs.resize (regnum, reg (offset));
ea3e7d71 66
82ec9bc7
AH
67 tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
68 treg->bitsize);
69 offset += treg->bitsize;
70 }
3aee8918
PA
71
72 tdesc->registers_size = offset / 8;
73
74 /* Make sure PBUFSIZ is large enough to hold a full register
75 packet. */
38e08fca 76 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
3aee8918
PA
77}
78
5f035c07
YQ
79struct target_desc *
80allocate_target_description (void)
81{
82 return new target_desc ();
83}
84
3aee8918
PA
85#ifndef IN_PROCESS_AGENT
86
f49ff000 87static const struct target_desc default_description {};
3aee8918
PA
88
89void
90copy_target_description (struct target_desc *dest,
91 const struct target_desc *src)
92{
93 dest->reg_defs = src->reg_defs;
3aee8918
PA
94 dest->expedite_regs = src->expedite_regs;
95 dest->registers_size = src->registers_size;
96 dest->xmltarget = src->xmltarget;
97}
98
99const struct target_desc *
100current_target_desc (void)
101{
0bfdf32f 102 if (current_thread == NULL)
3aee8918
PA
103 return &default_description;
104
105 return current_process ()->tdesc;
106}
0abe8a89 107
f46cd62a 108/* See common/tdesc.h. */
5f035c07 109
d278f585
AH
110const char *
111tdesc_architecture_name (const struct target_desc *target_desc)
112{
113 return target_desc->arch;
114}
115
116/* See common/tdesc.h. */
117
0abe8a89
YQ
118void
119set_tdesc_architecture (struct target_desc *target_desc,
120 const char *name)
121{
122 target_desc->arch = xstrdup (name);
123}
124
f46cd62a 125/* See common/tdesc.h. */
5f035c07 126
d278f585
AH
127const char *
128tdesc_osabi_name (const struct target_desc *target_desc)
129{
130 return target_desc->osabi;
131}
132
133/* See common/tdesc.h. */
134
0abe8a89
YQ
135void
136set_tdesc_osabi (struct target_desc *target_desc, const char *name)
137{
138 target_desc->osabi = xstrdup (name);
139}
140
141/* Return a string which is of XML format, including XML target
142 description to be sent to GDB. */
143
144const char *
145tdesc_get_features_xml (target_desc *tdesc)
146{
147 /* Either .xmltarget or .features is not NULL. */
148 gdb_assert (tdesc->xmltarget != NULL
17d08cd4 149 || (!tdesc->features.empty ()
1d0aa65c 150 && tdesc->arch != NULL));
0abe8a89
YQ
151
152 if (tdesc->xmltarget == NULL)
153 {
154 std::string buffer ("@<?xml version=\"1.0\"?>");
155
156 buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
157 buffer += "<target>";
158 buffer += "<architecture>";
d278f585 159 buffer += tdesc_architecture_name (tdesc);
0abe8a89
YQ
160 buffer += "</architecture>";
161
d278f585
AH
162 const char *osabi = tdesc_osabi_name (tdesc);
163 if (osabi != nullptr)
1d0aa65c
AH
164 {
165 buffer += "<osabi>";
d278f585 166 buffer += osabi;
1d0aa65c
AH
167 buffer += "</osabi>";
168 }
0abe8a89 169
82ec9bc7 170 for (const tdesc_feature_up &feature : tdesc->features)
0abe8a89
YQ
171 {
172 buffer += "<xi:include href=\"";
82ec9bc7 173 buffer += feature->name;
0abe8a89
YQ
174 buffer += "\"/>";
175 }
176
177 buffer += "</target>";
178
179 tdesc->xmltarget = xstrdup (buffer.c_str ());
180 }
181
182 return tdesc->xmltarget;
183}
3aee8918 184#endif
f49ff000 185
f46cd62a 186/* See common/tdesc.h. */
f49ff000
YQ
187
188struct tdesc_feature *
0abe8a89
YQ
189tdesc_create_feature (struct target_desc *tdesc, const char *name,
190 const char *xml)
f49ff000 191{
82ec9bc7
AH
192 struct tdesc_feature *new_feature = new tdesc_feature
193 (xml != nullptr ? xml : name);
194 tdesc->features.emplace_back (new_feature);
195 return new_feature;
f49ff000 196}
This page took 0.463429 seconds and 4 git commands to generate.