Dynamically composite xml in reply to GDB
[deliverable/binutils-gdb.git] / gdb / gdbserver / tdesc.c
1 /* Copyright (C) 2012-2017 Free Software Foundation, Inc.
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
22 void
23 init_target_desc (struct target_desc *tdesc)
24 {
25 int offset, i;
26 struct reg *reg;
27
28 offset = 0;
29 for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
30 {
31 reg->offset = offset;
32 offset += reg->size;
33 }
34
35 tdesc->registers_size = offset / 8;
36
37 /* Make sure PBUFSIZ is large enough to hold a full register
38 packet. */
39 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
40 }
41
42 #ifndef IN_PROCESS_AGENT
43
44 static const struct target_desc default_description {};
45
46 void
47 copy_target_description (struct target_desc *dest,
48 const struct target_desc *src)
49 {
50 dest->reg_defs = src->reg_defs;
51 dest->expedite_regs = src->expedite_regs;
52 dest->registers_size = src->registers_size;
53 dest->xmltarget = src->xmltarget;
54 }
55
56 const struct target_desc *
57 current_target_desc (void)
58 {
59 if (current_thread == NULL)
60 return &default_description;
61
62 return current_process ()->tdesc;
63 }
64
65 void
66 set_tdesc_architecture (struct target_desc *target_desc,
67 const char *name)
68 {
69 target_desc->arch = xstrdup (name);
70 }
71
72 void
73 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
74 {
75 target_desc->osabi = xstrdup (name);
76 }
77
78 /* Return a string which is of XML format, including XML target
79 description to be sent to GDB. */
80
81 const char *
82 tdesc_get_features_xml (target_desc *tdesc)
83 {
84 /* Either .xmltarget or .features is not NULL. */
85 gdb_assert (tdesc->xmltarget != NULL
86 || (tdesc->features != NULL
87 && tdesc->arch != NULL
88 && tdesc->osabi != NULL));
89
90 if (tdesc->xmltarget == NULL)
91 {
92 std::string buffer ("@<?xml version=\"1.0\"?>");
93
94 buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
95 buffer += "<target>";
96 buffer += "<architecture>";
97 buffer += tdesc->arch;
98 buffer += "</architecture>";
99
100 buffer += "<osabi>";
101 buffer += tdesc->osabi;
102 buffer += "</osabi>";
103
104 char *xml;
105
106 for (int i = 0; VEC_iterate (char_ptr, tdesc->features, i, xml); i++)
107 {
108 buffer += "<xi:include href=\"";
109 buffer += xml;
110 buffer += "\"/>";
111 }
112
113 buffer += "</target>";
114
115 tdesc->xmltarget = xstrdup (buffer.c_str ());
116 }
117
118 return tdesc->xmltarget;
119 }
120 #endif
121
122 struct tdesc_type
123 {};
124
125 /* See arch/tdesc.h. */
126
127 struct tdesc_feature *
128 tdesc_create_feature (struct target_desc *tdesc, const char *name,
129 const char *xml)
130 {
131 #ifndef IN_PROCESS_AGENT
132 VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml));
133 #endif
134 return tdesc;
135 }
136
137 /* See arch/tdesc.h. */
138
139 struct tdesc_type *
140 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
141 int size)
142 {
143 return NULL;
144 }
145
146 /* See arch/tdesc.h. */
147
148 void
149 tdesc_add_flag (struct tdesc_type *type, int start,
150 const char *flag_name)
151 {}
152
153 /* See arch/tdesc.h. */
154
155 struct tdesc_type *
156 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
157 {
158 return NULL;
159 }
160
161 /* See arch/tdesc.h. */
162
163 struct tdesc_type *
164 tdesc_create_union (struct tdesc_feature *feature, const char *id)
165 {
166 return NULL;
167 }
168
169 /* See arch/tdesc.h. */
170
171 struct tdesc_type *
172 tdesc_create_struct (struct tdesc_feature *feature, const char *id)
173 {
174 return NULL;
175 }
176
177 /* See arch/tdesc.h. */
178
179 void
180 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
181 int regnum, int save_restore, const char *group,
182 int bitsize, const char *type)
183 {
184 struct target_desc *tdesc = (struct target_desc *) feature;
185
186 while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum)
187 {
188 struct reg *reg = XCNEW (struct reg);
189
190 reg->name = "";
191 reg->size = 0;
192 VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
193 }
194
195 gdb_assert (regnum == 0
196 || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs));
197
198 struct reg *reg = XCNEW (struct reg);
199
200 reg->name = name;
201 reg->size = bitsize;
202 VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
203 }
204
205 /* See arch/tdesc.h. */
206
207 struct tdesc_type *
208 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
209 struct tdesc_type *field_type, int count)
210 {
211 return NULL;
212 }
213
214 void
215 tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
216 int start, int end)
217 {}
218
219 /* See arch/tdesc.h. */
220
221 void
222 tdesc_add_field (struct tdesc_type *type, const char *field_name,
223 struct tdesc_type *field_type)
224 {}
225
226 /* See arch/tdesc.h. */
227
228 void
229 tdesc_set_struct_size (struct tdesc_type *type, int size)
230 {
231 }
This page took 0.036678 seconds and 4 git commands to generate.