aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver
diff options
context:
space:
mode:
authorAlan Hayward <alan.hayward@arm.com>2018-04-18 20:09:12 +0100
committerAlan Hayward <alan.hayward@arm.com>2018-04-18 20:44:39 +0100
commite98577a9dc4da048ded601920dc6471dcab375aa (patch)
tree375ce804dcb3c8308b95542b7a8e16ed5d4803e1 /gdb/gdbserver
parentad7fc756d12a841d4b8dd707568426d875e26755 (diff)
downloadgdb-e98577a9dc4da048ded601920dc6471dcab375aa.zip
gdb-e98577a9dc4da048ded601920dc6471dcab375aa.tar.gz
gdb-e98577a9dc4da048ded601920dc6471dcab375aa.tar.bz2
Create xml from target descriptions
Add a print_xml_feature visitor class which turns a target description into xml. Both gdb and gdbserver can do this. gdb/ * common/tdesc.c (print_xml_feature::visit_pre): Add xml parsing. (print_xml_feature::visit_post): Likewise. (print_xml_feature::visit): Likewise. * common/tdesc.h (tdesc_get_features_xml): Use const tdesc. (print_xml_feature): Add new class. * regformats/regdat.sh: Null xmltarget on feature targets. * target-descriptions.c (struct target_desc): Add xmltarget. (maintenance_check_tdesc_xml_convert): Add unittest function. (tdesc_get_features_xml): Add function to get xml. (maintenance_check_xml_descriptions): Test xml generation. * xml-tdesc.c (string_read_description_xml): Add function. * xml-tdesc.h (string_read_description_xml): Add declaration. gdbserver/ * gdb/gdbserver/server.c (get_features_xml): Remove cast. * tdesc.c (void target_desc::accept): Fill in function. (tdesc_get_features_xml): Remove old xml creation. (print_xml_feature::visit_pre): Add xml vistor. * tdesc.h (struct target_desc): Make xmltarget mutable. (tdesc_get_features_xml): Remove declaration.
Diffstat (limited to 'gdb/gdbserver')
-rw-r--r--gdb/gdbserver/ChangeLog9
-rw-r--r--gdb/gdbserver/server.c2
-rw-r--r--gdb/gdbserver/tdesc.c45
-rw-r--r--gdb/gdbserver/tdesc.h14
4 files changed, 33 insertions, 37 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 96dc83c..43fa090 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,14 @@
2018-04-18 Alan Hayward <alan.hayward@arm.com>
+ * server.c (get_features_xml): Remove cast.
+ * tdesc.c (void target_desc::accept): Fill in function.
+ (tdesc_get_features_xml): Remove old xml creation.
+ (print_xml_feature::visit_pre): Add xml vistor.
+ * tdesc.h (struct target_desc): Make xmltarget mutable.
+ (tdesc_get_features_xml): Remove declaration.
+
+2018-04-18 Alan Hayward <alan.hayward@arm.com>
+
* tdesc.c (tdesc_architecture_name): Add new function.
(tdesc_osabi_name): Likewise.
(tdesc_get_features_xml): Use new functions.
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 64c72bd..5027df5 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -940,7 +940,7 @@ get_features_xml (const char *annex)
if (strcmp (annex, "target.xml") == 0)
{
- const char *ret = tdesc_get_features_xml ((target_desc*) desc);
+ const char *ret = tdesc_get_features_xml (desc);
if (*ret == '@')
return ret + 1;
diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c
index 7603a90..126589f 100644
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -47,6 +47,18 @@ bool target_desc::operator== (const target_desc &other) const
#endif
+void target_desc::accept (tdesc_element_visitor &v) const
+{
+#ifndef IN_PROCESS_AGENT
+ v.visit_pre (this);
+
+ for (const tdesc_feature_up &feature : features)
+ feature->accept (v);
+
+ v.visit_post (this);
+#endif
+}
+
void
init_target_desc (struct target_desc *tdesc)
{
@@ -138,11 +150,10 @@ set_tdesc_osabi (struct target_desc *target_desc, const char *name)
target_desc->osabi = xstrdup (name);
}
-/* Return a string which is of XML format, including XML target
- description to be sent to GDB. */
+/* See common/tdesc.h. */
const char *
-tdesc_get_features_xml (target_desc *tdesc)
+tdesc_get_features_xml (const target_desc *tdesc)
{
/* Either .xmltarget or .features is not NULL. */
gdb_assert (tdesc->xmltarget != NULL
@@ -151,31 +162,9 @@ tdesc_get_features_xml (target_desc *tdesc)
if (tdesc->xmltarget == NULL)
{
- std::string buffer ("@<?xml version=\"1.0\"?>");
-
- buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
- buffer += "<target>";
- buffer += "<architecture>";
- buffer += tdesc_architecture_name (tdesc);
- buffer += "</architecture>";
-
- const char *osabi = tdesc_osabi_name (tdesc);
- if (osabi != nullptr)
- {
- buffer += "<osabi>";
- buffer += osabi;
- buffer += "</osabi>";
- }
-
- for (const tdesc_feature_up &feature : tdesc->features)
- {
- buffer += "<xi:include href=\"";
- buffer += feature->name;
- buffer += "\"/>";
- }
-
- buffer += "</target>";
-
+ std::string buffer ("@");
+ print_xml_feature v (&buffer);
+ tdesc->accept (v);
tdesc->xmltarget = xstrdup (buffer.c_str ());
}
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 197fb59..61a3e4e 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -27,7 +27,7 @@
/* A target description. Inherit from tdesc_feature so that target_desc
can be used as tdesc_feature. */
-struct target_desc
+struct target_desc : tdesc_element
{
/* A vector of elements of register definitions that
describe the inferior's register set. */
@@ -49,9 +49,9 @@ struct target_desc
verbatim XML code (prefixed with a '@') or else the name of the
actual XML file to be used in place of "target.xml".
- It can be NULL, then, its content is got from the following three
- fields features, arch, and osabi in tdesc_get_features_xml. */
- const char *xmltarget = NULL;
+ If NULL then its content will be generated by parsing the target
+ description into xml. */
+ mutable const char *xmltarget = NULL;
/* The value of <architecture> element in the XML, replying GDB. */
const char *arch = NULL;
@@ -73,6 +73,8 @@ public:
return !(*this == other);
}
#endif
+
+ void accept (tdesc_element_visitor &v) const override;
};
/* Copy target description SRC to DEST. */
@@ -89,8 +91,4 @@ void init_target_desc (struct target_desc *tdesc);
const struct target_desc *current_target_desc (void);
-#ifndef IN_PROCESS_AGENT
-const char *tdesc_get_features_xml (struct target_desc *tdesc);
-#endif
-
#endif /* TDESC_H */