]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/xml-support.h
Add missing changelog entry
[thirdparty/binutils-gdb.git] / gdb / xml-support.h
CommitLineData
fd79ecee
DJ
1/* Helper routines for parsing XML using Expat.
2
42a4f53d 3 Copyright (C) 2006-2019 Free Software Foundation, Inc.
fd79ecee
DJ
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fd79ecee
DJ
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fd79ecee
DJ
19
20
21#ifndef XML_SUPPORT_H
22#define XML_SUPPORT_H
23
e776119f 24#include "gdb_obstack.h"
268a13a5
TT
25#include "gdbsupport/vec.h"
26#include "gdbsupport/xml-utils.h"
27#include "gdbsupport/byte-vector.h"
0d12e84c 28#include "gdbsupport/gdb_optional.h"
fd79ecee 29
e776119f
DJ
30struct gdb_xml_parser;
31struct gdb_xml_element;
32struct gdb_xml_attribute;
fd79ecee 33
108546a0
DJ
34/* Return an XML document which was compiled into GDB, from
35 the given FILENAME, or NULL if the file was not compiled in. */
36
37const char *fetch_xml_builtin (const char *filename);
38
05a4558a
DJ
39/* A to_xfer_partial helper function which reads XML files which were
40 compiled into GDB. The target may call this function from its own
41 to_xfer_partial handler, after converting object and annex to the
42 appropriate filename. */
43
44LONGEST xml_builtin_xfer_partial (const char *filename,
45 gdb_byte *readbuf, const gdb_byte *writebuf,
46 ULONGEST offset, LONGEST len);
47
108546a0
DJ
48/* The text of compiled-in XML documents, from xml-builtin.c
49 (generated). */
de584861 50
108546a0
DJ
51extern const char *xml_builtin[][2];
52
de584861
PA
53/* Support for XInclude. */
54
55/* Callback to fetch a new XML file, based on the provided HREF. */
56
9018be22
SM
57typedef gdb::optional<gdb::char_vector> (*xml_fetch_another) (const char *href,
58 void *baton);
de584861 59
bd8a901f
PA
60/* Append the expansion of TEXT after processing <xi:include> tags in
61 RESULT. FETCHER will be called (with FETCHER_BATON) to retrieve
62 any new files. DEPTH should be zero on the initial call.
de584861 63
bd8a901f 64 On failure, this function uses NAME in a warning and returns false.
de584861
PA
65 It may throw an exception, but does not for XML parsing
66 problems. */
67
bd8a901f
PA
68bool xml_process_xincludes (std::string &result,
69 const char *name, const char *text,
70 xml_fetch_another fetcher, void *fetcher_baton,
71 int depth);
de584861 72
108546a0
DJ
73/* Simplified XML parser infrastructure. */
74
e776119f 75/* A name and value pair, used to record parsed attributes. */
fd79ecee 76
e776119f
DJ
77struct gdb_xml_value
78{
4d0fdd9b
SM
79 gdb_xml_value (const char *name_, void *value_)
80 : name (name_), value (value_)
81 {}
82
e776119f 83 const char *name;
4d0fdd9b 84 gdb::unique_xmalloc_ptr<void> value;
e776119f 85};
fd79ecee 86
e776119f 87/* The type of an attribute handler.
fd79ecee 88
e776119f
DJ
89 PARSER is the current XML parser, which should be used to issue any
90 debugging or error messages. The second argument is the
91 corresponding attribute description, so that a single handler can
92 be used for multiple attributes; the attribute name is available
93 for error messages and the handler data is available for additional
94 customization (see gdb_xml_parse_attr_enum). VALUE is the string
95 value of the attribute.
96
97 The returned value should be freeable with xfree, and will be freed
98 after the start handler is called. Errors should be reported by
99 calling gdb_xml_error. */
100
101typedef void *(gdb_xml_attribute_handler) (struct gdb_xml_parser *parser,
102 const struct gdb_xml_attribute *,
103 const char *value);
104
105/* Flags for attributes. If no flags are specified, the attribute is
106 required. */
107
108enum gdb_xml_attribute_flag
109{
110 GDB_XML_AF_NONE,
111 GDB_XML_AF_OPTIONAL = 1 << 0, /* The attribute is optional. */
112};
113
114/* An expected attribute and the handler to call when it is
115 encountered. Arrays of struct gdb_xml_attribute are terminated
116 by an entry with NAME == NULL. */
117
118struct gdb_xml_attribute
119{
120 const char *name;
121 int flags;
122 gdb_xml_attribute_handler *handler;
123 const void *handler_data;
124};
125
126/* Flags for elements. If no flags are specified, the element is
127 required exactly once. */
128
129enum gdb_xml_element_flag
130{
131 GDB_XML_EF_NONE,
132 GDB_XML_EF_OPTIONAL = 1 << 0, /* The element is optional. */
133 GDB_XML_EF_REPEATABLE = 1 << 1, /* The element is repeatable. */
134};
135
136/* A handler called at the beginning of an element.
137
138 PARSER is the current XML parser, which should be used to issue any
139 debugging or error messages. ELEMENT is the current element.
140 USER_DATA is the opaque pointer supplied when the parser was
141 created. ATTRIBUTES is a vector of the values of any attributes
142 attached to this element.
143
144 The start handler will only be called if all the required
145 attributes were present and parsed successfully, and elements of
146 ATTRIBUTES are guaranteed to be in the same order used in
147 ELEMENT->ATTRIBUTES (not the order from the XML file). Accordingly
148 fixed offsets can be used to find any non-optional attributes as
149 long as no optional attributes precede them. */
150
151typedef void (gdb_xml_element_start_handler)
152 (struct gdb_xml_parser *parser, const struct gdb_xml_element *element,
4d0fdd9b 153 void *user_data, std::vector<gdb_xml_value> &attributes);
e776119f
DJ
154
155/* A handler called at the end of an element.
156
157 PARSER, ELEMENT, and USER_DATA are as for the start handler. BODY
158 is any accumulated body text inside the element, with leading and
159 trailing whitespace removed. It will never be NULL. */
160
161typedef void (gdb_xml_element_end_handler)
162 (struct gdb_xml_parser *, const struct gdb_xml_element *,
163 void *user_data, const char *body_text);
164
165/* An expected element and the handlers to call when it is
166 encountered. Arrays of struct gdb_xml_element are terminated
167 by an entry with NAME == NULL. */
168
169struct gdb_xml_element
170{
171 const char *name;
172 const struct gdb_xml_attribute *attributes;
173 const struct gdb_xml_element *children;
174 int flags;
175
176 gdb_xml_element_start_handler *start_handler;
177 gdb_xml_element_end_handler *end_handler;
178};
179
efc0eabd
PA
180/* Parse a XML document. DOCUMENT is the data to parse, which should
181 be NUL-terminated. If non-NULL, use the compiled-in DTD named
182 DTD_NAME to drive the parsing.
183
184 The return value is 0 for success or -1 for error. It may throw,
185 but only if something unexpected goes wrong during parsing; parse
186 errors will be caught, warned about, and reported as failure. */
187
188int gdb_xml_parse_quick (const char *name, const char *dtd_name,
189 const struct gdb_xml_element *elements,
190 const char *document, void *user_data);
191
e776119f
DJ
192/* Issue a debugging message from one of PARSER's handlers. */
193
194void gdb_xml_debug (struct gdb_xml_parser *parser, const char *format, ...)
21047726 195 ATTRIBUTE_PRINTF (2, 3);
e776119f
DJ
196
197/* Issue an error message from one of PARSER's handlers, and stop
198 parsing. */
199
200void gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...)
21047726 201 ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
e776119f 202
3d2c1d41
PA
203/* Find the attribute named NAME in the set of parsed attributes
204 ATTRIBUTES. Returns NULL if not found. */
205
4d0fdd9b
SM
206struct gdb_xml_value *xml_find_attribute
207 (std::vector<gdb_xml_value> &attributes, const char *name);
3d2c1d41 208
e776119f
DJ
209/* Parse an integer attribute into a ULONGEST. */
210
211extern gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest;
212
213/* Map NAME to VALUE. A struct gdb_xml_enum * should be saved as the
214 value of handler_data when using gdb_xml_parse_attr_enum to parse a
215 fixed list of possible strings. The list is terminated by an entry
216 with NAME == NULL. */
217
218struct gdb_xml_enum
219{
220 const char *name;
221 ULONGEST value;
222};
223
123dc839
DJ
224/* A handler_data for yes/no boolean values. */
225extern const struct gdb_xml_enum gdb_xml_enums_boolean[];
226
e776119f
DJ
227extern gdb_xml_attribute_handler gdb_xml_parse_attr_enum;
228
229/* Parse an integer string into a ULONGEST and return it, or call
230 gdb_xml_error if it could not be parsed. */
231
232ULONGEST gdb_xml_parse_ulongest (struct gdb_xml_parser *parser,
233 const char *value);
fd79ecee 234
a96d9b2e 235/* Open FILENAME, read all its text into memory, close it, and return
9018be22
SM
236 the text. If something goes wrong, return an uninstantiated optional
237 and warn. */
a96d9b2e 238
9018be22 239extern gdb::optional<gdb::char_vector> xml_fetch_content_from_file
b7b030ad 240 (const char *filename, void *baton);
a96d9b2e 241
fd79ecee 242#endif