Use int instead of LONGEST in tdesc_type sizes.
[deliverable/binutils-gdb.git] / gdb / xml-tdesc.c
1 /* XML target description support for GDB.
2
3 Copyright (C) 2006-2016 Free Software Foundation, Inc.
4
5 Contributed by CodeSourcery.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "target.h"
24 #include "target-descriptions.h"
25 #include "xml-support.h"
26 #include "xml-tdesc.h"
27 #include "osabi.h"
28 #include "filenames.h"
29
30 /* Maximum sizes.
31 This is just to catch obviously wrong values. */
32 #define MAX_FIELD_SIZE 65536
33 #define MAX_FIELD_BITSIZE (MAX_FIELD_SIZE * TARGET_CHAR_BIT)
34 #define MAX_VECTOR_SIZE 65536
35
36 #if !defined(HAVE_LIBEXPAT)
37
38 /* Parse DOCUMENT into a target description. Or don't, since we don't have
39 an XML parser. */
40
41 static struct target_desc *
42 tdesc_parse_xml (const char *document, xml_fetch_another fetcher,
43 void *fetcher_baton)
44 {
45 static int have_warned;
46
47 if (!have_warned)
48 {
49 have_warned = 1;
50 warning (_("Can not parse XML target description; XML support was "
51 "disabled at compile time"));
52 }
53
54 return NULL;
55 }
56
57 #else /* HAVE_LIBEXPAT */
58
59 /* A record of every XML description we have parsed. We never discard
60 old descriptions, because we never discard gdbarches. As long as we
61 have a gdbarch referencing this description, we want to have a copy
62 of it here, so that if we parse the same XML document again we can
63 return the same "struct target_desc *"; if they are not singletons,
64 then we will create unnecessary duplicate gdbarches. See
65 gdbarch_list_lookup_by_info. */
66
67 struct tdesc_xml_cache
68 {
69 const char *xml_document;
70 struct target_desc *tdesc;
71 };
72 typedef struct tdesc_xml_cache tdesc_xml_cache_s;
73 DEF_VEC_O(tdesc_xml_cache_s);
74
75 static VEC(tdesc_xml_cache_s) *xml_cache;
76
77 /* Callback data for target description parsing. */
78
79 struct tdesc_parsing_data
80 {
81 /* The target description we are building. */
82 struct target_desc *tdesc;
83
84 /* The target feature we are currently parsing, or last parsed. */
85 struct tdesc_feature *current_feature;
86
87 /* The register number to use for the next register we see, if
88 it does not have its own. This starts at zero. */
89 int next_regnum;
90
91 /* The struct or union we are currently parsing, or last parsed. */
92 struct tdesc_type *current_type;
93
94 /* The byte size of the current struct type, if specified. Zero
95 if not specified. */
96 int current_type_size;
97
98 /* Whether the current type is a flags type. */
99 int current_type_is_flags;
100 };
101
102 /* Handle the end of an <architecture> element and its value. */
103
104 static void
105 tdesc_end_arch (struct gdb_xml_parser *parser,
106 const struct gdb_xml_element *element,
107 void *user_data, const char *body_text)
108 {
109 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
110 const struct bfd_arch_info *arch;
111
112 arch = bfd_scan_arch (body_text);
113 if (arch == NULL)
114 gdb_xml_error (parser, _("Target description specified unknown "
115 "architecture \"%s\""), body_text);
116 set_tdesc_architecture (data->tdesc, arch);
117 }
118
119 /* Handle the end of an <osabi> element and its value. */
120
121 static void
122 tdesc_end_osabi (struct gdb_xml_parser *parser,
123 const struct gdb_xml_element *element,
124 void *user_data, const char *body_text)
125 {
126 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
127 enum gdb_osabi osabi;
128
129 osabi = osabi_from_tdesc_string (body_text);
130 if (osabi == GDB_OSABI_UNKNOWN)
131 warning (_("Target description specified unknown osabi \"%s\""),
132 body_text);
133 else
134 set_tdesc_osabi (data->tdesc, osabi);
135 }
136
137 /* Handle the end of a <compatible> element and its value. */
138
139 static void
140 tdesc_end_compatible (struct gdb_xml_parser *parser,
141 const struct gdb_xml_element *element,
142 void *user_data, const char *body_text)
143 {
144 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
145 const struct bfd_arch_info *arch;
146
147 arch = bfd_scan_arch (body_text);
148 tdesc_add_compatible (data->tdesc, arch);
149 }
150
151 /* Handle the start of a <target> element. */
152
153 static void
154 tdesc_start_target (struct gdb_xml_parser *parser,
155 const struct gdb_xml_element *element,
156 void *user_data, VEC(gdb_xml_value_s) *attributes)
157 {
158 char *version = (char *) xml_find_attribute (attributes, "version")->value;
159
160 if (strcmp (version, "1.0") != 0)
161 gdb_xml_error (parser,
162 _("Target description has unsupported version \"%s\""),
163 version);
164 }
165
166 /* Handle the start of a <feature> element. */
167
168 static void
169 tdesc_start_feature (struct gdb_xml_parser *parser,
170 const struct gdb_xml_element *element,
171 void *user_data, VEC(gdb_xml_value_s) *attributes)
172 {
173 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
174 char *name = (char *) xml_find_attribute (attributes, "name")->value;
175
176 data->current_feature = tdesc_create_feature (data->tdesc, name);
177 }
178
179 /* Handle the start of a <reg> element. Fill in the optional
180 attributes and attach it to the containing feature. */
181
182 static void
183 tdesc_start_reg (struct gdb_xml_parser *parser,
184 const struct gdb_xml_element *element,
185 void *user_data, VEC(gdb_xml_value_s) *attributes)
186 {
187 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
188 struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
189 int ix = 0, length;
190 char *name, *group, *type;
191 int bitsize, regnum, save_restore;
192
193 length = VEC_length (gdb_xml_value_s, attributes);
194
195 name = (char *) attrs[ix++].value;
196 bitsize = * (ULONGEST *) attrs[ix++].value;
197
198 if (ix < length && strcmp (attrs[ix].name, "regnum") == 0)
199 regnum = * (ULONGEST *) attrs[ix++].value;
200 else
201 regnum = data->next_regnum;
202
203 if (ix < length && strcmp (attrs[ix].name, "type") == 0)
204 type = (char *) attrs[ix++].value;
205 else
206 type = "int";
207
208 if (ix < length && strcmp (attrs[ix].name, "group") == 0)
209 group = (char *) attrs[ix++].value;
210 else
211 group = NULL;
212
213 if (ix < length && strcmp (attrs[ix].name, "save-restore") == 0)
214 save_restore = * (ULONGEST *) attrs[ix++].value;
215 else
216 save_restore = 1;
217
218 if (strcmp (type, "int") != 0
219 && strcmp (type, "float") != 0
220 && tdesc_named_type (data->current_feature, type) == NULL)
221 gdb_xml_error (parser, _("Register \"%s\" has unknown type \"%s\""),
222 name, type);
223
224 tdesc_create_reg (data->current_feature, name, regnum, save_restore, group,
225 bitsize, type);
226
227 data->next_regnum = regnum + 1;
228 }
229
230 /* Handle the start of a <union> element. Initialize the type and
231 record it with the current feature. */
232
233 static void
234 tdesc_start_union (struct gdb_xml_parser *parser,
235 const struct gdb_xml_element *element,
236 void *user_data, VEC(gdb_xml_value_s) *attributes)
237 {
238 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
239 char *id = (char *) xml_find_attribute (attributes, "id")->value;
240
241 data->current_type = tdesc_create_union (data->current_feature, id);
242 data->current_type_size = 0;
243 data->current_type_is_flags = 0;
244 }
245
246 /* Handle the start of a <struct> element. Initialize the type and
247 record it with the current feature. */
248
249 static void
250 tdesc_start_struct (struct gdb_xml_parser *parser,
251 const struct gdb_xml_element *element,
252 void *user_data, VEC(gdb_xml_value_s) *attributes)
253 {
254 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
255 char *id = (char *) xml_find_attribute (attributes, "id")->value;
256 struct tdesc_type *type;
257 struct gdb_xml_value *attr;
258
259 type = tdesc_create_struct (data->current_feature, id);
260 data->current_type = type;
261 data->current_type_size = 0;
262 data->current_type_is_flags = 0;
263
264 attr = xml_find_attribute (attributes, "size");
265 if (attr != NULL)
266 {
267 ULONGEST size = * (ULONGEST *) attr->value;
268
269 if (size > MAX_FIELD_SIZE)
270 {
271 gdb_xml_error (parser,
272 _("Struct size %s is larger than maximum (%d)"),
273 pulongest (size), MAX_FIELD_SIZE);
274 }
275 tdesc_set_struct_size (type, size);
276 data->current_type_size = size;
277 }
278 }
279
280 static void
281 tdesc_start_flags (struct gdb_xml_parser *parser,
282 const struct gdb_xml_element *element,
283 void *user_data, VEC(gdb_xml_value_s) *attributes)
284 {
285 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
286 char *id = (char *) xml_find_attribute (attributes, "id")->value;
287 ULONGEST size = * (ULONGEST *)
288 xml_find_attribute (attributes, "size")->value;
289 struct tdesc_type *type;
290
291 if (size > MAX_FIELD_SIZE)
292 {
293 gdb_xml_error (parser,
294 _("Flags size %s is larger than maximum (%d)"),
295 pulongest (size), MAX_FIELD_SIZE);
296 }
297 type = tdesc_create_flags (data->current_feature, id, size);
298
299 data->current_type = type;
300 data->current_type_size = 0;
301 data->current_type_is_flags = 1;
302 }
303
304 /* Handle the start of a <field> element. Attach the field to the
305 current struct or union. */
306
307 static void
308 tdesc_start_field (struct gdb_xml_parser *parser,
309 const struct gdb_xml_element *element,
310 void *user_data, VEC(gdb_xml_value_s) *attributes)
311 {
312 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
313 struct gdb_xml_value *attr;
314 struct tdesc_type *field_type;
315 char *field_name, *field_type_id;
316 int start, end;
317
318 field_name = (char *) xml_find_attribute (attributes, "name")->value;
319
320 attr = xml_find_attribute (attributes, "type");
321 if (attr != NULL)
322 field_type_id = (char *) attr->value;
323 else
324 field_type_id = NULL;
325
326 attr = xml_find_attribute (attributes, "start");
327 if (attr != NULL)
328 {
329 ULONGEST ul_start = * (ULONGEST *) attr->value;
330
331 if (ul_start > MAX_FIELD_BITSIZE)
332 {
333 gdb_xml_error (parser,
334 _("Field start %s is larger than maximum (%d)"),
335 pulongest (ul_start), MAX_FIELD_BITSIZE);
336 }
337 start = ul_start;
338 }
339 else
340 start = -1;
341
342 attr = xml_find_attribute (attributes, "end");
343 if (attr != NULL)
344 {
345 ULONGEST ul_end = * (ULONGEST *) attr->value;
346
347 if (ul_end > MAX_FIELD_BITSIZE)
348 {
349 gdb_xml_error (parser,
350 _("Field end %s is larger than maximum (%d)"),
351 pulongest (ul_end), MAX_FIELD_BITSIZE);
352 }
353 end = ul_end;
354 }
355 else
356 end = -1;
357
358 if (field_type_id != NULL)
359 {
360 if (data->current_type_is_flags)
361 gdb_xml_error (parser, _("Cannot add typed field \"%s\" to flags"),
362 field_name);
363 if (data->current_type_size != 0)
364 gdb_xml_error (parser,
365 _("Explicitly sized type can not "
366 "contain non-bitfield \"%s\""),
367 field_name);
368
369 field_type = tdesc_named_type (data->current_feature, field_type_id);
370 if (field_type == NULL)
371 gdb_xml_error (parser, _("Field \"%s\" references undefined "
372 "type \"%s\""),
373 field_name, field_type_id);
374
375 tdesc_add_field (data->current_type, field_name, field_type);
376 }
377 else if (start != -1 && end != -1)
378 {
379 struct tdesc_type *t = data->current_type;
380
381 if (data->current_type_is_flags)
382 tdesc_add_flag (t, start, field_name);
383 else
384 {
385 if (data->current_type_size == 0)
386 gdb_xml_error (parser,
387 _("Implicitly sized type can "
388 "not contain bitfield \"%s\""),
389 field_name);
390
391 if (end >= 64)
392 gdb_xml_error (parser,
393 _("Bitfield \"%s\" goes past "
394 "64 bits (unsupported)"),
395 field_name);
396
397 /* Assume that the bit numbering in XML is "lsb-zero". Most
398 architectures other than PowerPC use this ordering. In
399 the future, we can add an XML tag to indicate "msb-zero"
400 numbering. */
401 if (start > end)
402 gdb_xml_error (parser, _("Bitfield \"%s\" has start after end"),
403 field_name);
404
405 if (end >= data->current_type_size * TARGET_CHAR_BIT)
406 gdb_xml_error (parser,
407 _("Bitfield \"%s\" does not fit in struct"));
408
409 tdesc_add_bitfield (t, field_name, start, end);
410 }
411 }
412 else
413 gdb_xml_error (parser, _("Field \"%s\" has neither type nor bit position"),
414 field_name);
415 }
416
417 /* Handle the start of a <vector> element. Initialize the type and
418 record it with the current feature. */
419
420 static void
421 tdesc_start_vector (struct gdb_xml_parser *parser,
422 const struct gdb_xml_element *element,
423 void *user_data, VEC(gdb_xml_value_s) *attributes)
424 {
425 struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
426 struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
427 struct tdesc_type *field_type;
428 char *id, *field_type_id;
429 ULONGEST count;
430
431 id = (char *) attrs[0].value;
432 field_type_id = (char *) attrs[1].value;
433 count = * (ULONGEST *) attrs[2].value;
434
435 if (count > MAX_VECTOR_SIZE)
436 {
437 gdb_xml_error (parser,
438 _("Vector size %s is larger than maximum (%d)"),
439 pulongest (count), MAX_VECTOR_SIZE);
440 }
441
442 field_type = tdesc_named_type (data->current_feature, field_type_id);
443 if (field_type == NULL)
444 gdb_xml_error (parser, _("Vector \"%s\" references undefined type \"%s\""),
445 id, field_type_id);
446
447 tdesc_create_vector (data->current_feature, id, field_type, count);
448 }
449
450 /* The elements and attributes of an XML target description. */
451
452 static const struct gdb_xml_attribute field_attributes[] = {
453 { "name", GDB_XML_AF_NONE, NULL, NULL },
454 { "type", GDB_XML_AF_OPTIONAL, NULL, NULL },
455 { "start", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
456 { "end", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
457 { NULL, GDB_XML_AF_NONE, NULL, NULL }
458 };
459
460 static const struct gdb_xml_element struct_union_children[] = {
461 { "field", field_attributes, NULL, GDB_XML_EF_REPEATABLE,
462 tdesc_start_field, NULL },
463 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
464 };
465
466 static const struct gdb_xml_attribute reg_attributes[] = {
467 { "name", GDB_XML_AF_NONE, NULL, NULL },
468 { "bitsize", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
469 { "regnum", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
470 { "type", GDB_XML_AF_OPTIONAL, NULL, NULL },
471 { "group", GDB_XML_AF_OPTIONAL, NULL, NULL },
472 { "save-restore", GDB_XML_AF_OPTIONAL,
473 gdb_xml_parse_attr_enum, gdb_xml_enums_boolean },
474 { NULL, GDB_XML_AF_NONE, NULL, NULL }
475 };
476
477 static const struct gdb_xml_attribute struct_union_attributes[] = {
478 { "id", GDB_XML_AF_NONE, NULL, NULL },
479 { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL},
480 { NULL, GDB_XML_AF_NONE, NULL, NULL }
481 };
482
483 static const struct gdb_xml_attribute flags_attributes[] = {
484 { "id", GDB_XML_AF_NONE, NULL, NULL },
485 { "size", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL},
486 { NULL, GDB_XML_AF_NONE, NULL, NULL }
487 };
488
489 static const struct gdb_xml_attribute vector_attributes[] = {
490 { "id", GDB_XML_AF_NONE, NULL, NULL },
491 { "type", GDB_XML_AF_NONE, NULL, NULL },
492 { "count", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
493 { NULL, GDB_XML_AF_NONE, NULL, NULL }
494 };
495
496 static const struct gdb_xml_attribute feature_attributes[] = {
497 { "name", GDB_XML_AF_NONE, NULL, NULL },
498 { NULL, GDB_XML_AF_NONE, NULL, NULL }
499 };
500
501 static const struct gdb_xml_element feature_children[] = {
502 { "reg", reg_attributes, NULL,
503 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
504 tdesc_start_reg, NULL },
505 { "struct", struct_union_attributes, struct_union_children,
506 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
507 tdesc_start_struct, NULL },
508 { "union", struct_union_attributes, struct_union_children,
509 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
510 tdesc_start_union, NULL },
511 { "flags", flags_attributes, struct_union_children,
512 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
513 tdesc_start_flags, NULL },
514 { "vector", vector_attributes, NULL,
515 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
516 tdesc_start_vector, NULL },
517 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
518 };
519
520 static const struct gdb_xml_attribute target_attributes[] = {
521 { "version", GDB_XML_AF_NONE, NULL, NULL },
522 { NULL, GDB_XML_AF_NONE, NULL, NULL }
523 };
524
525 static const struct gdb_xml_element target_children[] = {
526 { "architecture", NULL, NULL, GDB_XML_EF_OPTIONAL,
527 NULL, tdesc_end_arch },
528 { "osabi", NULL, NULL, GDB_XML_EF_OPTIONAL,
529 NULL, tdesc_end_osabi },
530 { "compatible", NULL, NULL, GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
531 NULL, tdesc_end_compatible },
532 { "feature", feature_attributes, feature_children,
533 GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
534 tdesc_start_feature, NULL },
535 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
536 };
537
538 static const struct gdb_xml_element tdesc_elements[] = {
539 { "target", target_attributes, target_children, GDB_XML_EF_NONE,
540 tdesc_start_target, NULL },
541 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
542 };
543
544 /* Parse DOCUMENT into a target description and return it. */
545
546 static struct target_desc *
547 tdesc_parse_xml (const char *document, xml_fetch_another fetcher,
548 void *fetcher_baton)
549 {
550 struct cleanup *back_to, *result_cleanup;
551 struct tdesc_parsing_data data;
552 struct tdesc_xml_cache *cache;
553 char *expanded_text;
554 int ix;
555
556 /* Expand all XInclude directives. */
557 expanded_text = xml_process_xincludes (_("target description"),
558 document, fetcher, fetcher_baton, 0);
559 if (expanded_text == NULL)
560 {
561 warning (_("Could not load XML target description; ignoring"));
562 return NULL;
563 }
564
565 /* Check for an exact match in the list of descriptions we have
566 previously parsed. strcmp is a slightly inefficient way to
567 do this; an SHA-1 checksum would work as well. */
568 for (ix = 0; VEC_iterate (tdesc_xml_cache_s, xml_cache, ix, cache); ix++)
569 if (strcmp (cache->xml_document, expanded_text) == 0)
570 {
571 xfree (expanded_text);
572 return cache->tdesc;
573 }
574
575 back_to = make_cleanup (null_cleanup, NULL);
576
577 memset (&data, 0, sizeof (struct tdesc_parsing_data));
578 data.tdesc = allocate_target_description ();
579 result_cleanup = make_cleanup_free_target_description (data.tdesc);
580 make_cleanup (xfree, expanded_text);
581
582 if (gdb_xml_parse_quick (_("target description"), "gdb-target.dtd",
583 tdesc_elements, expanded_text, &data) == 0)
584 {
585 /* Parsed successfully. */
586 struct tdesc_xml_cache new_cache;
587
588 new_cache.xml_document = expanded_text;
589 new_cache.tdesc = data.tdesc;
590 VEC_safe_push (tdesc_xml_cache_s, xml_cache, &new_cache);
591 discard_cleanups (result_cleanup);
592 do_cleanups (back_to);
593 return data.tdesc;
594 }
595 else
596 {
597 warning (_("Could not load XML target description; ignoring"));
598 do_cleanups (back_to);
599 return NULL;
600 }
601 }
602 #endif /* HAVE_LIBEXPAT */
603 \f
604
605 /* Read an XML target description from FILENAME. Parse it, and return
606 the parsed description. */
607
608 const struct target_desc *
609 file_read_description_xml (const char *filename)
610 {
611 struct target_desc *tdesc;
612 char *tdesc_str;
613 struct cleanup *back_to;
614 char *dirname;
615
616 tdesc_str = xml_fetch_content_from_file (filename, NULL);
617 if (tdesc_str == NULL)
618 {
619 warning (_("Could not open \"%s\""), filename);
620 return NULL;
621 }
622
623 back_to = make_cleanup (xfree, tdesc_str);
624
625 dirname = ldirname (filename);
626 if (dirname != NULL)
627 make_cleanup (xfree, dirname);
628
629 tdesc = tdesc_parse_xml (tdesc_str, xml_fetch_content_from_file, dirname);
630 do_cleanups (back_to);
631
632 return tdesc;
633 }
634
635 /* Read a string representation of available features from the target,
636 using TARGET_OBJECT_AVAILABLE_FEATURES. The returned string is
637 malloc allocated and NUL-terminated. NAME should be a non-NULL
638 string identifying the XML document we want; the top level document
639 is "target.xml". Other calls may be performed for the DTD or
640 for <xi:include>. */
641
642 static char *
643 fetch_available_features_from_target (const char *name, void *baton_)
644 {
645 struct target_ops *ops = (struct target_ops *) baton_;
646
647 /* Read this object as a string. This ensures that a NUL
648 terminator is added. */
649 return target_read_stralloc (ops,
650 TARGET_OBJECT_AVAILABLE_FEATURES,
651 name);
652 }
653 \f
654
655 /* Read an XML target description using OPS. Parse it, and return the
656 parsed description. */
657
658 const struct target_desc *
659 target_read_description_xml (struct target_ops *ops)
660 {
661 struct target_desc *tdesc;
662 char *tdesc_str;
663 struct cleanup *back_to;
664
665 tdesc_str = fetch_available_features_from_target ("target.xml", ops);
666 if (tdesc_str == NULL)
667 return NULL;
668
669 back_to = make_cleanup (xfree, tdesc_str);
670 tdesc = tdesc_parse_xml (tdesc_str,
671 fetch_available_features_from_target,
672 ops);
673 do_cleanups (back_to);
674
675 return tdesc;
676 }
677
678 /* Fetches an XML target description using OPS, processing
679 includes, but not parsing it. Used to dump whole tdesc
680 as a single XML file. */
681
682 char *
683 target_fetch_description_xml (struct target_ops *ops)
684 {
685 #if !defined(HAVE_LIBEXPAT)
686 static int have_warned;
687
688 if (!have_warned)
689 {
690 have_warned = 1;
691 warning (_("Can not fetch XML target description; XML support was "
692 "disabled at compile time"));
693 }
694
695 return NULL;
696 #else
697 struct target_desc *tdesc;
698 char *tdesc_str;
699 char *expanded_text;
700 struct cleanup *back_to;
701
702 tdesc_str = fetch_available_features_from_target ("target.xml", ops);
703 if (tdesc_str == NULL)
704 return NULL;
705
706 back_to = make_cleanup (xfree, tdesc_str);
707 expanded_text = xml_process_xincludes (_("target description"),
708 tdesc_str,
709 fetch_available_features_from_target, ops, 0);
710 do_cleanups (back_to);
711 if (expanded_text == NULL)
712 {
713 warning (_("Could not load XML target description; ignoring"));
714 return NULL;
715 }
716
717 return expanded_text;
718 #endif
719 }
This page took 0.078223 seconds and 5 git commands to generate.