This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions
- From: Pedro Alves <palves at redhat dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>, gdb-patches at sourceware dot org
- Date: Wed, 28 Jun 2017 17:13:11 +0100
- Subject: Re: [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5EF71883B1
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5EF71883B1
- References: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> <1497256916-4958-9-git-send-email-yao.qi@linaro.org>
On 06/12/2017 09:41 AM, Yao Qi wrote:
>
> +@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}.
I'd suggest:
Check that the target descriptions created dynamically by
@value{GDBN} equal the descriptions created from XML files
found in @var{dir}.
> }
> + bool operator!= (const tdesc_feature &other) const
> + {
(Missing empty line just above the method.)
Nit, it's a bit more conventional to define operator==
instead, and then operator!= in terms of operator==,
like you had in other cases. Can you do the same here?
It'd just mean swapping true/false in the body of this
function, I think.
> +
> + bool operator!= (const target_desc &other) const
> + {
Ditto.
>
> +namespace selftests {
> +
> +static std::vector<std::pair<const char*, const target_desc *>> 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
> +
Missing intro comments.
> +}
> +
> +/* Test these GDB builtin target descriptions equal to these which
> + are generated by the corresponding xml files. */
"these" here isn't specified (two times). Can you name what
"these" are instead, avoiding indirection? Maybe:
Check that the target descriptions created dynamically by
architecture-specific code, as registered in XML_TDESC,
equal the descriptions created from XML files found in the
specified directory.
> +
> +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;
I'd suggest s/name/dir/ for a tiny bit more clarify.
> +
> + 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);
s/are/were/. Or better, I think:
printf_filtered (_("Tested %lu XML files, %d failed\n"),
(long) selftests::xml_tdesc.size (), failed);
In the same spirit of "maint selftest"'s output.
> +
> + add_cmd ("xml-descriptions", class_maintenance,
> + maintenance_check_xml_descriptions, _("\
> +Check the target descriptions.\n\
> +Takes a directory parameter."),
Can you expand this a little bit?
> + &maintenancechecklist);
Also, I tried the command manually, and noticed that it doesn't
support filename TAB completion. You can fix that with:
set_cmd_completer (c, filename_completer);
It'd be convenient too if it support tilde expansion:
(gdb) maintenance check xml-descriptions ~/gdb/mygit/src/gdb/features
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-mmx-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-mpx-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-mpx-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-avx512-linux.xml"
warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.xml"
7 XML are tested, 7 failed
(gdb) maintenance check xml-descriptions /home/pedro/gdb/mygit/src/gdb/features
7 XML are tested, 0 failed
You can fix that by simply calling tilde_expand.
>
> +#if GDB_SELF_TEST
> +namespace selftests {
> +
> +/* Record the target description TDESC generated by XML_FILE. */
"record for what?" is a reasonable question that the comment
doesn't help with. Maybe write something like this:
Record that XML_FILE should generate a target description that
equals TDESC, to be verified by the "maintenance check xml-descriptions"
command.
> +
> +void record_xml_tdesc (const char *xml_file,
> + const struct target_desc *tdesc);
> +}
> +#endif
> +
Thanks,
Pedro Alves