gdb/xml-support.h - gdb

Global variables defined

Data types defined

Macros defined

Source code

  1. /* Helper routines for parsing XML using Expat.

  2.    Copyright (C) 2006-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */


  14. #ifndef XML_SUPPORT_H
  15. #define XML_SUPPORT_H

  16. #include "gdb_obstack.h"
  17. #include "vec.h"
  18. #include "xml-utils.h"

  19. struct gdb_xml_parser;
  20. struct gdb_xml_element;
  21. struct gdb_xml_attribute;

  22. /* Return an XML document which was compiled into GDB, from
  23.    the given FILENAME, or NULL if the file was not compiled in.  */

  24. const char *fetch_xml_builtin (const char *filename);

  25. /* A to_xfer_partial helper function which reads XML files which were
  26.    compiled into GDB.  The target may call this function from its own
  27.    to_xfer_partial handler, after converting object and annex to the
  28.    appropriate filename.  */

  29. LONGEST xml_builtin_xfer_partial (const char *filename,
  30.                                   gdb_byte *readbuf, const gdb_byte *writebuf,
  31.                                   ULONGEST offset, LONGEST len);

  32. /* The text of compiled-in XML documents, from xml-builtin.c
  33.    (generated).  */

  34. extern const char *xml_builtin[][2];

  35. /* Support for XInclude.  */

  36. /* Callback to fetch a new XML file, based on the provided HREF.  */

  37. typedef char *(*xml_fetch_another) (const char *href, void *baton);

  38. /* Return a new string which is the expansion of TEXT after processing
  39.    <xi:include> tags.  FETCHER will be called (with FETCHER_BATON) to
  40.    retrieve any new files.  DEPTH should be zero on the initial call.

  41.    On failure, this function uses NAME in a warning and returns NULL.
  42.    It may throw an exception, but does not for XML parsing
  43.    problems.  */

  44. char *xml_process_xincludes (const char *name, const char *text,
  45.                              xml_fetch_another fetcher, void *fetcher_baton,
  46.                              int depth);

  47. /* Simplified XML parser infrastructure.  */

  48. /* A name and value pair, used to record parsed attributes.  */

  49. struct gdb_xml_value
  50. {
  51.   const char *name;
  52.   void *value;
  53. };
  54. typedef struct gdb_xml_value gdb_xml_value_s;
  55. DEF_VEC_O(gdb_xml_value_s);

  56. /* The type of an attribute handler.

  57.    PARSER is the current XML parser, which should be used to issue any
  58.    debugging or error messages.  The second argument is the
  59.    corresponding attribute description, so that a single handler can
  60.    be used for multiple attributes; the attribute name is available
  61.    for error messages and the handler data is available for additional
  62.    customization (see gdb_xml_parse_attr_enum).  VALUE is the string
  63.    value of the attribute.

  64.    The returned value should be freeable with xfree, and will be freed
  65.    after the start handler is called.  Errors should be reported by
  66.    calling gdb_xml_error.  */

  67. typedef void *(gdb_xml_attribute_handler) (struct gdb_xml_parser *parser,
  68.                                            const struct gdb_xml_attribute *,
  69.                                            const char *value);

  70. /* Flags for attributes.  If no flags are specified, the attribute is
  71.    required.  */

  72. enum gdb_xml_attribute_flag
  73. {
  74.   GDB_XML_AF_NONE,
  75.   GDB_XML_AF_OPTIONAL = 1 << 0/* The attribute is optional.  */
  76. };

  77. /* An expected attribute and the handler to call when it is
  78.    encountered.  Arrays of struct gdb_xml_attribute are terminated
  79.    by an entry with NAME == NULL.  */

  80. struct gdb_xml_attribute
  81. {
  82.   const char *name;
  83.   int flags;
  84.   gdb_xml_attribute_handler *handler;
  85.   const void *handler_data;
  86. };

  87. /* Flags for elements.  If no flags are specified, the element is
  88.    required exactly once.  */

  89. enum gdb_xml_element_flag
  90. {
  91.   GDB_XML_EF_NONE,
  92.   GDB_XML_EF_OPTIONAL = 1 << 0/* The element is optional.  */
  93.   GDB_XML_EF_REPEATABLE = 1 << 1/* The element is repeatable.  */
  94. };

  95. /* A handler called at the beginning of an element.

  96.    PARSER is the current XML parser, which should be used to issue any
  97.    debugging or error messages.  ELEMENT is the current element.
  98.    USER_DATA is the opaque pointer supplied when the parser was
  99.    created.  ATTRIBUTES is a vector of the values of any attributes
  100.    attached to this element.

  101.    The start handler will only be called if all the required
  102.    attributes were present and parsed successfully, and elements of
  103.    ATTRIBUTES are guaranteed to be in the same order used in
  104.    ELEMENT->ATTRIBUTES (not the order from the XML file).  Accordingly
  105.    fixed offsets can be used to find any non-optional attributes as
  106.    long as no optional attributes precede them.  */

  107. typedef void (gdb_xml_element_start_handler)
  108.      (struct gdb_xml_parser *parser, const struct gdb_xml_element *element,
  109.       void *user_data, VEC(gdb_xml_value_s) *attributes);

  110. /* A handler called at the end of an element.

  111.    PARSER, ELEMENT, and USER_DATA are as for the start handler.  BODY
  112.    is any accumulated body text inside the element, with leading and
  113.    trailing whitespace removed.  It will never be NULL.  */

  114. typedef void (gdb_xml_element_end_handler)
  115.      (struct gdb_xml_parser *, const struct gdb_xml_element *,
  116.       void *user_data, const char *body_text);

  117. /* An expected element and the handlers to call when it is
  118.    encountered.  Arrays of struct gdb_xml_element are terminated
  119.    by an entry with NAME == NULL.  */

  120. struct gdb_xml_element
  121. {
  122.   const char *name;
  123.   const struct gdb_xml_attribute *attributes;
  124.   const struct gdb_xml_element *children;
  125.   int flags;

  126.   gdb_xml_element_start_handler *start_handler;
  127.   gdb_xml_element_end_handler *end_handler;
  128. };

  129. /* Associate DTD_NAME, which must be the name of a compiled-in DTD,
  130.    with PARSER.  */

  131. void gdb_xml_use_dtd (struct gdb_xml_parser *parser, const char *dtd_name);

  132. /* Invoke PARSER on BUFFER.  BUFFER is the data to parse, which
  133.    should be NUL-terminated.

  134.    The return value is 0 for success or -1 for error.  It may throw,
  135.    but only if something unexpected goes wrong during parsing; parse
  136.    errors will be caught, warned about, and reported as failure.  */

  137. int gdb_xml_parse (struct gdb_xml_parser *parser, const char *buffer);

  138. /* Parse a XML document.  DOCUMENT is the data to parse, which should
  139.    be NUL-terminated. If non-NULL, use the compiled-in DTD named
  140.    DTD_NAME to drive the parsing.

  141.    The return value is 0 for success or -1 for error.  It may throw,
  142.    but only if something unexpected goes wrong during parsing; parse
  143.    errors will be caught, warned about, and reported as failure.  */

  144. int gdb_xml_parse_quick (const char *name, const char *dtd_name,
  145.                          const struct gdb_xml_element *elements,
  146.                          const char *document, void *user_data);

  147. /* Issue a debugging message from one of PARSER's handlers.  */

  148. void gdb_xml_debug (struct gdb_xml_parser *parser, const char *format, ...)
  149.      ATTRIBUTE_PRINTF (2, 0);

  150. /* Issue an error message from one of PARSER's handlers, and stop
  151.    parsing.  */

  152. void gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...)
  153.      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 0);

  154. /* Find the attribute named NAME in the set of parsed attributes
  155.    ATTRIBUTES.  Returns NULL if not found.  */

  156. struct gdb_xml_value *xml_find_attribute (VEC(gdb_xml_value_s) *attributes,
  157.                                           const char *name);

  158. /* Parse an integer attribute into a ULONGEST.  */

  159. extern gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest;

  160. /* Map NAME to VALUE.  A struct gdb_xml_enum * should be saved as the
  161.    value of handler_data when using gdb_xml_parse_attr_enum to parse a
  162.    fixed list of possible strings.  The list is terminated by an entry
  163.    with NAME == NULL.  */

  164. struct gdb_xml_enum
  165. {
  166.   const char *name;
  167.   ULONGEST value;
  168. };

  169. /* A handler_data for yes/no boolean values.  */
  170. extern const struct gdb_xml_enum gdb_xml_enums_boolean[];

  171. extern gdb_xml_attribute_handler gdb_xml_parse_attr_enum;

  172. /* Parse an integer string into a ULONGEST and return it, or call
  173.    gdb_xml_error if it could not be parsed.  */

  174. ULONGEST gdb_xml_parse_ulongest (struct gdb_xml_parser *parser,
  175.                                  const char *value);

  176. /* Simple printf to obstack function.  Current implemented formatters:
  177.    %s - grow an xml escaped text in OBSTACK.  */

  178. extern void obstack_xml_printf (struct obstack *obstack,
  179.                                const char *format, ...)
  180.   ATTRIBUTE_PRINTF_2;

  181. /* Open FILENAME, read all its text into memory, close it, and return
  182.    the text.  If something goes wrong, return NULL and warn.  */

  183. extern char *xml_fetch_content_from_file (const char *filename,
  184.                                           void *baton);

  185. #endif