This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC 7/7] Remove builtin tdesc_i386_*_linux
Hi Yao,
On Thu, 11 May 2017 16:55:05 +0100
Yao Qi <qiyaoltc@gmail.com> wrote:
[...]
> diff --git a/gdb/features/i386/i386-mpx-linux.c
> b/gdb/features/i386/i386-mpx-linux.c index 9c722cf..15a1ebe 100644
> --- a/gdb/features/i386/i386-mpx-linux.c
> +++ b/gdb/features/i386/i386-mpx-linux.c
> @@ -216,25 +216,10 @@ create_feature_org_gnu_gdb_i386_mpx (struct target_desc
> *result, long regnum) }
> #endif /* _ORG_GNU_GDB_I386_MPX */
>
> -struct target_desc *tdesc_i386_mpx_linux;
> static void
> initialize_tdesc_i386_mpx_linux (void)
> {
> - struct target_desc *result = allocate_target_description ();
> -
> - set_tdesc_architecture (result, bfd_scan_arch ("i386"));
> -
> - set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
> -
> - long regnum = 0;
> -
> - regnum = create_feature_org_gnu_gdb_i386_core_i386 (result, regnum);
> - regnum = create_feature_org_gnu_gdb_i386_sse (result, regnum);
> - regnum = create_feature_org_gnu_gdb_i386_linux (result, regnum);
> - regnum = create_feature_org_gnu_gdb_i386_mpx (result, regnum);
> -
> - tdesc_i386_mpx_linux = result;
> #if GDB_SELF_TEST
> - selftests::record_xml_tdesc ("i386/i386-mpx-linux.xml",
> tdesc_i386_mpx_linux);
> + selftests::record_xml ("i386/i386-mpx-linux.xml");
> #endif /* GDB_SELF_TEST */
> }
Do you really still need the initialize_tdesc_* functions when you initialize
the target description dynamically? Can't you move the seftest somewhere else
and get rid of it in this case? This would make the code slightly nicer.
> diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
> index a81ae0d..da44e37 100644
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c
> @@ -2005,6 +2005,15 @@ tdesc_feature_unique_name (const struct tdesc_feature*
> feature) return name;
> }
>
> +/* Whether print code initializing tdesc_FUNCTION or not. */
> +
> +static bool
> +tdesc_print_intiailize_tdesc_p (const char *function)
> +{
> + return !(strncmp (function, "i386", 4) == 0
common/common-utils.h:startswith (function, "i386") ?
> + && strncmp (&function[strlen (function) - 6], "_linux", 6) == 0);
common/common-utils.h:endswith (function, "_linux") ?
(From my concat_path patch
https://sourceware.org/ml/gdb-patches/2017-03/msg00272.html)
Even nicer would be if you don't check the function name at all but check e.g.
a flag a target must set or use a feature method. Otherwise you will get an
extremely long and unreadable expression once more targets use this method.
Philipp
> +}
> +
> static void
> maint_print_c_tdesc_cmd (char *args, int from_tty)
> {
> @@ -2262,10 +2271,15 @@ maint_print_c_tdesc_cmd (char *args, int from_tty)
> printf_unfiltered ("\n");
> }
>
> - printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
> + if (tdesc_print_intiailize_tdesc_p (function))
> + printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
> +
> printf_unfiltered ("static void\n");
> printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
> printf_unfiltered ("{\n");
> +
> + if (tdesc_print_intiailize_tdesc_p (function))
> + {
> printf_unfiltered
> (" struct target_desc *result = allocate_target_description ();\n");
>
> @@ -2320,10 +2334,20 @@ maint_print_c_tdesc_cmd (char *args, int from_tty)
>
> printf_unfiltered ("\n");
> printf_unfiltered (" tdesc_%s = result;\n", function);
> + }
>
> printf_unfiltered ("#if GDB_SELF_TEST\n");
> - printf_unfiltered (" selftests::record_xml_tdesc (\"%s\", tdesc_%s);\n",
> - filename_after_features.data (), function);
> +
> + if (tdesc_print_intiailize_tdesc_p (function))
> + {
> + printf_unfiltered (" selftests::record_xml_tdesc (\"%s\",
> tdesc_%s);\n",
> + filename_after_features.data (), function);
> + }
> + else
> + {
> + printf_unfiltered (" selftests::record_xml (\"%s\");\n",
> + filename_after_features.data ());
> + }
> printf_unfiltered ("#endif /* GDB_SELF_TEST */\n");
> printf_unfiltered ("}\n");
> }
> @@ -2341,12 +2365,32 @@ record_xml_tdesc (std::string xml_file, const struct
> target_desc *tdesc) lists.emplace_back (xml_file, tdesc);
> }
>
> +/* XML files, which generate C files and compiled into GDB. */
> +
> +static std::vector<std::string> xml_files;
> +
> +void
> +record_xml (const char *xml_file)
> +{
> + xml_files.emplace_back (xml_file);
> +}
> +
> /* Test these GDB builtin target descriptions are identical to these which
> are generated by the corresponding xml files. */
>
> static void
> xml_builtin_tdesc_test (void)
> {
> + /* Make sure we have a test for every xml target description. */
> + for (auto const &xml : xml_files)
> + {
> + auto r = std::find_if (std::begin (lists), std::end (lists),
> + [&xml](decltype (lists)::const_reference e)
> + -> bool {return e.first == xml;});
> +
> + SELF_CHECK (r != std::end (lists));
> + }
> +
> std::string feature_dir (ldirname (__FILE__));
> struct stat st;
>
> diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
> index 78416ae..2667bcd 100644
> --- a/gdb/target-descriptions.h
> +++ b/gdb/target-descriptions.h
> @@ -266,6 +266,10 @@ namespace selftests {
>
> void record_xml_tdesc (std::string xml_file,
> const struct target_desc *tdesc);
> +
> +/* Record c file generated by XML_FILE is compiled into GDB. */
> +
> +void record_xml (const char *xml_file);
> }
> #endif
>