From patchwork Mon Jul 30 20:47:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 28694 Received: (qmail 66086 invoked by alias); 30 Jul 2018 20:48:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 65499 invoked by uid 89); 30 Jul 2018 20:47:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy= X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Jul 2018 20:47:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1532983675; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EEHJVa9OsXdYH+4kZ0w0JUxjOgvZEb3J+SSIvkEzqy0=; b=YuE0Km1wDUlcWIVk1/VyGRmy76uLIPCinXn5rvDHiUCmTn2oB/IfjEloOQlYsDrV ogidpjamR0Z0a1kMvGK98+n+md4e5M1kUFyFWyZE99/Fg5mFmlHF14bn9FoK3Ul3 YwjN0WICAKwP7L0Hd1qrJ2Iuf5tLSdbUC0Yuz/L8F+c=; Received: from ESESBMB501.ericsson.se (Unknown_Domain [153.88.183.114]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 59.D8.22978.B797F5B5; Mon, 30 Jul 2018 22:47:55 +0200 (CEST) Received: from ESESSMB501.ericsson.se (153.88.183.162) by ESESBMB501.ericsson.se (153.88.183.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Mon, 30 Jul 2018 22:47:54 +0200 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Mon, 30 Jul 2018 22:47:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=96Pff9jPdA4KkdECUs9j6IehdxNKNT2AU/DNXcXHLBc=; b=B79Qg8EDMZmMy1T9VmKau47KGZ4LD7nMvArgsoAl6eNom8hi34oSRpzr7J6j/ColiRxTEllFfhnlSFQz4/6pb6mNhPbjaHXiTx+UBRNCaCM1mfMsbQSEZ5w6nH3uAH6F8DpYnZEZBdB1ItkM2KLThdasjO7hrxrOZRbdnzyRbOE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.ca.am.ericsson.se (192.75.88.130) by SN6PR15MB2398.namprd15.prod.outlook.com (2603:10b6:805:24::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Mon, 30 Jul 2018 20:47:51 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH] Delete test target descriptions when exiting Date: Mon, 30 Jul 2018 16:47:41 -0400 Message-Id: <1532983661-8486-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes 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/target-descriptions.c | 26 +++++++++++++++++++------- gdb/target-descriptions.h | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index a96416c..087de14 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 87403ac..96290b7 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);