diff options
author | Alan Hayward <alan.hayward@arm.com> | 2018-04-18 20:09:12 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2018-04-18 20:44:39 +0100 |
commit | e98577a9dc4da048ded601920dc6471dcab375aa (patch) | |
tree | 375ce804dcb3c8308b95542b7a8e16ed5d4803e1 /gdb/target-descriptions.c | |
parent | ad7fc756d12a841d4b8dd707568426d875e26755 (diff) | |
download | fsf-binutils-gdb-e98577a9dc4da048ded601920dc6471dcab375aa.zip fsf-binutils-gdb-e98577a9dc4da048ded601920dc6471dcab375aa.tar.gz fsf-binutils-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/target-descriptions.c')
-rw-r--r-- | gdb/target-descriptions.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index da2c1ce..c0f8511 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -333,6 +333,9 @@ struct target_desc : tdesc_element /* The features associated with this target. */ std::vector<tdesc_feature_up> features; + /* Used to cache the generated xml version of the target description. */ + mutable char *xmltarget = nullptr; + void accept (tdesc_element_visitor &v) const override { v.visit_pre (this); @@ -1667,6 +1670,21 @@ private: int m_next_regnum = 0; }; +/* See common/tdesc.h. */ + +const char * +tdesc_get_features_xml (const target_desc *tdesc) +{ + if (tdesc->xmltarget == nullptr) + { + std::string buffer ("@"); + print_xml_feature v (&buffer); + tdesc->accept (v); + tdesc->xmltarget = xstrdup (buffer.c_str ()); + } + return tdesc->xmltarget; +} + static void maint_print_c_tdesc_cmd (const char *args, int from_tty) { @@ -1739,6 +1757,39 @@ record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc) } +/* Test the convesion process of a target description to/from xml: Take a target + description TDESC, convert to xml, back to a description, and confirm the new + tdesc is identical to the original. */ +static bool +maintenance_check_tdesc_xml_convert (const target_desc *tdesc, const char *name) +{ + const char *xml = tdesc_get_features_xml (tdesc); + + if (xml == nullptr || *xml != '@') + { + printf_filtered (_("Could not convert description for %s to xml.\n"), + name); + return false; + } + + const target_desc *tdesc_trans = string_read_description_xml (xml + 1); + + if (tdesc_trans == nullptr) + { + printf_filtered (_("Could not convert description for %s from xml.\n"), + name); + return false; + } + else if (*tdesc != *tdesc_trans) + { + printf_filtered (_("Converted description for %s does not match.\n"), + name); + return false; + } + return true; +} + + /* Check that the target descriptions created dynamically by architecture-specific code equal the descriptions created from XML files found in the specified directory DIR. */ @@ -1760,6 +1811,12 @@ maintenance_check_xml_descriptions (const char *dir, int from_tty) = file_read_description_xml (tdesc_xml.data ()); if (tdesc == NULL || *tdesc != *e.second) + { + printf_filtered ( _("Descriptions for %s do not match.\n"), e.first); + failed++; + } + else if (!maintenance_check_tdesc_xml_convert (tdesc, e.first) + || !maintenance_check_tdesc_xml_convert (e.second, e.first)) failed++; } printf_filtered (_("Tested %lu XML files, %d failed\n"), |