From 1c28969efcca7c214e41c496f599bc4de2c56dbe Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 31 Jul 2018 10:06:00 -0400 Subject: [PATCH] Delete test target descriptions when exiting Looking at the address sanitizer output, this was a quite low hanging fruit. We create target_desc objects for testing that we never free. Saving them in unique_ptrs takes care of it. I created a small struct to hold these because I thought it would help readability. gdb/ChangeLog: * target-descriptions.c (struct xml_test_tdesc): New. (xml_tdesc): Change type to std::vector. (record_xml_tdesc): Update. (maintenance_check_xml_descriptions): Update. * target-descriptions.h (record_xml_tdesc): Update comment. --- gdb/ChangeLog | 8 ++++++++ gdb/target-descriptions.c | 26 +++++++++++++++++++------- gdb/target-descriptions.h | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6d5b24c1e11..1fbe025be8c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-07-31 Simon Marchi + + * target-descriptions.c (struct xml_test_tdesc): New. + (xml_tdesc): Change type to std::vector. + (record_xml_tdesc): Update. + (maintenance_check_xml_descriptions): Update. + * target-descriptions.h (record_xml_tdesc): Update comment. + 2018-07-30 Andrew Burgess * eval.c (evaluate_subexp_for_sizeof): Check for array type before diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index a96416cd3cc..087de141f7f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1734,7 +1734,19 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty) namespace selftests { -static std::vector> xml_tdesc; +/* A reference target description, used for testing (see record_xml_tdesc). */ + +struct xml_test_tdesc +{ + xml_test_tdesc (const char *name, std::unique_ptr &&tdesc) + : name (name), tdesc (std::move (tdesc)) + {} + + const char *name; + std::unique_ptr tdesc; +}; + +static std::vector xml_tdesc; #if GDB_SELF_TEST @@ -1743,7 +1755,7 @@ static std::vector> xml_tdesc; void record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc) { - xml_tdesc.emplace_back (xml_file, tdesc); + xml_tdesc.emplace_back (xml_file, std::unique_ptr (tdesc)); } #endif @@ -1798,17 +1810,17 @@ maintenance_check_xml_descriptions (const char *dir, int from_tty) for (auto const &e : selftests::xml_tdesc) { - std::string tdesc_xml = (feature_dir + SLASH_STRING + e.first); + std::string tdesc_xml = (feature_dir + SLASH_STRING + e.name); const target_desc *tdesc = file_read_description_xml (tdesc_xml.data ()); - if (tdesc == NULL || *tdesc != *e.second) + if (tdesc == NULL || *tdesc != *e.tdesc) { - printf_filtered ( _("Descriptions for %s do not match.\n"), e.first); + printf_filtered ( _("Descriptions for %s do not match.\n"), e.name); failed++; } - else if (!maintenance_check_tdesc_xml_convert (tdesc, e.first) - || !maintenance_check_tdesc_xml_convert (e.second, e.first)) + else if (!maintenance_check_tdesc_xml_convert (tdesc, e.name) + || !maintenance_check_tdesc_xml_convert (e.tdesc.get (), e.name)) failed++; } printf_filtered (_("Tested %lu XML files, %d failed\n"), diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index 87403acc0d4..96290b7d97e 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -215,7 +215,7 @@ namespace selftests { /* Record that XML_FILE should generate a target description that equals TDESC, to be verified by the "maintenance check xml-descriptions" - command. */ + command. This function takes ownership of TDESC. */ void record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc); -- 2.30.2