From patchwork Mon Jun 12 08:41:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20923 Received: (qmail 70459 invoked by alias); 12 Jun 2017 08:42:11 -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 70278 invoked by uid 89); 12 Jun 2017 08:42:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Mini, Maintenance, Takes X-HELO: mail-io0-f179.google.com Received: from mail-io0-f179.google.com (HELO mail-io0-f179.google.com) (209.85.223.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 08:42:05 +0000 Received: by mail-io0-f179.google.com with SMTP id i7so52289059ioe.1 for ; Mon, 12 Jun 2017 01:42:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2mSVFh9PkZsgl5rroU73AYHcrg6cy80mJeQ6vds5f80=; b=gauf9gXQmaR9u+lre5udMKfDUNTKeqmuj08FDJ8oE1YX5ARtkQ1nlQM7AWq2aiYDou BjPUP2QCdRaKqyK362IFKmNWvcg5YW43YR66N9LI/kOcG00zaLVNBKOnm9EDFFjuQjMh /7fluaAtFizWgS+QF4Nu6/LdeLsCI5vGoU8OJg07GSG1hRU3AqZ+LWtMWf5TiRIDmpIb AS69EdgQbUMWeb7asXM+D4Nwj6JuvSjH3iY63eI7WEtpvyXWmbNIpqnDDpaC1gYum88y 6O1Sb4HYDTn8Y7LA0Zpbgs3mm0Orsni7Z3SToR2K0prrHEd66s7WvJdylLoUdutELIXh 6s9g== X-Gm-Message-State: AKS2vOzEdVI7oASNiK5vy8x4pJ7QwWGRepmtkjrti7OPSb6r+RF6ttce GHUoKlT/nb1DmDzC X-Received: by 10.107.149.193 with SMTP id x184mr25258237iod.104.1497256928428; Mon, 12 Jun 2017 01:42:08 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id u4sm5280289itu.1.2017.06.12.01.42.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 01:42:08 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Date: Mon, 12 Jun 2017 09:41:39 +0100 Message-Id: <1497256916-4958-9-git-send-email-yao.qi@linaro.org> In-Reply-To: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> References: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes Now, GDB is able to dynamically create i386-linux target descriptions from features, instead of using pre-generated target descriptions. These pre-generated target descriptions are no longer used by GDB (note that they are still used by GDBserver). This patch add a new maint command "maint check xml-descriptions" to test dynamically generated tdesc are identical to these generated from xml files. gdb: 2017-06-06 Yao Qi * cli/cli-cmds.c (maintenancechecklist): New variable. * gdbcmd.h (maintenancechecklist): Declare it. * i386-linux-tdep.c (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Call i386_linux_read_description with different masks. * maint.c (maintenance_check_command): New function. (_initialize_maint_cmds): Call add_prefix_cmd. * target-descriptions.c (tdesc_reg): override operator != and ==. (tdesc_type): Likewise. (tdesc_feature): Likewise. (target_desc): Likewise. [GDB_SELF_TEST] (selftests::record_xml_tdesc): New function. (maintenance_check_xml_descriptions): New function. (_initialize_target_descriptions) Add command "xml-descriptions". * target-descriptions.h (selftests::record_xml_tdesc): Declare. gdb/testsuite: 2017-06-06 Yao Qi * gdb.gdb/unittest.exp: Invoke command "maintenance check xml-descriptions". gdb/doc: 2017-06-06 Yao Qi * gdb.texinfo (Maintenance Commands): Document command "maint check xml-descriptions". --- gdb/cli/cli-cmds.c | 4 + gdb/doc/gdb.texinfo | 5 ++ gdb/gdbcmd.h | 4 + gdb/i386-linux-tdep.c | 20 +++++ gdb/maint.c | 18 +++++ gdb/target-descriptions.c | 148 +++++++++++++++++++++++++++++++++++++ gdb/target-descriptions.h | 10 +++ gdb/testsuite/gdb.gdb/unittest.exp | 5 ++ 8 files changed, 214 insertions(+) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 0930342..6d7532b 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -168,6 +168,10 @@ struct cmd_list_element *maintenanceinfolist; struct cmd_list_element *maintenanceprintlist; +/* Chain containing all defined "maintenance check" subcommands. */ + +struct cmd_list_element *maintenancechecklist; + struct cmd_list_element *setprintlist; struct cmd_list_element *showprintlist; diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index eb35b43..10c82b8 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -34684,6 +34684,11 @@ argument @var{file} or the current target description. The created source file can be used in @value{GDBN} when an XML parser is not available to parse the description. +@kindex maint check xml-descriptions +@item maint check xml-descriptions @var{dir} +Check the target descriptions created by @value{GDBN} equal to these +which are created from XML files in @var{dir}. + @kindex maint print dummy-frames @item maint print dummy-frames Prints the contents of @value{GDBN}'s internal dummy-frame stack. diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h index fbd0cb9..14c7f4e 100644 --- a/gdb/gdbcmd.h +++ b/gdb/gdbcmd.h @@ -95,6 +95,10 @@ extern struct cmd_list_element *maintenanceinfolist; extern struct cmd_list_element *maintenanceprintlist; +/* Chain containing all defined "maintenance check" subcommands. */ + +extern struct cmd_list_element *maintenancechecklist; + /* Chain containing all defined "maintenance set" subcommands. */ extern struct cmd_list_element *maintenance_set_cmdlist; diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 5ca58a1..f8d5a7b 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -1116,4 +1116,24 @@ _initialize_i386_linux_tdep (void) { gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX, i386_linux_init_abi); + +#if GDB_SELF_TEST + std::pair xml_masks[] = { + { "i386/i386-linux.xml", X86_XSTATE_SSE_MASK }, + { "i386/i386-mmx-linux.xml", X86_XSTATE_X87_MASK }, + { "i386/i386-avx-linux.xml", X86_XSTATE_AVX_MASK }, + { "i386/i386-mpx-linux.xml", X86_XSTATE_MPX_MASK }, + { "i386/i386-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK }, + { "i386/i386-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK }, + { "i386/i386-avx-mpx-avx512-pku-linux.xml", + X86_XSTATE_AVX_MPX_AVX512_PKU_MASK }, + }; + + for (auto &a : xml_masks) + { + auto tdesc = i386_linux_read_description (a.second); + + selftests::record_xml_tdesc (a.first, tdesc); + } +#endif /* GDB_SELF_TEST */ } diff --git a/gdb/maint.c b/gdb/maint.c index d95f658..a0d43ec 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -178,6 +178,19 @@ maintenance_info_command (char *arg, int from_tty) gdb_stdout); } +/* The "maintenance check" command is defined as a prefix, with + allow_unknown 0. Therefore, its own definition is called only for + "maintenance check" with no args. */ + +static void +maintenance_check_command (char *arg, int from_tty) +{ + printf_unfiltered (_("\"maintenance check\" must be followed " + "by the name of a check command.\n")); + help_list (maintenancechecklist, "maintenance check ", all_commands, + gdb_stdout); +} + /* Mini tokenizing lexer for 'maint info sections' command. */ static int @@ -1104,6 +1117,11 @@ Print the internal architecture configuration.\n\ Takes an optional file parameter."), &maintenanceprintlist); + add_prefix_cmd ("check", class_maintenance, maintenance_check_command, _("\ +Commands for checking internal gdb state."), + &maintenancechecklist, "maintenance check ", 0, + &maintenancelist); + add_cmd ("translate-address", class_maintenance, maintenance_translate_address, _("Translate a section name and address to a symbol."), diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index c0b716a..2b3083a 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -133,6 +133,20 @@ public: v.visit (this); } + bool operator== (const tdesc_reg &other) const + { + return (streq (name, other.name) + && target_regnum == other.target_regnum + && save_restore == other.save_restore + && bitsize == other.bitsize + && (group == other.group || streq (group, other.group)) + && streq (type, other.type)); + } + + bool operator!= (const tdesc_reg &other) const + { + return !(*this == other); + } } *tdesc_reg_p; DEF_VEC_P(tdesc_reg_p); @@ -247,6 +261,15 @@ public: v.visit (this); } + bool operator== (const tdesc_type &other) const + { + return (streq (name, other.name) && kind == other.kind); + } + + bool operator!= (const tdesc_type &other) const + { + return !(*this == other); + } } *tdesc_type_p; DEF_VEC_P(tdesc_type_p); @@ -315,6 +338,53 @@ public: v.visit_end (this); } + bool operator!= (const tdesc_feature &other) const + { + if (strcmp (name, other.name) != 0) + return true; + + if (VEC_length (tdesc_reg_p, registers) + != VEC_length (tdesc_reg_p, other.registers)) + return true; + + struct tdesc_reg *reg; + + for (int ix = 0; + VEC_iterate (tdesc_reg_p, registers, ix, reg); + ix++) + { + struct tdesc_reg *reg2 + = VEC_index (tdesc_reg_p, other.registers, ix); + + if (reg != reg2 && *reg != *reg2) + return true; + } + + if (VEC_length (tdesc_type_p, types) + != VEC_length (tdesc_type_p, other.types)) + return true; + + struct tdesc_type *type; + + for (int ix = 0; + VEC_iterate (tdesc_type_p, types, ix, type); + ix++) + { + struct tdesc_type *type2 + = VEC_index (tdesc_type_p, other.types, ix); + + if (type != type2 && *type != *type2) + return true; + } + + return false; + } + + bool operator== (const tdesc_feature &other) const + { + return !(*this != other); + } + } *tdesc_feature_p; DEF_VEC_P(tdesc_feature_p); @@ -385,6 +455,39 @@ public: v.visit_end (this); } + + bool operator!= (const target_desc &other) const + { + if (arch != other.arch) + return true; + + if (osabi != other.osabi) + return true; + + if (VEC_length (tdesc_feature_p, features) + != VEC_length (tdesc_feature_p, other.features)) + return true; + + struct tdesc_feature *feature; + + for (int ix = 0; + VEC_iterate (tdesc_feature_p, features, ix, feature); + ix++) + { + struct tdesc_feature *feature2 + = VEC_index (tdesc_feature_p, other.features, ix); + + if (feature != feature2 && *feature != *feature2) + return true; + } + + return false; + } + + bool operator== (const target_desc &other) const + { + return !(*this != other); + } }; /* Per-architecture data associated with a target description. The @@ -2170,6 +2273,45 @@ maint_print_c_tdesc_cmd (char *args, int from_tty) } } +namespace selftests { + +static std::vector> xml_tdesc; + +#if GDB_SELF_TEST +void +record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc) +{ + xml_tdesc.emplace_back (xml_file, tdesc); +} +#endif + +} + +/* Test these GDB builtin target descriptions equal to these which + are generated by the corresponding xml files. */ + +static void +maintenance_check_xml_descriptions (char *name, int from_tty) +{ + if (name == NULL) + error (_("Missing dir name")); + + std::string feature_dir (name); + unsigned int failed = 0; + + for (auto const &e : selftests::xml_tdesc) + { + std::string tdesc_xml = (feature_dir + SLASH_STRING + e.first); + const target_desc *tdesc + = file_read_description_xml (tdesc_xml.data ()); + + if (tdesc == NULL || *tdesc != *e.second) + failed++; + } + printf_filtered (_("%lu XML are tested, %d failed\n"), + (long) selftests::xml_tdesc.size (), failed); +} + /* Provide a prototype to silence -Wmissing-prototypes. */ extern initialize_file_ftype _initialize_target_descriptions; @@ -2210,4 +2352,10 @@ GDB will read the description from the target."), add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\ Print the current target description as a C source file."), &maintenanceprintlist); + + add_cmd ("xml-descriptions", class_maintenance, + maintenance_check_xml_descriptions, _("\ +Check the target descriptions.\n\ +Takes a directory parameter."), + &maintenancechecklist); } diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index 361ac97..d730672 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -253,4 +253,14 @@ void tdesc_create_reg (struct tdesc_feature *feature, const char *name, int regnum, int save_restore, const char *group, int bitsize, const char *type); +#if GDB_SELF_TEST +namespace selftests { + +/* Record the target description TDESC generated by XML_FILE. */ + +void record_xml_tdesc (const char *xml_file, + const struct target_desc *tdesc); +} +#endif + #endif /* TARGET_DESCRIPTIONS_H */ diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp index d6fc3de..991ab9c 100644 --- a/gdb/testsuite/gdb.gdb/unittest.exp +++ b/gdb/testsuite/gdb.gdb/unittest.exp @@ -15,3 +15,8 @@ gdb_start gdb_test "maintenance selftest" "Ran $decimal unit tests, 0 failed" + +if { ![is_remote host] } { + gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \ + "$decimal XML are tested, 0 failed" +}