aboutsummaryrefslogtreecommitdiff
path: root/gdb/xml-support.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2011-01-25 09:49:59 +0000
committerPedro Alves <palves@redhat.com>2011-01-25 09:49:59 +0000
commitefc0eabd6019406ff92286a36713d41a42515e09 (patch)
treeba00441bc43cc80496e16e09e2e9ae366e2079dd /gdb/xml-support.c
parentf30f86fa955570721c2c0c95468d975f216bf754 (diff)
downloadgdb-efc0eabd6019406ff92286a36713d41a42515e09.zip
gdb-efc0eabd6019406ff92286a36713d41a42515e09.tar.gz
gdb-efc0eabd6019406ff92286a36713d41a42515e09.tar.bz2
Simplify XML parsing a bit.
* xml-support.h (gdb_xml_parse_quick): Declare. * xml-support.c (gdb_xml_create_parser_and_cleanup_1): Renamed from gdb_xml_create_parser_and_cleanup, and added `old_chain' parameter. (gdb_xml_create_parser_and_cleanup): Reimplement on top of gdb_xml_create_parser_and_cleanup_1. (gdb_xml_parse_quick): New. * memory-map.c (parse_memory_map): Use gdb_xml_parse_quick. * osdata.c (osdata_parse): Ditto. * remote.c (remote_threads_info): Ditto. * solib-target.c (solib_target_parse_libraries): Ditto. * xml-syscall.c (syscall_parse_xml): Ditto. * xml-tdesc.c (tdesc_parse_xml): Ditto.
Diffstat (limited to 'gdb/xml-support.c')
-rw-r--r--gdb/xml-support.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index 140d0d9..0bcb975 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -427,13 +427,14 @@ gdb_xml_cleanup (void *arg)
/* Initialize and return a parser. Register a cleanup to destroy the
parser. */
-struct gdb_xml_parser *
-gdb_xml_create_parser_and_cleanup (const char *name,
- const struct gdb_xml_element *elements,
- void *user_data)
+static struct gdb_xml_parser *
+gdb_xml_create_parser_and_cleanup_1 (const char *name,
+ const struct gdb_xml_element *elements,
+ void *user_data, struct cleanup **old_chain)
{
struct gdb_xml_parser *parser;
struct scope_level start_scope;
+ struct cleanup *dummy;
/* Initialize the parser. */
parser = XZALLOC (struct gdb_xml_parser);
@@ -459,11 +460,27 @@ gdb_xml_create_parser_and_cleanup (const char *name,
start_scope.elements = elements;
VEC_safe_push (scope_level_s, parser->scopes, &start_scope);
- make_cleanup (gdb_xml_cleanup, parser);
+ if (old_chain == NULL)
+ old_chain = &dummy;
+ *old_chain = make_cleanup (gdb_xml_cleanup, parser);
return parser;
}
+/* Initialize and return a parser. Register a cleanup to destroy the
+ parser. */
+
+struct gdb_xml_parser *
+gdb_xml_create_parser_and_cleanup (const char *name,
+ const struct gdb_xml_element *elements,
+ void *user_data)
+{
+ struct cleanup *old_chain;
+
+ return gdb_xml_create_parser_and_cleanup_1 (name, elements, user_data,
+ &old_chain);
+}
+
/* External entity handler. The only external entities we support
are those compiled into GDB (we do not fetch entities from the
target). */
@@ -581,6 +598,26 @@ gdb_xml_parse (struct gdb_xml_parser *parser, const char *buffer)
return -1;
}
+int
+gdb_xml_parse_quick (const char *name, const char *dtd_name,
+ const struct gdb_xml_element *elements,
+ const char *document, void *user_data)
+{
+ struct gdb_xml_parser *parser;
+ struct cleanup *back_to;
+ int result;
+
+ parser = gdb_xml_create_parser_and_cleanup_1 (name, elements,
+ user_data, &back_to);
+ if (dtd_name != NULL)
+ gdb_xml_use_dtd (parser, dtd_name);
+ result = gdb_xml_parse (parser, document);
+
+ do_cleanups (back_to);
+
+ return result;
+}
+
/* Parse a field VALSTR that we expect to contain an integer value.
The integer is returned in *VALP. The string is parsed with an
equivalent to strtoul.