Commit | Line | Data |
---|---|---|
61baf725 | 1 | /* Copyright (C) 2012-2017 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 | ||
22 | void | |
23 | init_target_desc (struct target_desc *tdesc) | |
24 | { | |
c4dfafab | 25 | int offset = 0; |
3aee8918 | 26 | |
c4dfafab | 27 | for (reg *reg : tdesc->reg_defs) |
3aee8918 | 28 | { |
f7000548 YQ |
29 | reg->offset = offset; |
30 | offset += reg->size; | |
3aee8918 PA |
31 | } |
32 | ||
33 | tdesc->registers_size = offset / 8; | |
34 | ||
35 | /* Make sure PBUFSIZ is large enough to hold a full register | |
36 | packet. */ | |
38e08fca | 37 | gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ); |
3aee8918 PA |
38 | } |
39 | ||
5f035c07 YQ |
40 | struct target_desc * |
41 | allocate_target_description (void) | |
42 | { | |
43 | return new target_desc (); | |
44 | } | |
45 | ||
3aee8918 PA |
46 | #ifndef IN_PROCESS_AGENT |
47 | ||
f49ff000 | 48 | static const struct target_desc default_description {}; |
3aee8918 PA |
49 | |
50 | void | |
51 | copy_target_description (struct target_desc *dest, | |
52 | const struct target_desc *src) | |
53 | { | |
54 | dest->reg_defs = src->reg_defs; | |
3aee8918 PA |
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 * | |
61 | current_target_desc (void) | |
62 | { | |
0bfdf32f | 63 | if (current_thread == NULL) |
3aee8918 PA |
64 | return &default_description; |
65 | ||
66 | return current_process ()->tdesc; | |
67 | } | |
0abe8a89 | 68 | |
5f035c07 YQ |
69 | /* See arch/tdesc.h. */ |
70 | ||
0abe8a89 YQ |
71 | void |
72 | set_tdesc_architecture (struct target_desc *target_desc, | |
73 | const char *name) | |
74 | { | |
75 | target_desc->arch = xstrdup (name); | |
76 | } | |
77 | ||
5f035c07 YQ |
78 | /* See arch/tdesc.h. */ |
79 | ||
0abe8a89 YQ |
80 | void |
81 | set_tdesc_osabi (struct target_desc *target_desc, const char *name) | |
82 | { | |
83 | target_desc->osabi = xstrdup (name); | |
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 * | |
90 | tdesc_get_features_xml (target_desc *tdesc) | |
91 | { | |
92 | /* Either .xmltarget or .features is not NULL. */ | |
93 | gdb_assert (tdesc->xmltarget != NULL | |
94 | || (tdesc->features != NULL | |
95 | && tdesc->arch != NULL | |
96 | && tdesc->osabi != NULL)); | |
97 | ||
98 | if (tdesc->xmltarget == NULL) | |
99 | { | |
100 | std::string buffer ("@<?xml version=\"1.0\"?>"); | |
101 | ||
102 | buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"; | |
103 | buffer += "<target>"; | |
104 | buffer += "<architecture>"; | |
105 | buffer += tdesc->arch; | |
106 | buffer += "</architecture>"; | |
107 | ||
108 | buffer += "<osabi>"; | |
109 | buffer += tdesc->osabi; | |
110 | buffer += "</osabi>"; | |
111 | ||
112 | char *xml; | |
113 | ||
114 | for (int i = 0; VEC_iterate (char_ptr, tdesc->features, i, xml); i++) | |
115 | { | |
116 | buffer += "<xi:include href=\""; | |
117 | buffer += xml; | |
118 | buffer += "\"/>"; | |
119 | } | |
120 | ||
121 | buffer += "</target>"; | |
122 | ||
123 | tdesc->xmltarget = xstrdup (buffer.c_str ()); | |
124 | } | |
125 | ||
126 | return tdesc->xmltarget; | |
127 | } | |
3aee8918 | 128 | #endif |
f49ff000 YQ |
129 | |
130 | struct tdesc_type | |
131 | {}; | |
132 | ||
133 | /* See arch/tdesc.h. */ | |
134 | ||
135 | struct tdesc_feature * | |
0abe8a89 YQ |
136 | tdesc_create_feature (struct target_desc *tdesc, const char *name, |
137 | const char *xml) | |
f49ff000 | 138 | { |
0abe8a89 YQ |
139 | #ifndef IN_PROCESS_AGENT |
140 | VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml)); | |
141 | #endif | |
f49ff000 YQ |
142 | return tdesc; |
143 | } | |
144 | ||
145 | /* See arch/tdesc.h. */ | |
146 | ||
147 | struct tdesc_type * | |
148 | tdesc_create_flags (struct tdesc_feature *feature, const char *name, | |
149 | int size) | |
150 | { | |
151 | return NULL; | |
152 | } | |
153 | ||
154 | /* See arch/tdesc.h. */ | |
155 | ||
156 | void | |
157 | tdesc_add_flag (struct tdesc_type *type, int start, | |
158 | const char *flag_name) | |
159 | {} | |
160 | ||
161 | /* See arch/tdesc.h. */ | |
162 | ||
163 | struct tdesc_type * | |
164 | tdesc_named_type (const 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_union (struct tdesc_feature *feature, const char *id) | |
173 | { | |
174 | return NULL; | |
175 | } | |
176 | ||
177 | /* See arch/tdesc.h. */ | |
178 | ||
179 | struct tdesc_type * | |
180 | tdesc_create_struct (struct tdesc_feature *feature, const char *id) | |
181 | { | |
182 | return NULL; | |
183 | } | |
184 | ||
185 | /* See arch/tdesc.h. */ | |
186 | ||
187 | void | |
188 | tdesc_create_reg (struct tdesc_feature *feature, const char *name, | |
189 | int regnum, int save_restore, const char *group, | |
190 | int bitsize, const char *type) | |
191 | { | |
192 | struct target_desc *tdesc = (struct target_desc *) feature; | |
193 | ||
c4dfafab | 194 | while (tdesc->reg_defs.size () < regnum) |
f49ff000 YQ |
195 | { |
196 | struct reg *reg = XCNEW (struct reg); | |
197 | ||
198 | reg->name = ""; | |
199 | reg->size = 0; | |
c4dfafab | 200 | tdesc->reg_defs.push_back (reg); |
f49ff000 YQ |
201 | } |
202 | ||
203 | gdb_assert (regnum == 0 | |
c4dfafab | 204 | || regnum == tdesc->reg_defs.size ()); |
f49ff000 YQ |
205 | |
206 | struct reg *reg = XCNEW (struct reg); | |
207 | ||
208 | reg->name = name; | |
209 | reg->size = bitsize; | |
c4dfafab | 210 | tdesc->reg_defs.push_back (reg); |
f49ff000 YQ |
211 | } |
212 | ||
213 | /* See arch/tdesc.h. */ | |
214 | ||
215 | struct tdesc_type * | |
216 | tdesc_create_vector (struct tdesc_feature *feature, const char *name, | |
217 | struct tdesc_type *field_type, int count) | |
218 | { | |
219 | return NULL; | |
220 | } | |
221 | ||
222 | void | |
223 | tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, | |
224 | int start, int end) | |
225 | {} | |
226 | ||
227 | /* See arch/tdesc.h. */ | |
228 | ||
229 | void | |
230 | tdesc_add_field (struct tdesc_type *type, const char *field_name, | |
231 | struct tdesc_type *field_type) | |
232 | {} | |
233 | ||
234 | /* See arch/tdesc.h. */ | |
235 | ||
236 | void | |
237 | tdesc_set_struct_size (struct tdesc_type *type, int size) | |
238 | { | |
239 | } |