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
@@ -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;
@@ -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.
@@ -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;
@@ -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<const char *, uint64_t> 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 */
}
@@ -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."),
@@ -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<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
+
+}
+
+/* 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);
}
@@ -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 */
@@ -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"
+}