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